Saturday, August 20, 2011

Software Development Environment on Linux

For beginners..

You need a shell to try these commands as you read. You may need help with this step.

Linux has been traditionally command line oriented. You type commands and then hit enter and something happens.

The program that listens to your commands is called the shell. There are different types of shells a common one is bash.

You should know the following commands to be functional:
man

pwd
ls
more
less
cat
cd
cp
mv
rm
mkdir
env
echo
tar
gunzip
hostname
vi

These commands will take you an hour to learn. Most valuable is the man command that shows you the manual for other commands. Try the command 'man pwd' to check it out. To exit from a manual page hit the letter 'q'

You enter the commands at the command prompt of the shell. Some commands are interactive and you need to end the interactive session by some form of quitting, to be able to enter further commands. vi is the most disconcerting of all the commands because it is not trivial to get out of it (vi is the standard editor for Unix environments). If you are inside a vi session and need to get out use <Esc> key followed by :q! sequence of keys (remember you need to hold the shift to use ':' and '!'. To exit a 'more' or 'less' session just hit 'q', yes the same one you used to exit the man page. man actually uses the less command to show the pages.

Learning these commands without context is boring and without benefit. Some of them have so many options or flags that it is impossible to learn them all. Here are some use cases to put context around these commands.

Know where you are in the file system. pwd - present working directory shows you where you are and ls lists the files and directories at the specified path or current directory if a path is not specified. Try these commands as you read.
[cox@ip-10-160-178-130 ~]$ pwd

/home/cox
[cox@ip-10-160-178-130 ~]$
create your directory and some files.
[cox@ip-10-160-178-130 ~]$ mkdir test

[cox@ip-10-160-178-130 ~]$ cd test
[cox@ip-10-160-178-130 test]$ echo "Simple text" > test_file.txt
echo prints the given text to screen and the '>' redirects the output to a file (test_file.txt). The following cat command prints the contents of our new file.

[cox@ip-10-160-178-130 test]$ cat test_file.txt

Simple text
[cox@ip-10-160-178-130 test]$ cp test_file.txt copy.txt
[cox@ip-10-160-178-130 test]$ cat copy.txt
Simple text
[cox@ip-10-160-178-130 test]$ ls
copy.txt test_file.txt
[cox@ip-10-160-178-130 test]$ mv copy.txt renamed_copy.txt
[cox@ip-10-160-178-130 test]$ ls
renamed_copy.txt test_file.txt
[cox@ip-10-160-178-130 test]$ cat renamed_copy.txt
Simple text
[cox@ip-10-160-178-130 test]$ rm renamed_copy.txt
[cox@ip-10-160-178-130 test]$ ls
test_file.txt
[cox@ip-10-160-178-130 test]$
cat, more, less help you see the contents of a file in different ways.

tar (tape archive) is useful for extracting files sent to you by others. These files typically have .tgz extension. Here we will create an archive and extract it.
[cox@ip-10-160-178-130 test]$ tar -cvzf archive.tgz test_file.txt

test_file.txt
[cox@ip-10-160-178-130 test]$ ls
archive.tgz test_file.txt
[cox@ip-10-160-178-130 test]$ rm test_file.txt
[cox@ip-10-160-178-130 test]$ ls
archive.tgz
[cox@ip-10-160-178-130 test]$ tar -xvzf archive.tgz
test_file.txt
[cox@ip-10-160-178-130 test]$ ls
archive.tgz test_file.txt
[cox@ip-10-160-178-130 test]$
Then let us remove what we just created. Before that in Unix '.' means current directory and '..' means parent directory. To switch to parent directory we use cd .. quite often.
[cox@ip-10-160-178-130 test]$ cd ..

[cox@ip-10-160-178-130 ~]$ pwd
/home/cox
[cox@ip-10-160-178-130 ~]$ ls
test
[cox@ip-10-160-178-130 ~]$ rm -rf test/
[cox@ip-10-160-178-130 ~]$ ls
[cox@ip-10-160-178-130 ~]$
notice the -rf flags to the rm command here. we give options or flags to commands to modify their behavior. You can mix multiple flags into a sequence -rf is same as -r -f (two flags). Here -r means remove recursively, -f means force. This is a common way to remove directories. rmdir works for directories that are empty.

Be careful with the rm command, there is no trash can to recover your data from.

What are the other commands?
[cox@ip-10-160-178-130 ~]$ echo $PATH

/usr/local/bin:/bin:/usr/bin:/opt/aws/bin:/home/cox/bin
[cox@ip-10-160-178-130 ~]$
the shell finds the commands/executable files from these directories list (each directory separated by ':').

You can see some of our commands are in the directory /bin (second directory in the list).
[cox@ip-10-160-178-130 ~]$ ls /bin

arch chmod date domainname false gunzip kill ls more nisdomainname raw rvi sort tcptraceroute traceroute6 usleep
awk chown dd echo fgrep gzip ksh mail mount pgawk readlink rview stty tcsh tracert vi
basename cp df ed find hostname ksh93 mailx mountpoint ping red sed su touch true view
bash cpio dmesg egrep gawk igawk link mkdir mv ping6 rm setserial sync tracepath umount ypdomainname
cat csh dnsdomainname env grep ipcalc ln mknod netstat ps rmdir sh tar tracepath6 uname zcat
chgrp cut doexec ex gtar iptables-xml login mktemp nice pwd rpm sleep taskset traceroute unlink
[cox@ip-10-160-178-130 ~]$
You can learn about these commands using the man command.

vi is a text editor that deserves its own section, but it is so ubiquitous everyone needs to know the first aid to survive in the Linux world.

You start a vi session (interactive session) by running it on command line. If a parameter is given it opens the path specified by the parameter. As with other commands you can use flags to modify behavior.

Once the interactive session starts you are not in the shell anymore, you are in vi. It has its own commands.

First how do I get out if I entered it accidentally?
<esc> key and then :q!
You may not need the <esc> key but sometimes you might have already entered the insert mode, and <esc> will get you to command mode. Yes vi has two modes insert and command. That is the toughest part about vi. It is vi's way of choosing who to be friends with.

Now for the easy part..

Say you did want to use vi to edit a file. Say you opened the session with
vi myNewFile.txt

assuming this file does not exist in the current directory, it will say at the bottom "myNewFile.txt" [New File]

vi tells you what is going on in the editing session by these messages at the bottom.

to add text you first enter the insert mode by the key 'i' (there are other ways but you just need to know there are other ways). Then you enter text, everything shows up as you expect! Great!

Now you are done editing or you just want to save your changes... anything you type shows up how do you do this? Well, you enter the command mode first by using the <esc> key first.

When in command mode, several keys have functionality, so be careful what you touch (you can learn some of these later). You need learn about the ':' commands first. If you hit ':' (shift + ';:' key) it shows up at the bottom. Now it is ready to take commands. Remember q!, that means quit don't ask questions. Normally if there is unsaved work it will refuse to quit unless you write. ! modifies q to force the quit command. We were talking about saving your work. 'w' for write will write your changes to the file. If you are done :wq will write and quit.

You should be able to survive a few vi sessions with these few commands. Too complicated? Well it is complicated, but it has its uses. You should learn at least this much if you are going to develop on Linux. A little more would be better. http://www.unix-manuals.com/tutorials/vi/vi-in-10-1.html and http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.html should help.

Thursday, August 18, 2011

The Future of Apple

I have been watching Apple stock from 2007. It is a relatively easy stock to analyze. The number for the product sales and market share are available. It is simpler to make projections with large errors that could still give meaningful conclusions for long term investing.

After years of following bits and pieces by reading news articles, checking out products and buying some, and sometimes reading the patents, a synthesized opinion dawned upon me.

What is Apple doing? It is changing the way we use computers. While the industry and the society needed the Microsoft/Intel model of a stable design to iterate on and make use of Moors law to make computing accessible at costs we can afford (hence make the industry possible), time for change has come. Apple has a history of changing the way we use computers, its time has come again.

The transformation has merely begun. Personal computing the way it is even with the recent devices still requires us to adapt around the devices. Apple has learned the art of changing the game and profit from it.

In the days of the Moors law, the model was to pack more computing punch and indicate it with a number on a linear scale to make people want to upgrade. Technology was ready for sometime to change gears and say leave the computing power upgrade to the server rooms and focus on innovation in user interface.

New and seemless ways of interacting with the computer is driving the industry in this decade. Apple has taken the lead and the competition is doing its job well by making Apple run for its money. The stage is set for transformation of computing devices.

Some things to expect are better speech integration, hand gestures, usage of devices while interacting with others, doing away with traditional laptops, your computer goes in your pocket.

In the end, if you are going to pull out the smart phone in the elevator and miss out on the small talk it is really a matter of your habits. Even the cave men had these problems of focusing on the rock cutting tool when they had the chance to make a meaningful conversation. Not sure if computers can save us from our habits.

Wednesday, August 17, 2011

Apple model for eCommerce

eCommerce is growing at double digit pace. Web influenced sales are growing as well, particularly with the increasing use of smart phones and shopping apps made for them.

It is the second part that got me thinking, web influenced sales. The influence can be other way as well. Consumers checkout the product in the physical store and buy online.

What if companies like P&G adopted the Apple model and built their retail stores?