Wednesday, February 24, 2010

The LISP-end of the computing

LISP never introduced until very late in school and that too in the form of ONE slide (yes true) one slide. So what is it in LISP that deserves so little concern. Looking at MIT OCW lectures it seems to be THE language of choice. So whats lisp infact? LISP (LISt Processing) is a language where the primary data structure is list and modus operandi is list operations.

Step 1:  Installation
Installation of lisp on aptitude based package manager (like Debian/ Ubuntu) can be achieved by the following command.
 $ sudo apt-get  install clisp
Alongside this its recommended to install the HTML version of the book  Common Lisp the language, 2nd Edition by Guy L. Steele Jr.
$ sudo apt-get install cltl
The book is installed in the /usr/share/doc/cltl/clm/index.html.

Step 2: Testing LISP functionality
Soon after installation clisp can be tested for functionality. The following sequence of commands test the lisp environment.
 To start clisp
$ clisp
Try out the lisp-expression to add 2 and 2 the result is in the second line. 
[1]> (+ 2 2)
4
Build on more complex lists.  The following expression is lisp way of (1*2)+ 6.

[2]> (+ (* 1 2) 6)
8
Now with the increase in comfort and confidence that lisp is installed and functional. Assigning values to variables is done via the following command
[3]> (setq a 10)
10
For an extremely simple loop using the print command to print hello world five times.
[4]> (do ((x 1 (+ x 1))) ((> x 5)) (print "hello world"))

"hello world"
"hello world"
"hello world"
"hello world"
"hello world"
NIL
Step 3: Doing something more than "hello world"
Having done with assignments and control structures. The next thing is procedures / functions. LISP supports functions via the keyword defun.
[5]> (defun increment (x) (+ x 1))
INCREMENT
[6]> (increment 10)
11
 The line 5 defines the function named increment which essentially has one argument and one line in which the argument is incremented by one. The line 6 calls the function increment with the argument passed as second member of the list.

The following code finds the square of a variable x.
(defun square(x) (x*x))
(setq x 10)
(square x)
Exploration of LISP on emacs is another really interesting topic which needs a dedicated post.

Why hibernating Linux might be a great idea

Why hibernating Linux might be a great idea? What supports the idea? There are basically two reasons that support this idea. One Linux has traditionally lived up to the billing as premium server class operating system.  Secondly it might strange but Windows has performed much better on Laptop using hibernate option than desktops. The former is a direct evidence support the convention while latter is circumstantial evidence. Since Windows is performing better in spite of it’s not so glorious record otherwise. So Linux can be expected to perform better than Windows because of its better history. The conjecture that server’s better performance can be attributed to the lesser frequent restarts needs to be further investigated but for now we could assume it to be true. Therefore its important to start setting up the hibernate option in the Operating System (be it Windows or Linux on laptop or a desktop). Its very good for the battery life too.

Steps for initiating hibernate inUbuntu Linux (Karmic 9.10)
Ubuntu click on your user name on the task bar and select "Hibernate" from the menu.

Steps for initiating hibernate in Windows
XP Operating System the option can be accessed by clicking Control Panel --> Power Options --> Selecting the tab Hibernate. Click the box next to Enable Hibernate (it would be checked by a tick mark). Next go to Advanced Tab and select actions to perform when the lid of the portable computer is closed , Power button is pressed or standby button is pressed.

Thursday, February 18, 2010

The Evolution that is Linux

The availability of huge number of Linux distributions is amazing. The primordial soup developed by  Dennis Ritchie and Ken Thompson named UNIX had in it genesis the most amazing OS Multics. The primordial soup gave birth to a phenomenon which resulted in evolution of one beautiful species after another. The rise of Lisa led to Mac. Even the great evil empire acknowledged its superiority by first trying to develop Xenix and when it failed in its attempt to usurp started slowly building in features into its own Windows. A mutation took place in 1991 when Linux Travolds gave birth to Linux. This led to the never ending stream of species. Each and every species had its strengths and weaknesses but every species showed the brilliance and resilience that was present in its initial genes. The Linux of today cannot be compared directly to the MULTICS or even the first UNIX but the design is same providing solid and unbeatable performance. Not only is Linux and FreeBSD holding on to the server markets but also under the hood of iPhones and ARM processors. Spreading its seeds across all continents be it the PC Market or Laptop or Mini-Laptop Market, the species continues to awe its original developers.

Thursday, February 11, 2010

Linux Newbie : Why I cannot use Latex like those gurus?

Latex is another brilliant Linux / Unix specialty hidden behind the geek facade.  Interesting introduction here {warning PDF file} talks in detail about why and how document processing improves with increase in document complexity. In the words of the author "It is very hard to write unstructured and disorganized documents". I like the approach but feel that this might attract power users but for newbies its more of the same old school of Linux is for geeks. The purpose is not to criticize the authors. He / she did a great job and deserves credit for this article as well. Now the primary question is how and where to start, following tutorials almost always leads to temporary use. Even students writing thesis in latex only a few would later use it for submitting assignments or other work. The problem is two fold one the students or users are not introduced to latex in a friendly manner rather they use it as if trying to live up to the 'lofty standards' setup by advisers or seniors. The second problem was highlighted when a highly motivated student submitted a journal paper in pdf format (developed via pdflatex) to the supervisor. The supervisor demanded an MS-Word Copy of the paper so as to edit. The student completely disgruntled vowed never to use Latex again.
Therefore a complete change of heart is required to accept Latex. Once this step has been done getting to grips with Latex becomes easier and fun.

Step one: Getting Latex
The following method is for Ubuntu. Please google/ contact service manual on how to install on other distributions or here for steps.

Ubuntu / Debian : $ apt-get install texlive

Step two: Starting up
Its never an easy job getting used to something as complex and with such rich history like tex. Using a gui-based tex would be a perfect way to not getting to use tex later. Since in that scenario it is incorrectly compared to microsoft and open office. Yes those programs are good to get work done but they are not anything like tex. Why? This would become clear soon.
Write the following text in a file using editor of your choice (freedom at last). 
\documentclass{article}
\title{Welcome to Freedom}
\begin{document}
\maketitle
This is a sample document which showcases the freedom and peace of mind offered by using {LATEX}
\end{document}
The following command creates an output file (pdf format) with same name as the name of the tex file.
$ pdflatex firstTry.tex

So here lies the first charm of latex that my readers dont need to buy expensive EDITING software just to read what i write.

How did latex decide about the placement of the title and date and fonts. The key to success lies in the fact that the document design and text has been separated. Hence now the user can concentrate on producing text rather than deciding about placement of text, font sizes and  other details that confound a user trying to use a word processor.  This fact can be readily appreciated by a simple change in the above code. Change \documentclass{article} to \documentclass{report} or \documentclass{book}. The resulting pdf file exhibits that the formating of the document can be changed at any stage and the user is least bothered how the document looks while typing the document. This is immense relief.

This bare-minimum tex file ONLY demonstrates the principle of separation of  formatting and content.


Step three: Adding more functionality
Now that fear of tags has subsided. The following tags add more formating information.
\section {SECTION_HEADING_HERE}
\subsection{SUB_SECTION HEADING_HERE}
\subsubsection{SUB_SUB_SECTION_HEADING_HERE}

Incorporate the above tags in the file as below.

\documentclass{article}
\title{Welcome to Freedom}
\begin{document}
\maketitle
    This is a sample document which showcases the freedom and peace of mind offered by using \LaTeX
\section{Formating Sections}
The best part is that you dont have to set font sizes and then try to place the
section headings
\subsection{Sub Sections are cool}
Adding simple tag of subsection simply adds more sections and special part is there is no numbering involved. The numbering is dealt with automatically at the time of preparing pdf file.
\subsubsection{Moving further inside we can enjoy better functionality}
This shows how easy it is create subsections within subsections. Simply continue
 to add sub behind the tag and it goes deeper and deeper.
\section{Simplicity is still the essence}
So the current document if shown to a novice will scare away but we are begining to get the feel of Latex.
Rest would be mostly easier part
\end{document}
The following screen shot exhibits the usage of the above tags.
Adding \tableofcontents after \maketitle adds table of contents automatically.


Step four: Moving on to power usage
Moving on to power usage requires the approach according to the Chinese proverb.

Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Instead of going into the details of each and every command/ tag. Its far better to use the "i will learn it when I need it" approach. This can only be achieved by keeping a tap on where to get the desired information. One method is to use  "The (Not So) Short Introduction to LATEX 2E" as a reference and simply copy and use any commands (examples) and tweak to requirement.

For Example , In order to add mathematical equations and use them effectively the best manner is to actually go and check out an example in the tutorial and study them. The following code fragment adds the equations given in the screen shot that follows.
\section{Explaining how to write Mathematical Equations}
One simple way to write mathematical equations is $A_x^2$ or using the tags begin equation and end equation
\begin{equation}
    \sum_{i=0}^{\infty} X_i=0
\end{equation}
\begin{equation}
    \omega = \Omega
\end{equation}
\begin{equation}
    \sigma = \Sigma
\end{equation}



The code fragments shows in order to write subscript _ is used while to write as superscript ^ is used. Also another thing to notice is that \sigma outputs lower case Greek alphabet sigma while \Sigma outputs an upper case Greek alphabet sigma. 

Another method more in line with the Chinese proverb is the use of the template files provided by the publishers. E.g., IEEE conference style file (IEEEconf.sty) comes with a pdf which explains all the features and how to use IEEEconf.sty. Similarly University of California Los Angeles (UCLA) thesis style file comes with a readme file which explains how to use it.

This way by maintaining high level of confidence and keeping learning Latex while ACTUALLY using it to accomplish different tasks leads to better understanding and long term use.

Tuesday, February 09, 2010

How to automatically change proxy setting in Firefox ?

Proxy setting for office LAN / WLAN and home LAN / WLAN are often different. Firefox provides an easy method of changing proxies without having to do anything. The file proxy.pac provides an easy method of automatically changing proxy setting in Firefox from one network to another. There are elaborate methods of changing proxy settings given here. However the easiest method is described below.

Step 1: Edit the file proxy.pac (preferably save it at a convenient location) and add the following line.

function FindProxyForURL(url, host)  
{ 
   return "PROXY proxy.example.com:8080; DIRECT";  
}
Where proxy.example.com  is simply the address of proxy and could be replaced by the IP Address of the proxy server. 8080 is the port address for http in most networks but could be different in some networks.

Step 2: Go to Firefox Menu--> Tools --> Options --> Network Tab --> Click Setting Button --> Check the automatic proxy configuration url and enter "file:///your_path_goes_here/proxy.pac" in it.
Please ensure to replace the your_path_goes_here with the path where the file proxy.pac is saved. For example in my case it was file:///home/zahid/proxy.pac

Now the Firefox  will first check the proxy and if it is not responding then connect directly to the internet.

This removes the head ache of changing proxy settings on an almost daily basis. Peace at last !!

For those still using Internet Explorer :::  Please keep changing your proxy at regular intervals :)

Wednesday, February 03, 2010

Linux Newbie : Why grep almost never yields something productive

Getting Started Level 0

Every Linux newbie hears about power of grep sooner or later. But no sooner does newbie try to use the grep command the experiment ends badly. The reason grep almost never yields anything productive is because of a couple of issues. The basic problem is lack of knowledge of regular expressions and secondly knowledge of switches of grep. This realization should not deter a new user from using grep. A very nice detailed tutorial of regular expression (regex) is available here. The migrating user having used dir and similar commands in DOS and using windows search box almost never expects (nor can fathom) the power provided by grep. Firstly grep means "global regular expression print". Now this means that knowledge of regex is required to be able to use grep effectively. Now what should a newbie do? Wait till user's regex knowledge improves? NO NOT AT ALL. That would scare away the user and never to use grep. Here is the first simple command that would work to display the files in the current directory.
grep -l ".*" *
REMEMBER this only lists the files (not directories). Now this is not why grep is used but simply given to enhance confidence of the user that "yes we can" use grep. The command ls can be used to list contents of current working directory. The command grep is used to do something more productive. Now lets start doing something ls might not do. Lets try to find all the files with the word "include" IN them. The following simple command does this simply.
grep -l "include" * 
To search all the subdirectories add r to the options which means to search recursively.
grep -lr "include" *
This is all one actually needs to start using grep a little bit more effectively.

Jumping to Level 1

Now to be more productive one has to start using regular expressions. A step by step approach would be better than first going to a regular expressions tutorial and then coming back totally lost. The following can serve as the first command which uses regular expression.  The average user might not even sense any difference because primarily its the same command as above but adds huge difference with slight modification.  Now to check for files which have either trap or drap add t and d in brackets before rap and then search. The following command searches for all the files which have either trap or drap.
grep -l "[td]rap" * 

Jumping to Level 2

This simple addition has enhanced our power of using grep. Another addition to our power is provided by two characters "^" and "$". Now the following command searches files which contain words starting with alphabet a.
grep -l "^a" *
And the following command simply searches words which end with the alphabet d.
grep -l "d$" *
Now in combination the following command can be used to find the files which contain words starting with alphabet a and ending with the alphabet d.
grep -l "^a.*d$" *
This was accomplished by simply adding the ".*" between the two alphabets ensures that anything in between the start and end "pattern".

Jumping to Level 3

Now going back to the brackets discussed earlier. Multiple characters can be added to search by simply adding them in brackets. E.g, To search words starting with either a, e, i, o or u. The following command can be used.
grep -l "^[aeiou]" *
This command searches for all the words that start with a vowel i.e, a,e,i,o or u. This can be used in combination by using commands similar to the following where the files listed contain words that start with a or b and end with d or s.
grep -l "^[ab].*[ds]$" *
Now the expression in brackets can be improved by using ranges and groups.
A-Z match all the upper case alphabets
a-z match all  the lower case alphabets
0-9 matches all the digits

Now using the above ranges the following command tries to search files with words which start with an alphabet and end with a digit. Combining A-Za-z ensures that the starting alphabet could either be upper case or lower case.
grep -l "^[A-Za-z].*[0-9]$"
 The above discussion is enough for a Linux newbie to appreciate the usage of grep command and be comfortable at different levels. In order to attain more power in using grep consult man / info pages of grep or any advanced grep or regex tutorial over the Internet.

References
  1. Linux Manual grep
  2. http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/