Friday, December 31, 2010

Time limit exceeded- Error!

When running the same code for sorting integers, but on a test case of size of order 10^6 I realized that it took more than 5s to sort the integers in python.

Here is my code:

import time, profile
def timing():
    t1 = time.time()
    f1()
    print "f1: %.3f" %(time.time()-t1)
    t2 = time.time()
    f2()
    print "f2: %.3f" %(time.time()-t2)

def f1():
    lint = int
    list = [lint(raw_input()) for i in range(lint(raw_input()))]
    list.sort()
    for l in list:
        print l
    return

def f2():
    list = [int(raw_input()) for i in range(int(raw_input()))]
    list.sort()
    for l in list:
        print l
    return
profile.run('timing()', 'sort.tmp')

Vim is really programmers best friend like earthworms are farmers'
Vim helped me write a test case of this size in < 60 sec, and now I am there ready with a profiler and the time module to measure the time it takes to run that sort call.. The sort call that is a built-in function is probably not the culprit, I think in case I could parallelly carry on the reading and the sorting process the much needed optimisation can be brought..
This particular problem at the codechef.com under the easy problems tab is not that easy to do in python.. Everytime I get TLE error..
Some handy commands in vim:
:set binary
:set noeol
let me turn off the automatic end-of-line vim adds to every file editted in it.. And the profiler and time tools are easily available on the web can be found using google!

Here is the profiler output.

>>> import pstats
>>> p = pstats.Stats('sort.tmp')
>>> p.sort_stats('cumulative').print_stats(15)
Thu Dec 30 16:17:31 2010    sort.tmp

         2103371 function calls in 114.964 CPU seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000  114.964  114.964 profile:0(timing())
        1    0.109    0.109  114.964  114.964 sort.py:2(timing)
        1    0.000    0.000  114.964  114.964 :1(?)
        1   93.992   93.992  114.855  114.855 sort.py:10(f1)
  2103357   19.643    0.000   19.643    0.000 :0(raw_input)
        2    1.110    0.555    1.110    0.555 :0(sort)
        2    0.110    0.055    0.110    0.055 :0(range)
        1    0.000    0.000    0.000    0.000 :0(setprofile)
        4    0.000    0.000    0.000    0.000 :0(time)
        0    0.000             0.000          profile:0(profiler)
        1    0.000    0.000    0.000    0.000 sort.py:18(f2)




Suggestions solicited.. Just in case someone has faced this before, I have to submit a solution in python that sorts the huge integers in < 5 sec..

Monday, December 27, 2010

Thinking out loud

I am getting bored and laziness is getting over me. I think I have to do something to prevent myself from corrosion. That too very soon..
First thing first
i need to get something that challenges me to work on it..
I do have many things on my head, that may be one of the reasons I am doing nothing.
Okay, I should split it into small, reachable goals with deadlines..
I should first move my blog on django+google app engine
when done i'll think of other things, first this, thats it..

What's wrong?

The day since I have joined the company, i mean i have started a so called corporate life.. i am getting as bored as I have never been.
I miss the bunking classes (though i bunked very less of them), building castles in air (khayali pulao), driving my scooty, screaming at home about all the wrongs that are happening and how I could change it given a chance :P
Now when I have the chance, I don't know what am I doing?
The problem is not with the office, the project I am in is one of the most coveted one in my company, and even I found the technology very interesting. also there is no problem of time I think I now have more time than what I had in college... We have flexible timings and access to almost all of what one generally needs.. (Gmail, fb, google; these are normally blocked in other companies) So there is almost no problem on the professional and technical part of the life..
So what is going wrong? I think it is the social life, the personal part that is getting screwed up.. I feel lonely, unenthusiastic, wasted, in short terrible!
Any suggestions what I could do to improve my life as well as living..

Note: don't suggest make a boyfriend!

Wednesday, December 8, 2010

Flashing N900 Indian Version, for Skype support

If you are using an N900 you've bought anywhere in India then odds are that you are quite disgusted of your purchase. By the set bought in India I mean a set bought after N900 was officially launched in India and you purchased a set with bill! not a grey phone.. Like I did :(
I was not aware of this complete thing, later when I knew I could not stand this and hence I gave back the phone to the shopkeeper nd asked for a fresh one, with bill. And though the phone was brand new the experience was very bad. And I was smitten when I found that there was no skype, (for those not aware, skype integration is the expertise of maemo). Also there was a lot of stuttering when I played songs in the media player. To make things worse, there wasn't any call summary displayed when I made a call or used internet. Those who use an airtel sim and live in Rajasthan or places where *121# etc. only work and there is no support for listening to your balance can probably understand my situation very well!
So, finally 3 days back I decided to flash my device with the global firmware of fremantle latest release. Believe me it is the best thing to do with your phone. If you are really considerate for your phone, then do it! To do it literally simple. You are just three simple steps away from this pleasant experience called N900!
  1. Get the flasher from here.
  2. Get the firmware binary here.
  3. Read this manual.
And trust me you are good to go. Nothing happens, everything your calls, your wifi, your gui and SKYPE works better than before. And you get those call summary as well!!!
                        So go ahead and flash your device!!!
                        Happy N900...

Friday, October 22, 2010

Cooking 'ratatouille' dishes, :P

WARNING: don't read further if expecting very tasty, book style, chefs' pride kind of recipe! Readers are also advised to try all this on their own risks! :P

After shifting to my PG - fooding facility or Hostel + Awesome residential facility, referred to as PH, whichever suits the boot, I have cooked food for myself for two reasons :
1. Feed my tummy,
2. Use the food raw material to prevent its wastage.!

The basic time and space tradeoffs have been related to the usual time, effort, material used in cooking a palatable dish.. Check out the recipe of my Kheere ki sabzi

Thursday, September 30, 2010

GSOC Phase of my life

GSOC, it seems is the turning point of my life, so I think I can identify 3 phases pre-GSOC, GSOC, Post-GSOC phase...
The post-gsoc phase doesn't seem that exciting so far as the Gsoc phase has been. The pre-GSOC phase is reserved for another post.. The GSOC phase is the one I would want over and over again.
The reasons for the above statement are:
    The freedom to learn and work on stuff of my choice.

    Work from home at my own comfort level.

    Work under extremely talented mentor.

    Never miss mom's food!!!

    Earn while you learn!!!

    Get as lazy as you can be :P

    Freedom from traffic and bad roads!


and many more...

What I enjoyed all this while:
learning stuff of my choice, like python, scripting etc..
mom's delicious food
chatting with buddies
late at night and late in the morning
cooking and innovating new recipes.. And treating mom with them!

All in all the best phase of my life!!!

Friday, September 24, 2010

Life Post GSOC

Well this is a post after a long time.. The just previous one was a draft which I chose to finally publish today, so lets not count it.
Gsoc has been the fun and the best time of my life.. But every time good or bad is not unlimited. So, Gsoc period also came to end; best part being success !!
Finally, post Gsoc I have found a day time job for myself that's not very different from what I have been doing till now.. This job required shifting to a new place called the Millennium City, or Mini Singapore which actually is Gurgaon, a genuine simulation of Singapore and a millennium city but not of this mind it; rather of the previous millennium. ..... I finally came to terms with this city and its roads and transport today when I found some good people who helped me without putting me into further trouble!! And I found my favourite bhutta being sold in the traditional manner... Simple thela-wala style of selling gave a humane feeling in this city of high rise buildings where people don't earn to live but live to earn.. They have feelings to listen to "Another day in paradise" but not the actual cries of a needy.. There are beautiful buildings hiding ugly faces.. There is a feeling of hollowness everywhere here... I don't know what to like about this city.. Its just a place i have been afraid of being to! But today i found life here, there is hope! I am finally feeling better.. And hence i am verbose.

Friday, August 27, 2010

Posting from vim using python to blogger

All thanks to Dennis for his cool python code and the post, http://djcraven5.blogspot.com/2006/10/success-posting-to-blogger-beta-using.html which enables to make blog posts from vim to blogger!!!
check it out, it is simply fun!!

Wednesday, August 11, 2010

Training the classifier or handling vmware errors!!

Training the classifier doesn't seem to be as much fun as I thought it would be.
Reasons I thought it would be fun:
  1. I had found some new malicious web pages, by simple google searches!!
  2. The lists for training the classifier for both the mal and safe classes was prepared.
  3. The only task was to now to pickle the features dictionary.
Reasons it became a pita:
  1. the vmware error, lack of memory, at the end of 12 URL scan
  2. the continuation of this error now, at each URL, and even after restarting the host machine, and allocating larger RAM to vmware.
  3. finally it rewrote the pickle file that it had learned, means features of 15 URLs..
I have googled for this vmware error, but haven't found any suitable solution.
I thought the OS were trained to handle batch jobs, very early after their birth. This anomalous behaviour is out my understanding!!
Any body with any relevant suggestions??

Sunday, August 1, 2010

Unarchiving Heritrix' archives - arc.gz

Those who have used heritrix for web crawling are aware of  the 'arc' format. For others, Heritrix is a web crawler (a million $ guess :P) which archives the pages it has crawled into arc format.
In order to collect the corpus for training my classifier I thought of using it. Though phoneyc would have been an option, but I had to collect as many samples as possible so I planned on using heritrix.
Configuring it is pretty easy as it has a nice documentation. Well, in order to extract the crawled pages I was searching for some script or tool (I am too foolish and scared of errors while coding, in short i am a noob!), so I wasted quite a lot of time googling.. Sometimes laziness is a boon, I wish I had been lazy to google!
Finally, I mailed Peter Likarish, a Phd. student at University of Iowa, who had previous experience with heritrix and obfuscated JS classification too, and he suggested that arc's are flat files and its pretty easy to extract pages from there. Also, some understanding of sgmllib.py helped me. using a handful of regular expressions and some loops, ta-da!! I got the code up and running!
For interested readers, the code is here.
I have tried it on some arc's, it seems to work fine. Well, in case someone tries to use it and run into a bug, I apologise for their inconvenience. Please let me know in case of problems, bugs, or errors. I would be grateful..

so, start crawling!!!

Tuesday, July 27, 2010

Blogger's unusual shenanigan ? safe : malicious

A very interesting thing happened while making the earlier post. I quite naively pushed the 'Publish Post' button after keying in the test javascript code snippet. Though the script was entered in the multiline comments construct /* */ of JS, but blogger identified it as javascript and started popping all the alerts there!

Yes!

This is not it, when I tried to edit the script to have '//' comment construct before each line.. there was no script to be found!
Blogger consumed the script, for all the alert calls the respective alerts were displayed and finally the post looked empty, without any JS code..

It may sound foolish... Well considering the fact that I am a /no{2}b/ this might make some sense...

Anyways, this also shows that any one can easily post any damn nasty JS code onto Blogger.(Any comments???)
Is blogger safe?

'top' property of 'Window'

The top element of the DOM in Javascript has the following properties:

   1. It refers to the [object window] or the self.
   2. In case of frames or iframes, as obvious, 'top' refers to the top object that created the [i]frame i.e. the [window]
   3. But when we do a window.open(), then the top of this window refer to itself and not to the parent window.
    ps. to refer to the parent window from this newly created window there is the 'opener' property.

The following code explains it clearly...

/************************ Toping.js *******************************/

//var i = "i am at the top."
//function foo(j)
//{
//return eval(3*j);
//}
//alert(foo(3));
//alert("self: "+self.location.href+"\n"+"top: "+top.location.href);
//document.write();
//o = window.open("teesri.js",'win')

/************************ bottom.js ******************************/

//alert(top.i);
//alert("self: "+self.location.href+"\n"+"top: "+top.location.href);
//var foo = top.foo;
//alert("top ka foo in bottom : "+ String(foo(4)));
//window.open("teesri.html","win");

/********************** teesri.js ********************************/

//alert("self: "+self.location.href+"\n top: "+top.location.href);

It might be a trivial concept for some, but it took long to sink in, for me!

Nothing malicious

There is nothing malicious in the last post related to 'top' attribute. Its just that I was unaware of the fact that blogger doesnot accept the multiline javascript comments, or perhaps I commented out the script incorrectly that there are so many non-sensical alerts popping up!
I sincerely regret the annoyance being caused. But, Blogger seems to have consumed the JS code :(
So, I am in a fix how to remove that code...
I appreciate suggestions on this!

Saturday, July 10, 2010

Malicious Javascript - blueprints

Javascript might be a great scripting language but it has been recently been abused a lot to carry out drive-by-downloads attacks. It targets the browsers and the plugins vulnerabilities at the client side.

There are certain features in the structure of the malicious javascript, though, which can be used to detect its presence with high precision. My GSOC 2010 project aims at finding these features and extracting them and thus classify scripts on the basis of these scores into benign and malicious. Finally integrating the complete solution in the low interaction client honeypot - PhoneyC.
I have extracted 9 features, which have been mentioned by a lot of people in their works. These features have been extracted from a very very modest corpus, which is not very broad yet, of 15 benign and 10 malicious JS samples.
The findings expressed as graphs, file against the feature value can be found here. The graphs show malicious scripts features in red and benign scripts in blue.

1. average characters per line
2. average eval() argument length
3. string definition to string use ratio
4. # unicode characters
5. # lines in the script
6. % human readable characters
7. % white space in the script 
8. # words in the script
9. dynamic execution calls

Though the results aren't very encouraging for all the features, but some of them like the string definition to use ratio, % human readable characters, %white space, offer some hope. Improvements in the implementation of the features extraction with little assumptions is required to build a proper extractor for the classifier.
The code for the feature extractor and the classifier may be accessed in my svn branch of phoneyc under njain-anomalydetection.

I sincerely appreciate the comments and reviews on the current work feature extraction and classification.
p.s. - truly speaking,this is my first attempt at regex, pickling, or in short, programming, in that case. All thanks to the mentor for his able guidance and constant motivation.

Monday, June 14, 2010

Malware: The Positive Aspect

Consider a life - Rules decided by the authority, People following them, Vigilant Guards at work 24X7... Too good a life to live. The future of such world -
Fools, crippled generation being born - quickly followed from law of Use and Disuse of the organ by Lamarck:
"In every animal which has not passed the limit of its development, a more frequent and continuous use of any organ gradually strengthens, develops and enlarges that organ, and gives it a power proportional to the length of time it has been so used; while the permanent disuse of any organ imperceptibly weakens and deteriorates it, and progressively diminishes its functional capacity, until it finally disappears".[source: Wikipedia-http://en.wikipedia.org/wiki/Jean-Baptiste_Lamarck]

Now consider our life - Struggle for existence onfile as well online, thanks to corrupt security government officials and ever enthusiastic and sharp hackers, Rules decided by the authority along with a backdoor!, People follow them as per convinience, Vigilant guards causing inconvinience...
Future - Evolved humans take birth, world civilises, OPtimisation of survival factor!!!

Clearly, the above pure world which is very nicely planned, a perfect dream world - is only fit for a dream as it is stagnant and therefore has almost negligible information and 0 entropy. Our world, on the other hand, may seem too messy, too problematic and disturbing but it is the one which is vivid, lively and bound to improve in existence level as there is always a scope of refinement to the current status. This is analogous to the river water, which keeps flowing indefinitely. It gets polluted on the way but it is pure where it emerged first and when it finally merged in the sea! The journey is its life and disturbance on the way is the spice of its otherwise monotonous flow...

Similar to this is our security professionals vs. Hackers game. The game is on only until hackers find another way to circumvent the current policies or find some vulnerability to exploit in the current setup. The malwares, worms, virus etc. may seem a nuisance on face but they are the driving force for all this security hype. Mind it the security professionals have a job only until hackers are interested in playing ;)
Therefore its a sort of win-win game. The security professionals are on a constant hunt for a best fit policy, secure software and the hackers are in constant search of vulnerability in the software and the trapdoor in the policy. You remove one cog the wheel stops and the future which we were imagining to be a storehouse of opportunities suddenly ceases to exist! All this malicious stuff is therefore the spice of a security profs food and the vulnerability in the operational system are the driving force for the hacker. Mind it a challenge interests only when it is difficult to crack.

With the limited knowledge i have of the field, I am fascinated by the way these people circumvent the rules and the policies to bring down the weak and vulnerable system and work constantly for improving it!

Tuesday, June 8, 2010

Unusual Redirections

The link www.bbassett.net/njs as well as www.ngs-js.org are both redirecting to a truckexplorersite. Since yesterday, these two links are both redirecting to the one site www.truckexplorer.com
No exploit or anything unusual happening has been detected yet.

Monday, June 7, 2010

Anomaly Detection

Anomaly detection is a unique approach to find the odd one out or malicious value. The approach basically involves learning the normal behavior and then detecting variation from this established behavior, which is called a profile. The variation is found based on a model. A model supports in learning as well as detecting. The crux of the approach is "the model".
A basic understanding of the approach can be had from the following program which learns A, an arbitrary integer variable. This model learns that A normally lies between the minimum and maximum values input during the learning mode. It also learns a threshold as 10% of the mean of the entered values. After successfully learning the values of A the model switches to the detection mode. In this mode the difference of the entered value and the mean is compared to the threshold. A difference greater than the threshold is marked anomalous and the value is put in the anomaly list else it is appended to the normal list of values. This is a very naive but working implementation of anomaly detection approach.
The original python implementation is here:

class learna(object):

    def learnA(self):
        """a function to learn a"""
        list=[]

        list=l.learn()
        low=min(list)
        high=max(list)
        avg=sum(list)/len(list)
        print "average is",avg
        l.detect(low,high,avg)


    def learn(self):
        print "learning mode"
        alearned=[]
        for i in range(5):
            al=int(raw_input("enter integer value for a."))
            alearned.append(al)
        lower=min(alearned)
        upper=max(alearned)
        print lower,"<",upper
        return alearned

    def detect(self,low,high,avg):
        print "running in detection mode."
        aentered=[]
        anomaly=[]
        normal=[]
        anomalous=[]
        threshold=0.1*avg
        for i in range(5):
            ae=int(raw_input("enter current integer value."))
            aentered.append(ae)
            if (aehigh):
                anomaly.append(ae)
            else:
                normal.append(ae)
            if (abs(ae-avg)>threshold):
                anomalous.append(ae)
        print "total anomalous value",len(anomaly)
        print "total normal values",len(normal)
        print "total entered values", len(aentered)
        print "total detected anomalous values",len(anomalous)

Tuesday, May 11, 2010

Bye Bye! B.Tech

Being an adult with child's freedom
That is a bachelor's kingdom!!!
Late entries, proxies & bunks!
All of this was a lot of fun..
Copying assignments ;) teasing friends :P
The entropy was always at its best!
Eavesdropping into friends' diary
to find only their crushes' history :P
The golden period, buddies, now sends
its best wishes for you, as it would soon end :(

Thursday, April 15, 2010

The Naughty Cooker

A knock on the door----
my sweet, vivid dream it tore.
Half-asleep I opened it,
to my surprise there was kept a kit.

The kit was like a big basket--
contained in it was a cooker and gasket.
I kept it aside and tried to sleep,
Noise again woke me, just at the dream leap!



Surrrrrr...Surrrrr.....
Oh God! whats that?
Terrified I went to the kitchen
The cooker was sneezing like a chicken

After putting all things in order
When I was to sleep and was on border,
There was a sound similar to that of an explosion,
At a time, when I was swimming in the dream ocean.

Peeping out of my room, What I found
was everywhere 'khichdi' scattered a pound
God forbid, this naughty cooker
Had at last burst like a boomer!

Annoyed, at the cooker, I lost my temper
called the number and started to hammer,
The head of the cooker repairer;
Before I found it was a wrong number!

Sunday, April 11, 2010

Structure of Implementation (original One)

STRUCTURE OF IMPLEMENTATION:
I drew it as an ASCII figure in the proposal and something unusual happened with the whitespaces, thus the figure became a mess. Please use this one for further reference.

Tuesday, April 6, 2010

Implementation of lamport's clock in Python

Here goes the lamport.py------

p = dict()
event = dict()
def clock():
    """local clock update"""
    procsno = int(raw_input("enter the no. of processes.\n"))
    for i in range(procsno):
        print "enter the events in process",
        eventno = int(raw_input(i))
        event[i] = eventno
        for j in range(event[i]):
            p[i,j] = j+1
            print i,j,p[i,j]
    mes = int(raw_input("please enter the no. of messages sent"))
    for i in range(mes):
        psen = int(raw_input("sender process"))
        esen = int(raw_input("sender event"))
        prec = int(raw_input("receiver process"))
        erec = int(raw_input("receiver event"))
        p[prec,erec] = lamportclock(psen,esen,prec,erec)
    for i in range(procsno):
        for j in range(event[i]):
            print i,j,p[i,j]

def lamportclock(si,sj,ri,rj):
    """global clock update by message passing"""
    q = p[si,sj]+1
    if q>p[ri,rj]:
        return q
    else:
        return p[ri,rj]

All reviews and errors and bugs report are solicited. I would be very happy to know if it helps you in your struggle with C implementation!
This one is really bad in the output view, though the internals is OK.
A better will be posted if I did work on it :P

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)

Wednesday, February 24, 2010

Human Behaviour


All of us have met the two people who are the boundary elements of all humanity. The ones on the top, who we all admire; and the ones on the bottom, who we all despise. The one thing, apart from from the striking dissimilarity, they have in common, is INTEGRITY.
The ones at the very bottom the place where you might not be able to locate them even at an angle of depression equal to 90 degree..., are very high up on the moral ladder than most of us are! They value their values more than the pleasures of living, which on the face value seem satisfactory. These pleasures fool most of us. But these souls are never chasing the ephemeral honey, lust has to offer us..., which shakes the very floor on which our world stands!
These people compromise on these time-bound-happinesses in quest of their place in these world. Only a room, where they can have fun with themselves and their values over a cup of coffee! These people get mocking remarks in return of their nonchalance...
On just the other end of the line lie their counterparts, truly speaking the ones who have trodden the
path these so called burden on this earth or foolish people are walking on, long back. These are the people whom we adulate. We watch their interviews, follow their life-styles, mug up their quotations (only to reciprocate at some public gathering), paste them on our walls, buy out their autographs (to auction them) and what not...., try to pose to be them just by wearing their pants and forgetting to remove them before the very obvious, using the toilet :D
And now just look out how the TRP's of the news channels increase for the coming days with Sachin having given them the cow which sells not only its milk but also its skin.Without any actual logic the channels will correlate the stats and the numerology and the stars of Sachin with his double century and people will finally end up believing that it were just for stars and numbers he scored a double century else this is the same Sachin who's out many a times at 0. :D

 

Friday, February 19, 2010

HOCKEY WORLD CUP

HEY! People do you know the hockey world cup is being played in INDIA on 28 feb 2010....
and our public media which claims to be a highly unbiased in its coverage but just look guys! has anyone of us read any news about the Hockey World Cup... 
How come such a great event has missed the eagle eye view of the media.. The media which runs after the news and many a times create some of these, that too sensationalizing them to hyper extent has missed this event of national importance........
come people lets together promote this event by sending messages, writing blog, tweeting and buzzing!!!!!!!
Now we have the power of the media and are not dependent on these already sold out people......

Tuesday, February 16, 2010

Leisure Time

These are some of the art works that I do
just for pleasure!! at leisure --
My school art teacher may again give me a B+
What do you people think??


Plz rate me higher!
Ok do what is actually true :)

Hey these are not pics of the pages on which I drew it using pen or paper..
I drew these on GIMP using my digital pen!!

Monday, February 8, 2010

Rare Rains

Rare rains of this monsoon 
Drenched me thrice, these noon.
Rains this time were declared precious 
But they showered on me, unconscious.

I have had little encounters with rains so far 
Perhaps the cover i held, bundled me in a car :)..
Hey! this time i dont know how??
The key was stolen somehow..

And the naughty rains placed the trap 
Caught their rare prey and clap slap.. 
Freely falling and endlessly lying
On my forehead and shoulders, busy prying!

Deceptive waterfall;
disguised as rainfall...
soothed the heat within,
was perfectly relaxin'.


Saturday, February 6, 2010

HOWTO on simply networking

Hey! it was a real fun today. I had to learn nat and I live at my place not in the hostel where you can have ready access to the network and you know the various ip addresses present at your disposal and obviously a lot of colleagues. So does this mean I could not learn nat today? It just struck--why not connect the two laptops I am having with the lan wire, and try something? I did.
I was like knowing that this is gonna happen and it should; but how? The lappies were not connecting! Then I thought of changing the IP addresses and the gateway address- manual connection. And yes! I was on. I started a terminal. I din't know any other place to test. I thought what can I possibly do now- telnet, ssh?? I tried both but 'connection refused'! (Well, as must be clear by now; I am a beginner to all this networking and have till now always remained confused on how this giant Internet machine works?)
Then I resorted to the beginning- ping! I typed 'ping address'-the address I had given to these machines, 10.10.0.2(firewall) and 10.10.0.3(server) and yes that happened. Well nothing big.Then I did 'wget address', an attempt to establish an http session. On one address connection refused and on other a file 'index.html' was transferred. I was puzzled!
I searched for the file. On opening the file I realized that the file was the one I wrote a few days back. This was good, I could now relate. Since I had an apache server up and running on this machine, therefore this machine could respond to the 'http request' and send index file during wget...
WOW! The questions in my mind were being answered though new questions were arising. But I had, in my otherwise undirected attempt, actually established a very crude and basic network of two lappies and a lan cable.... Well now I'll hurry to cook more using iptables, I had to learn nat! catch ya with further results soon!

Wednesday, February 3, 2010

Viral Song

Once in our life we all hear songs we particularly hate. We would have never agreed to hear these even in return of a lot of goodies. Its not because we don't have taste, rather its the exact opposite. Put the other way-If u have never despised a song in your lifetime; u surely don't have a taste....[:P]
If u have heard such a song then u must have also had a feeling to just tear off the thing thats playing it. Just peel off a cello tape and stick it onto the mouth of the singer, or kill the composer rather the recorder or more precisely the distributor. I, in fact, think where have those activists disappeared, why are they not opposing this song, why don't they launch a campaign against it and ban the playing of this song??
But then amidst all this turmoil something happens and I start finding a wall or a cello tape for myself, hang myself upside down.....Because leave apart the player I am now singing it...(oh!) It is played and replayed in me.. Almost congesting all thoughts and denying service to all thoughts which try to curb the playing of the song(DOS attack)... I am under the attack of the most malicious music!! A viral song has got into me and is now reproducing at its highest rate... Never felt like this? Hear this one then-
An example

Monday, February 1, 2010

When did future switch from being a promise to a threat?

When in the present of 2006, I got a gift wrap of “NOT SELECTED” JEE score card, my future switched to being a threat from promise. Until then future for me was a bright, glossy promisory note, but not anymore; as now the promise bearers had disowned it.

Since childhood I had studied hard, always stood first in class, as it was believed to be a practice with highest ROI.
Take coaching, study hard and smart, 36 hrs in a day of 24, get into IIT and live a life beyond imagination........
So we invested in money, year (after 12th) and faith in the bubble called IIT-JEE. But the bubble had gone bust and now I was facing The Great Depression of 1931 in 2006.

This depression unlike the true economic one started recovering soon, as I managed to secure admission in HBTI(considered next to IIT Kanpur, it actually is ;) and one among the top 50 engineering colleges of India). Soon after being admitted, bound by Schumpeter's economic cycle my future boomed, as again I secured a very promising percentage in first semester. So,
B.Tech in Hons., job in an MNC, great package.......
Again the bubble started building but this time I didn't blow air in to this bubble, I stayed away from it. “This bubble could not fool me again”, I said to myself.

Now when by the end of 2008, once again the economic carriages went out of control, into the slump under the gravity of greed and mismanaged decisions of the investors, disturbing the equilibrium of the economic forces of supply and demand, in short the bubble went bust again; I sit peacefully in my room, unperturbed......
This doen't mean I am mean or indifferent towards the world or any hermit etc. I am no anomaly to the current structure.

Through the past experience I have learned that this future is analogous to the 'stories of sheikhchilli' we heard in our childhood. In these stories he never bought any milk but did manage a flood of tears for spilling it.
Thanks to Chuck Palahnuik, to present this question before the world, which transformed it into a million dollar question but forgot his real billion dollar quote-

“ We are not special. We are not crap or trash either, we just are. We just are and what happens just happens!! ”

So, we must stop speculating on the promises or the threats of the future and start excelling in the tasks in hand, as it is rightly said- “A bird in hand is worth two in the bush.”

Sunday, January 31, 2010

Philosophy of Life Klotski style!


Yesterday night I was playing snowdrop of klotski. A thought struck me today morning while I was rising up from the bed. Life is similar to klotski as it doesnot allows for any undo or redo move, you go on just playing. there is a striking similarity between our life and klotski, look at this:

1. One game, until u alt+F4/ctrl+R, is a life.
2. F1 is your teacher, similar to the real life teacher.. boring theory ;)
3. Each stage is a stage in life, getting difficult ever..
4. In "only 18 steps" you are an adult, irrespective of the fact that you actually have grown- mentally ;)
5. You are offered three ways to play(live) klotski(life) viz, stick to play until you win(live life) or ctrl+R(consult doctor and start afresh, costly decision) or alt+F4(commit suicide).

there are generally no explicit constraint on the no. of moves in later stages, so u can play at ur ease and peace of mind. what happened yde was while playing that I went on playing for long and every now and then after certain moves I would feel I was about to crack, but no.... again I was stuck.. there were 3 choices- stick, ctrl+R, alt+F4. I stuck. This stage I had cleared in 67 moves a week back, how was it that this won't clear now? I was determined to do it, however long it took... so, with 132 moves I finally cleared it. I was now promoted to red donkey stage. This is just like the life, one who never quits is regularly presented with a new challenge. With each challenge he gets all the more stronger and wiser.

At all point in klotski you can reach back to the point where you started, you are never die or finish your energy, unlike other games. You don't have to fight others in klotski, only let loose your mind horses and stray in the field with blue chocolates of various sizes and orientation, controlling the temptation to eat them :P Don't worry about your neighbor and don't quit.. you'll always find new ways to bring the green block out...

To Be or Not To Be!



God is just one letter short of good.That too a zero if you see... When the creator is good then how can the creation ever be bad? Just hold on to the faith intensely and patiently,... without waiting for the result and you will sure find the thing you were looking for... I have seen very deep rooted firm believers and mark it- its really easy to choose a path and walk on it if only, you don't think twice or reflect upon its utility or why you chose it or is it good for you and blah blah...... If you just do and keep on doing ways open themselves! They may look as unknown though, but mind it, they are not unknown to your true self. They are just there, waiting for you.
In your heart, deep within, you know you too are aspiring for them but you don't know whether the road you choose will lead you there. But my dear! thousands of rivers converge in a sea and all seas are one; though may have different names. Similarly all paths converge! to one supreme place; though may look different on surface. Don't think after choosing as once. You've chosen. The time to think has gone. Its time to act now and when while choosing you never acted then after choosing? You shouldn't think friend! ACT!!!
Time comes and it goes never repeats; so never repent on a decision made or think twice on a path sought cause when after you'll reach ahead you will start realizing that this was only the one you were looking for. A river was never taught the road it should take or the path, which would be best for it and the river never looked on the path rather enjoyed the path it took and instead of taking something from the path it gifted it-- "GIFT OF NILE".
When Ganges may have emerged from the Gangotri it might have asked various rocks and plains to give it the path but they all being silent could not answer to her and thus she decided to turn silent herself too; and flow, rather than talk to anyone on her way to the ocean. She took the way herself, through the northern region leaving behind Rajasthan and Maharashtra and did not reflect back on the decision- 'Whether it would lead to the Bay of Bengal or the Arabian Sea?' Not once out of any confusion or perturbation did she change her course... Just rolled ahead with all her might. On her way she established plains and coasts and most fertile regions of the country and we know she did meet her destination. Though the optimal or the best path, in our language of computers, may have been to the Arabian Sea. Quick and Short...
So don't think after you choose and don't take long to choose... ;) Play it time bound when you have the most energy during the UPPER COURSE just flow; and when in the MIDDLE COURSE you start settling, remember your goal; by the time you reach the LOWER COURSE you will have gained so much that who ever comes in your way will get enriched. Just as a DELTA gets best of the sediments. You will sure, reach your destiny.
Life, Dear! is not a race and you have no competitors... Its a one man's play. His quest. Its not about where you reach, but about the way you took to reach and how enriched you are by the lower course! Remember hold on fast and strong to just one faith; in that matter, it can be anything but as experienced, God is the easiest and safest but difficult at times, as he silently takes all the blame on himself and never preaches you about himself; so its easy to get lost! Move ahead. Don't compare and contrast. Don't try to store huge data in your small brains and do data mining operations of, studying associations and correlations. These operations are very expensive both in space and time ;)(remember, some polynomial time complexity for just the database of the size of gbs). Your memory which stores a lot of data and has limited computation power as compared to supercomputers, computer theorists say, these operations themselves will take many lifetimes...

Walk buddy! The road is waiting for you to traverse.. It had been there, since you were born and has been preparing itself to get your warmth...

A Genuine Request!


Don't express this love
which I don't deserve.
Don't show me this magnificent world,
only to make me realize, my place is dirt.

Don't feel sorry-- my dear!
only to exhibit-- that u r near,
Don't kill my worldly ignorance
by ur wisely simulated fragrance

Don't show that u care
when actually u can never dare
to break me free
as i fulfill ur charity spree!

Hey folks! It is only u who nurtures this tree;
and later shrug calling it beggary!!!

Saturday, January 30, 2010

LIVE, Don't just survive!


U know u are near...
But still the fear,
In u like a bear
Has the strength to tear;
The faith u held dear.

Try once and keep
Laugh and don't weep
Reason but don't shout
Then every life's bout
Will be a gentle stroke--

Which will keep u alive
And ask u to Dive;
Into the depths of life
And never ever lead to strife!

Its ur tryst with destiny
Your way ahead not a mutiny
Don't run in the life
You won't get this twice :)

Time once gone is gone forever,
But moments lived are the ones remembered!

Blind Spot in Human Eye!

The blind spot, in the eye explains why many a times though an object is in front of our eyes but invisible.

Just as this spot may go unnoticed by most of the rays that fall on our eye; it is correct that a ray which falls on this spot goes unnoticed too...... thereby explaining the fact our look of the world is biased and skewed!!!
Every one of us is blind, some to complete others to limited extent, depending on the size of this blind spot...

KEEP STILL


























From people who show kindness, BEWARE!
Rise above them? U shudn't dare......
Intellects are something they don't care
Everything except ur happiness they share........

True empathy in them is rare
Sympathy and mockery is their pair.
You must always weep is what they accept as fare
Even ur deserving soar, prized!­ may lead them to despair.

If u really wanna rise high.
Touch that height of the sky!
Set urself free­­­­
from these emotional spree....

This world, believe me, is hell...
as when in true pain u yell..
forget a helping hand, they would happily sell
Your self­ respect, if you tell....
them once that it pains.
You have given the hen that gains.

They'll cash your sorrow.
And when, my dear, tomorrow...
YOU RISE!!!!
these fools, wise
will kick your ass.
to ensure u don't find solace...

So­­­­ decide for urself..
KILL or GET KILLED.

Don't kill these mocking birds..
As they are nothing more than shits..
Just ensure you kill
that one thing in u, which will
perturb u, when they point to ur hill.
Hey only, KEEP STILL....