Sunday, 8 February 2009

Timeline of my life

You can get your timeline at this site




1982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009
EpochOn the 11th day of the 11th month, when the sun is in Scorpio and doctors are irritated and tired, a 5 kilo baby is born
( 1982 - 1982 )
The sleeping tigerThe boy grows up, learning thinsg fast and easy, apple of all eyes and troubling one and all
( 1982 - 1985 )
The beginning of schoolingHe is admitted to school at the young age of 2.5 years, the telugu speaking principal has high hopes, but has a change of heart after he runs all over the school screaming and tells the principal rceipies for food that mom cooked at home. That was the beginning at Tiny Tots School Duliajan Assam
( 1985 - 1985 )
Initial schoolingSettled down at Tiny Tots, studied well and moved at Kendriya Vidyalaya. Not sure or cannot recollect how much he studied but he did do quite afew things that are better not told at home, was not a bad boy buty was not innocent either
( 1985 - 1992 )
The urge to excelStared getting interested in studies, painting etc etc and begins to have dreams
( 1992 - 1994 )
The studious boyMoved to Hyderabad, learnt proper telugu, got class first, was even the leader of a class with 47 girls and 7 boys, and did everything a good boy would do. The evil streak died and he became a saint
( 1994 - 1998 )
Pre universityRealized how much he doesnt know, and how scred he is - embarks on a journey to rectify things
( 1998 - 2000 )
The computer bugWas intoduced to the C programming language by a cousin , is hooked immediately
( 1994 - 1994 )
The computer bug #2Is good at C now, decides to look towards Microsoft now, and starts using Visual Basic
( 1999 - 1999 )
The computer bug #3By the end of the milennium sets sights on Java, and gets the first computer he can play with without worries about spoiling it
( 2000 - 2000 )
EngineeringSwam through electronics and commnunications engineering, not sure whether he likes circuits or microprocessors, made friends and learnt many lessons of life, is officially labelled \"ITEM\" for being the odd one out in the class
( 2000 - 2004 )
The computer bug #4Has mastered Java, 8051 assembly and whole lot of things and thinks can conquer the world now
( 2004 - 2004 )
On the jobRealized there is a lot of things to be learnt on the job, is good at the job and is doing quite well, waiting to get married in August
( 2004 - 2009 )
Important Event #1In January decides to quit Infosys and join Oracle, but sticks back - not sure why
( 2007 - 2007 )
Important Event #2In Feb starts blogging and writing supercoder stories
( 2007 - 2007 )
Impotant Event #3In July asks the most important question ever asked: \"which building dear?\"
( 2007 - 2007 )
Important Event #4In August life changed completely when on Aug 15 he got engaged to his sweetheart
( 2008 - 2008 )
Mega Event!!Getting married on Aug 2 2009
( 2009 - 2009 )
1982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009

Saturday, 7 February 2009

Extracting review comments with Python

Often I need to exchange code over email with temmates who cannot access our source control repository due to network issues. In many cases, especially after a code review, I find that they have removed the review comments that I put in and I have no way to figure where I commented on what. This is also partly due to the not-so-good practice where I put the comments in the code using '//@@' as an indicator. To get over such cases, I wrote a simple Python script that reads all my Java source files and extracts these lines with '//@@' and puts them in a text file. This text file then serves as a rough guideline for me to review the code again.

Here is the script, hope it proves useful to someone else.



import re
import os

class Parser:
def __init__(self,pattern,outfilename):
self.pattern=re.compile(pattern)
self.outfile=open(outfilename,'a')

def walkDir(self,base_dir):
for t in os.walk(base_dir):
for f in t[2]:
self.processFile("/".join((t[0], f)))
self.outfile.close()

def processFile(self,filename):
self.outfile.write('Processiing file :'+filename+'\n')
self.outfile.write('=============================\n')
file=open(filename,'r')
for line in file:
if(self.pattern.match(line) is not None):
self.outfile.write(line+'\n')


if __name__=="__main__":
p = Parser('^.*//@@.*','testresult.txt')
p.walkDir('./code_with_review_comments')







Let me know how useful you find it!

Perf stats with Python

Last week we need to do a quick and dirty performance test for out Java application. The simplest way I figured was to instrument the logs with performance data for each critical step and for the overall end to end processing. These were simple log4j statements that used a set of predefined keys and logged - "****** key=value millisecs" - in the logs. We then put together a simple Python script to use regex and parse these log4j files, and spew out the statistics.

Instrumenting the Java logs is trivial, just decide the keys you want to use and put something like this:


long epoch = System.curTimeMillis();
// do your operation
logger.debug("******total_end_to_end="+(System.curTimeMIllis()-epoch));

Then to process the logs, use the below Python script





#import the regex package
import re

"""
This class is a utility class to calculate the statistics of the
data being recorded and store the data for reference.

The stats reported are a simple average, min and max values
"""
class MinMaxAvg:

def __init__(self):
self.min=0
self.max=0
self.sum=0
self.count=0
self.data=[]

def put(self,value):
#if this is the first value, set it as both min and max
if self.min==0 and self.max==0:
self.min=value
self.max=value
#we have a new min value
elif valueself.max:
self.max=value
#sum the data so far
self.sum=self.sum+value
#and increment the count
self.count=self.count+1
#store for later use
self.data.append(value)
"""
returns the minimum value amongst all the values
stored in this object
"""
def getMin(self):
return self.min
"""
returns the maximum value amongst all the values
stored in this object
"""
def getMax(self):
return self.max
"""
returns the number of values stored in this object
"""
def getCount(self):
return self.count

"""
returns the simple average
"""
def getAvg(self):
return self.sum/self.count
"""
returns the data used
"""
def getData(self):
return self.data

class ParseFile:
"""
open the file, compile the egex pattern and
set a objetc to track the stats
"""
def __init__(self,filename,pattern):
self.file=open(filename,'r')
self.pattern=re.compile(pattern)
self.minmaxavg=MinMaxAvg()

"""
parse the file and send each line for further
processing
"""
def parse(self):
for line in self.file:
self.parseLine(line)

"""
apply regex and parse individual line
"""
def parseLine(self,inputLine):
#match the line to the regex
line=self.pattern.match(inputLine)
#if it is a match
if line is not None:
#get the string representation
line=line.group()
#split at the first separator
line=line.split("******")
#split again to get the two bits that we need
data=line[1].split("=")
#get the category name
self.detail=data[0]
#and set the value to get the stats
self.minmaxavg.put(int(data[1]))

"""
This method parses the file against the pattern and prints the
stats to a file specified by the user
` """
def result(self,reportFile):
#parse the input file
self.parse()
#open the output file
f=open(reportFile,'a')
#write the results
f.write("========================================\n")
f.write("results for "+str(self.detail)+"\n")
f.write("minimum time " +str(self.minmaxavg.getMin())+"\n")
f.write("maximum time " +str(self.minmaxavg.getMax())+"\n")
f.write("Number of samples " +str(self.minmaxavg.getCount())+"\n")
f.write("Average value " +str(self.minmaxavg.getAvg())+"\n")
f.write("Data used "+ str(self.minmaxavg.getData())+"\n")
f.write("========================================\n")

#if running stand-alone
if __name__=="__main__":
ParseFile('application.log','^.*total_processing_time_per_request=[0-9]*').result('report.txt')






Hope this is useful to someone!

Monday, 2 February 2009

More snow ....

There is even more snow today!

Find a few pics .. this time from my DSLR :)

Canon 350 D, 70-300mm lens


Snow!!!!!!!!!!

Its snowing here in London ... bigest snow in 18 years ... and for the first time in the 2 years that I am here ...I am having a blast .. unfortunately my DLSR was out of batteries ... so I am waiting for tomorrwo .. hopefuly to get my film developed :)

A few pics from our cell phones ..







Sunday, 1 February 2009

Why I dont want to be perfect ...

I am not perfect, and I don't want to be ... its a choice that I made ... because I am afraid I wont be able to keep up with peoples expectations ... afraid that I wont be able to run twice as fast just to retain my position ... Strange isn't it? I read it is not common or normal for a guy born in the sun sign scorpio saying that he is afraid and does not want to do something, but I guess scorpios are by nature hard to understand, so the person who said that might be wrong himself.

I am no loser or idiot or a case of sour grapes - I am a fairly successful software professional, one in the millions of software professionals in India, working for a dream top Indian company and in London on a project. I am good at what I do and I do that with dedication,100%, and have yet to come across a project that failed because of me. I just look for challenges in the job and am open to experiments. I dedicate almost 75% of my time to work or technology - things that keep my day job running like a well oiled machine. I can be seen so much with my laptop that my roomies feel sad for me that I am not doing much these days.

I have a life as well, I live and enjoy my work, I live and enjoy the comfort of the feeling that tomorrow morning when I go to office I am doing what I like, and I am good at it. Apart from this I like photographer and I play with my Canon Rebel (350D) and Canon EOS 300 cameras whenever I have time. I have about 3000+ pics , a pro flickr account and 4 hard bound books of my photos. I write stories, do things for my family and the special person who has made my life even more exciting.

Thats 100% of my life as on today.

I am doing well, but trouble is that I dont want to change those percentages.

When I picked up programming in high school it was like supercharging my brain. I did not have access to a computer but I always took a piece of paper and wrote down code on that, running it in my brain. By the time I left college I knew a lot of things that my friends only had an idea about or had just read the name in a courseware. So my IT job was a godsend - I could do what I like and at the same time help out at home with the responsibilities. But after 5 years I realized that there is an ocean out there, and I am not sure I will be able to swim it all and get to the other side. I do my job properly,but every time there is something that I havent done or heard of or learnt. So I put in an effort and learn it. When I started out this list was fairly short, today I dont know how long it is. Each manager that I work with adds to that list. And each time I reprioritize that list, someone just shuffles it for me.

Right now I am not perfect - not professionally,not in personal life. People have differing, often conflicting opinions about me. I am good, but on this road to perfection I do not want to get sucked completely into anything. I want to find that perfect balance where I am happy. Happiness is important for me.

Not many people ask me how happy I am - they ask my salary, my take home, my savings from my work in London, my promotion chances, why I am in the same company after 5 years and one question that dominates all these is - when will I get ready to move on to the next role? Is there any problem?

What is this mad rush for? Can't I just sit down, enjoy the moment, enjoy myself for a while? Why should there be a problem?

I am afraid that if I try to be perfect in any part of my life I might screw the other part - I cant drown myself in my job neither can I leave the job to go to hell and enjoy my life. I do not have that freedom or background. I need both , and I cannot be perfect if I want to balance both at the same time. I just like this middle ground where I go to do my job, make enough to live comfortably and save some for the future.

People call me mad for thinking this way. They point me to the people who are not as good as me, they tell me that if I dont do certain things they will overtake me and I will be left where I am currently. I need to run, I need to keep up. I need to do my job, learn new things, prepare for higher role, make sure I am ahead of that guy who I am supposed to be competeing with and do many many things - I dont have time for myself or to just sit and enjoy. They quote lines like "if you enjoy your work you will find time for everything", "learn to do things fast in short time", "busy man finds time for everything" etc etc.

No matter how fast pr perfect I might be in my work I am bound to get tired of this race. A guy with 10+ years under his belt can tell me to work smart, learn grow - but can he say that he never got sick of all this? I am sure he cannot.

That is why I dont want to be perfect - I am good at what I can do, and I want to draw the line, make my own rules, sit down and enjoy the moment - I want to be happy and content. To hell with the world!