Tuesday, March 23, 2010

FOR DIE HARD UNIX AND C FANS

Most of the people who use UNIX instead of Windows, consider themselves to be smarter computer professionals and learned programmers. Not all, but some always keep an air of superiority around themselves...
But all this will fade off once you read this speech which the developer of UNIX- brian and Ken Thompson gave after the release of their OS. Here it is as extracted from the book UNIX HATERS' BOOK.

In an announcement that has stunned the computer industry, Ken Thompson, Dennis Ritchie, and Brian Kernighan admitted that the Unix operating system and C programming language created by them is an elaborate April Fools prank kept alive for more than 20 years. Speaking at the recent Unix World Software Development Forum, Thompson revealed the following:
   “In 1969, AT&T had just terminated their work with the GE/AT&T
   Multics project. Brian and I had just started working with an early
   release of Pascal from Professor Nichlaus Wirth’s ETH labs in Swit-
   zerland, and we were impressed with its elegant simplicity and
   power. Dennis had just finished reading Bored of the Rings, a hilari-
   ous National Lampoon parody of the great Tolkien Lord of the Rings
   trilogy. As a lark, we decided to do parodies of the Multics environ-
   ment and Pascal. Dennis and I were responsible for the operating
   environment. We looked at Multics and designed the new system to
   be as complex and cryptic as possible to maximize casual users’ frus-
   tration levels, calling it Unix as a parody of Multics, as well as other
   more risque allusions.
   “Then Dennis and Brian worked on a truly warped version of Pascal,
   called “A.” When we found others were actually trying to create real
   programs with A, we quickly added additional cryptic features and
   evolved into B, BCPL, and finally C. We stopped when we got a clean compile
   on the following syntax:
                      for(;P("\n"),R=;P("|"))for(e=C;e=P("_"+(*u++/
                      8)%2))P("|"+(*u/4)%2);
“To think that modern programmers would try to use a language that
  allowed such a statement was beyond our comprehension! We actually thought
  of selling this to the Soviets to set their computer science progress back 20 or
  more years. Imagine our surprise when AT&T and other U.S. corporations
  actually began trying to use Unix and C! It has taken them 20 years to develop
  enough expertise to generate even marginally useful applications using this
  1960s technological parody, but we are impressed with the tenacity (if not
  common sense) of the general Unix and C programmer. In any event, Brian,
  Dennis, and I have been working exclusively in Lisp on the Apple Macintosh for
  the past few years and feel really guilty about the chaos, confusion, and truly
  bad programming that has resulted from our silly prank so long ago.”

After having read this I was Laughing out Loud and Rolling on my stomach. Its true a genius can make a fool of the world!! Every bit of computers 0 or 1 seems ephemeral now. It was an enlightening event......

DISCLAIMER: This extract has been taken from the book only for entertainment and sharing purpose. Anybody wanting to cite it for his/her book or any other purpose must follow the norms of copyright law and seek permission from the authors of the book. 

Sunday, March 21, 2010

God Knows What?

Openoffice.org is not properly synchronised with blogger.blogspot.com.
Know what it sucks when you post some article you wrote during your offline moments in openoffice.org. What will you do? Copy from the org file and paste on blogger. But this won't do as every time you copy paste it will add some meta tag which will irritate you and the things will become incorrigible. Today I suffered hard posting an article I had written a long time. But I carried out patiently and completed the pasting and was formatting it when something wrong happened and I did ctrl+z.
Guess what the complete article disappeared from the template.................
I was blank, furious..... and the devil saved it quickly to the drafts as well no way to recover....
Again the same the process should be repeated now to post the article....
In the mean time this frustration note!!!!!!!!

Beginner's Python Tutorial-- Plot graphs using MATPLOTLIB

I attended a Python Workshop sometime back at IITK during Fosskriti organized by a dedicated faction called FOSSEE. Here I'll share some of the knowledge I gained in a series of three posts. Below is the first one in the series.
GETTING STARTED WITH PYTHON
lets hissssssssssss.......
Guide to install Ipython-Interactive Python shell.(on a linux machine)
1. Install ipython- interactive python shell
   sudo apt-get install ipython
2. Install matplotlib and the support libraries for it:
   sudo apt-get install python-matplotlib python-numpy python-scipy
3. Type now on your terminal
   ipython -pylab
4. You should be able to see the ipython shell started. Don't worry about the warnings. Just look out for In[1]: This is your prompt where you need to enter the commands. You should be able to see a window like this:
Now you are ready to talk and plot in python.
1. Lets say hello to the world first(convention)
      type: print "Hello,World"
   output: Hello, World
Note: Python breaks the semicolon convention prevalent in most programming languages. It can read the return character to know where the line ended, so be careful when you press enter, as a new line means a new line of action for python.

2. Lets plot a curve now:
Matplotlib is a toolkit of choice for most of the python programmers not only because of the publication quality graphs but also because of the extensive library and documentation.  It gives a tough competition to the one commercial tool in this scientific plot area- Matlab!
Matlab users are going to find this very similar. But then Y Python? Simple- Python is open source programming language and Matlab is a propertiery commercial tool. Rest has more to do with ur choice and comfortability ;)
Here's a small HOW TO PLOT GRAPHS IN PYTHON(Matplotlib based):
   a) We define the values of x for which we plot f(x) on the graph using
       linspace(start, stop, step)
        x = linspace(0, 2*pi, 50)
   b) Now command it to plot the curve you want using plot(x, f(x))
        plot(x, sin(x))
   c) You can set the labels using xlabel and ylabel and title.
   d) You can display the legend of the graph using
    legend('sin(x)', loc=center).
   e) Annotate the point on the plot typing  
    annotate('local max' , xy=(1.5,1)).
   f) Save your first plot or figure using savefig('sinusoidal.png').
       Note: You may choose extensions of your choice.
   g) Close the figure typing close() or the current plot area typing clf().

Note: You can explore more about these commands by typing linspace? on the shell to view its help. And you can thus learn about various colors and forms in which you can plot a graph by typing plot? or help(plot) on the shell..

For your reference a complete script that u can straight away peruse by copying and saving in your home folder with .py extension is:

x = linspace(-2*pi,2*pi,100)
y = sin(x)
plot(x,y,'g',linewidth=2)
z = cos(x)
plot(x,z,'r',linewidth=2)     #Plotting red line graph of double thickness
c=0*x
plot(x,c,linewidth=2)
z=sin(x+pi)
plot(x,z,'p',linewidth=2)
z=cos(x+pi)
plot(x,z,'p',linewidth=2)
annotate('origin',xy=(0,0))
legend(['sin(x)','cos(x)'],loc='best')
xlabel('x')
ylabel('f(x)')
title('waves')
savefig('waves.png')
show()

You'll see an output something like this:


3) Plot using lists like:
      a) x = [1,2,3,4]   #creating a list
   b) y = [7,11,15,19]
   c) plot(x,y,'r')     #Plotting a red line graph
   d) plot(x,y,'o')    #Plotting coordinates
You will view the following curve:

Exploring the magic commands of Ipython shell--
How to save the commands u've entered so far:

1. Use %hist (history) command of ipython.
2. Select the command no. u want to save.
3. Save using %save of ipython. For instance:

In[]: %hist
In[]: %save first.py 3-15            # use no.s as stated on the terminal.

4. Running the script saved or general python scripts, use %run -i

In[]: %run -i first.py

How to exit the Ipython shell
1. Type ctrl+D
2. It will prompt a question asking-"Do you really want to quit? [y]/[n]"
3. Enter 'y' if you want to quit.

Links you may like:

To those interested in plotting dynamic graphs on their web-pages using python the following link would be of interest:

other related links:

one particular link of interest for those who want to explore the wide choice of plotting toolkits:



session 2
(will follow soon)