Thursday, February 22, 2007

python string += string

I use the string += operation very commonly in all my python programs, and sometimes store a few MB of data in memory before flushing it out to disk.

I just learnt that its implementation makes it a very slow operation. Basically, in python strings are immutable. This means += operation is destroying and creating objects on every call. Imagine doing this a few hundred thousand times in each program.

Today, when a simple loop was taking infinitely long time, I was forced to investigate, and sure enough someone had explained it on this thread on python forum.

But I cannot keep invoking file ios for each append operation either. Even though file writes already have buffering implemented, I like to explicitly store data in memory for a few steps of string appends, and then flushing it to disk. This is important if you want to monitor the progress of your program using these logs - deterministically - such as every 1000 steps of the loop. I wrote this simple class that makes this task very easy.

class hugeFileWrite:
def __init__(self, fname, step=100):
self.sout = ''
self.step = step
self.fname = fname
self.count = 0

f = open(fname, 'w')
f.write('')
f.close()

def addString(self, smore):
self.sout += smore
self.count += 1
if self.count > self.step:
self.flush()

# Make sure you call flush() after your last addString
def flush(self):
f = open(self.fname, 'a')
f.write(self.sout)
f.close()

self.sout = ''
self.count = 0

Wednesday, February 21, 2007

Google 101

Google folks are offering a class in UWashington - CSE 490h: Problem-solving on large-scale clusters: theory and applications.

What we study in the distributed systems classes is quite basic, and bit outdated compared to Google like infrastructure. This class might be pretty useful for people developing large scale cluster systems.

Also, see this talk on Google Cluster covering GFS, MapReduce, Sawzall and BigTable.

Thanks to Greg for all the pointers[1][2].

Friday, February 16, 2007

inspiring

Every once in a while, you come across acts that are inspiring. Speeches that boost up your motivation.

The famous inches speech by Al Pacino playing the football coach in Any Given Sunday:


And this image. (The website I found this image had some copyright notice, and was warning when I tried to copy this image. I hope I dont find myself fighting lawsuits for posting it here.)

Thursday, February 15, 2007

Learning the tricks of the trade

Industry experience adds a lot of weight to any person's resume. Sure, coz you learn many tools that are used in industry. But, I have started to believe that its partly also because you have learned how the system works.

When new, you dont want to come out of your mould, but sooner or later, you tend to give in, and start to pick up the tricks of the trade.

This is quite beautifully illustrated in this segment of Devil wears Prada on You Tube. I dont know how long this segment will be alive due to all the DRM issues. But until then, enjoy.

Tuesday, February 13, 2007

All the whinning about high salary of a CEO

I came accross a very interesting debate on the high salary (1 M) of Paul Levy, the CEO of a 100 B hospital in Boston. In a rare move of its kind, Paul has justified his salary and invited comments. As others, I am also impressed with his openness in such a political issue.

The major criticism are about the hospital marketing itself as non-profit, but using its size as the justification for 1 M salary of its CEO. Also, some people argue that a part of his salary could be better off being spent on acquiring additional resources for hospital.

I am actually just stepping out of school, and have seen very little of how economy and society operates. However, being an infant in the working class, impressed with the simplicity and democracy of a capitalistic economy, I find any opposition to his salary ridiculous, to say the least.

I completely endorse his salary. I think in a capitalist economy, salaries should be commensurate to the contribution of the individual. We need to pay as much as it is required to attract the most suitable talents.

Infact, unlinke some commenter, I dont even find anything wrong in athelets earning millions for just catching a ball. I dont think just because being a doctor is socially more noble than playing baseball, it deserves more respect and pay. If hospitals help people live longer life , entertainment helps people live happier life . In the end, what good is the longer life, if you werent not happy in those extra days.

As to someone trying to reframe the question, by saying we could pay Paul 0.5 M and spend the other 0.5 M in hiring extra nurses. Well, the thing is, Paul would perhaps move onto an organization that pays proportionate to his talent. Or may be wont strive so hard if not paid proportionate to his efforts. And therefore, this move might actually be counter productive. Its not a simple linear system, you see.

blogger pains

Why is switch to google's platform implying so many inconveniences for the users of Blogger?

First, they asked to do what-not-i-dont-remember. I was just clicking on whereever it was asking me to click. And then, it told me, I am now using Google version of Blogger. Well, okay! Why couldnt you make it simpler and more transparent to user?

As if thats not enough, everytime I now come to Blogger, I have to login twice. First, I login using my previous Blogger identity. And then it detects that this previous Blogger user is now using Google account. So gives me another login screen.

Why cant you use the same login screen for both the accounts, in the backend check against both databases, untill all your blogger users have moved into Google account? Which certainly would never happen coz of so many idle accounts. So until when do I have to keep logging in twice to use Blogger?

Another related bug (or is it a feature?) in Google Apps is, whenever you want to use some service, such as, Gmail, Orkut, Google Account, Blogger, you are required to login for the first access to each of the application. However, as soon as logout from any of them, it automatically logs you out from all the application. Well, why is this unsymmetry?

I will survive

Living in Midwest (urbana-champaign to be precise) makes you very strong.. well atleast in fighting against weather.

Today, we have prediction of over 1 foot of snow. Over 5 inches of snow fall happened overnight. Here is the note from Chancellor of UIUC:


Chancellor Richard Herman

All classes have been canceled for Tuesday (Feb. 13) at the University of Illinois at Urbana-Champaign. More than 5 inches of snow fell overnight, upto another foot of snow is possible by Tuesday night and a blizzard warning...


So what exactly is all this talk about global warming? On the one hand, we have a-glacier-like-situation in urbana.. on the other hand, we have polar glaciers melting. Perhaps, global warming just implies severe changes in climate.. not that it would be warmer in absolute terms.

Monday, February 12, 2007

Founders at work

I really liked this book by Jessica Livingston.

Its full of inspiring stories. I particularly like the first hand comments that are generally lacking in many other similar books I have read.

I also liked the fact that its not just a collection of super-successful-cant-be-replicated stories of Microsoft, Yahoo, Google, Apple. It covers a wider spectrum of companies, many of which happend in quite recent times, which makes it easier to relate to.

Thursday, February 08, 2007

the power of web

I really liked the following video that illustrates what is web, and how we can use it in an influential way. As John Battelle also points out, equally intriguing is the fact that the creator isnt an engineer but an anthropology prof.