Freedom and All That

March 3rd, 2009

I’ve just finished posting a new blog entry on XP-Dev.com on the definition of Stories, Tasks and Bugs from XP-Dev.com’s point of view. However, the beauty of it all is that users make XP-Dev.com their own. They end up using it for various other purposes other than software development (and agile at that!). They are free to use it whichever way they see fit.

In my blog entry, I said:

However, this article (and future ones) are only guidelines – you are free to decide on how you’d like to use XP-Dev.com.

“Free to decide” - these words triggered a memory from the past.

Back in 2003 I was doing an summer internship/job with Lec here in the UK and was rushing back to their office from Victoria station in London. I was running late and did not have enough time to read the notice board on which platform I was meant to catch the train from.

I ran to the first person who looked like he worked at the station, and I asked him which is the next train to Bognor Regis (Lec HQ). Apparently there were 2 - one that was leaving at that moment, and another that was leaving in 30 minutes. I wasn’t too sure which one my ticket was for, and showed him my tickets and asked “I’ve got these tickets - which train can I board?”.

As soon as I finished my question, he immediately replied “Take which ever one you’d like - it’s a Free country”. He didn’t bother even looking at the tickets!

With adrenaline still rushing through my heart, I thanked him, ran to the train and boarded it. The train left a minute later.

I have always comeback to this little episode whenever I think of usages of a tool or even idea - let it be a handy tool (screwdriver, etc) or even an edit (one of the team asking whether its OK to use Vim instead of Emacs). I have a 2 second flashback to that moment in Victoria station and reply to them in the same manner - “Its a free country. Do whatever you want.”

And this is the beauty about building tools that people use, like XP-Dev.com. Everyone has their own way of using it and it should be just like that. No hard rules, everyone gets to do it their own way, and everyone is happy.

There’s a saying “With freedom comes responsibility” - so, just don’t do anything unlawful.

XP-Dev.com : Another milestone

March 1st, 2009

So, it has been 3 months and a bit since the upgrade to the new platform that runs the current version of XP-Dev.com, and it has been eventful. There was the release that took a whole day, and then were some functional releases as well. The latest release bring some really cool features to XP-Dev.com.

Another milestone has been reached, and the functionality gap has been narrowing drastically the past 3 months. However, I will be brave enough to admit that the gap is still there, and at least for me, there’s still a mountain to climb ahead.

Enjoy the new releases, and as usual, your feedback is appreciated. Do give a shout in the forums, or just raise a support ticket. You can contact me via this blog as well.

Managing People in 15 minutes, or is it Micro-Management ?

February 25th, 2009

I enjoy reading HarvardBusiness.org. There are some really insightful articles there, and I think about some of the better ones days after reading them.

When I first read How to Manage People in 15 Minutes a Day by Daisy Wademan Dowling, I thought that it was a fairly good article. It was short and to the point. 10 minutes went by and that’s when its struck me: it’s rubbish.

Now, the article gives out 4 pointers on how to manage people in 15 minutes a day. My feeling is that its geared towards the busy manager/executive who will need to squeeze out every second of the working day to ensure that the team is working at 100%.

These are the 4 tips that were listed:

  1. Turn dead time into development time. Walking back to your office after a meeting? Use those two minutes to give your direct report feedback on the presentation, and on how he could do better next time. He didn’t have a speaking role? Ask him how he thought the meeting went and how he might have made certain points differently — and then offer feedback on that. Direct, in-the-moment feedback is your single best tool for developing people.
  2. Constantly spot dead time. Look for every two-minute stretch in your day during which you could be talking to someone else — most often, that’s travel time — and convert each into a coaching opportunity. Walking down to Starbucks to get a coffee? Driving to the airport? Headed out to your car at the end of the day? Ask one of your people to come along with — and talk to them about their goals and priorities.
  3. Show up in their workspace. Employees expect you to stay in your seat. Don’t. Once per day, get up and walk over to the desk of someone you haven’t spoken to recently. Take two minutes to ask her what she’s working on. Once she’s done answering, respond “What do you need from me to make that project/transaction successful?” Message to employee: I know who you are, I’ve got high expectations — and I’ve got your back.
  4. Make two calls per day. On your way home from work, call (or email) two people you met with that day, and offer “feedforward.” “I like what you’ve done with the Smithers account. Next time, let’s try to keep marketing costs down. Thanks for your hard work.” Always make “thank you” a part of the message. Employees who feel appreciated, and know that you’re trying to develop their skills, stay engaged over the long run.

I won’t go into the details and analyse each and every point. However, here’s my feedback to these 4 tips:

Points 1. and 2. is essentially time management. Its not rocket science and the subject been there since the dawn of modern management. So, lets not kid ourselves that we’re actually gaining new knowledge by coining it in new, fashionable ways. Nothing new here. Telling managers that they need to make sure every second of their time is used effectively is just pointless. Everyone knows about the importance of time management, but most get stuck on how to implement/execute it. For execution, there’s a plethora of seminars, books, papers, conferences around the subject.

When I was managing teams and projects, there were days that felt endless. I usually started work at 7am, and at 8am sharp 5 people decide to whack in 5 different meetings throughout the day at different times. Managing those days were challenging, but its was not rocket science. On days like those, every 5 minutes free time was spent with someone, which is a trait I picked up from my director at that time. I’ve sat in countless of meetings that I had lunch in. You just have to make every moment count.

However, the rubbish part comes on points 3. and 4. If you read them carefully and picture yourself as the manager, it makes sense. But lets remember - management is not about you, it’s about them. Now, put yourself in the place of the your direct report and all of a sudden points 3. and 4. suddenly feel like you’re being micro-managed. This is not the way to lead a team. To be honest, if I had done that to my teams in the past, the consequences would have been dire. Admittedly, managing developers is different from managing a team of say, sales people. However, micro-management is always a bad thing to do. It undermines, demoralises and makes the person feel utterly useless.

Now, it’s not normal to find such low quality content on HarvardBusiness.org, and this one has to be one of the worst I’ve read. Infact, head over to the article right now and just read the comments that were submitted. Not entirely good feedback at all.

Royal Mail Fail

February 24th, 2009

I just managed to get my Tier 1 visa approved a couple of weeks ago.

For those who don’t know what that is, Wikipedia has a short description about it.

It was a painful experience, one full of anxiety and frustration. It’s not down wholly to the application process, Royal Mail added their incompetence to it and made the whole process that much worse.

I applied back in November 2008 and it took a whole 10 weeks before I got the letter and my passport back. During this time, I did not manage to get hold of anyone from Home Office (BIA) to get an update on the progress of the application.

Job Security

Now, some of you may know this, but I work at an investment bank. Right now is the worst possible time to have a bank as an employer and your visa sponsored by the bank. If the bank goes belly up, you’re out of a job. You have a month (I think) to get a new one, or you’re out of the country. Good luck getting a new job in the banking sector in this climate (I heard rumours of 200:1 ratios for job openings, scary stuff).

Having the Tier 1 visa puts less pressure for me to get a job if the bank was ever to go belly up.

“Sorry You Were Out” Card

Anyways, so, it was 10 weeks pulling out my hair, wondering WTF happened to my application.

Until…

Until the fateful day that was Thursday, 5th February 2009. When I got home from work, I received a card telling me that Royal Mail tried to deliver a letter to me, but I was not at home. Yes, one of these:

The card said that I could collect this letter in 48 hours from a post office nearby (a 5 minute slow drive from where I stay). So, on Saturday (7th Feb) early morning, I went there to collect the letter, and I was really eager to get hold of it (for the reasons mentioned above).

However, the letter was not there. Apparently the post man responsible for the delivery had not returned the letter to that office. I was turned away with the phone number for one of the branch managers. They took my phone number and said that they will call me once they have the letter with them.

Tracking the Letter

I had a tracking number and went to Royal Mail’s website to find out where the letter was, and this is the response that they had on the website:

Recorded Signed For™ items are only tracked after the item has been delivered. Depending on whether the item was sent first or second class, this may be a few days after posting. Please try again later.

Information on your item is not yet available online.

Now, forget the fact that my letter was just a “Recorded Signed For”, which may not come with on-the-dot-accurate tracking. But how useful is a tracking system that only “tracks(ed) after the item has been delivered” ?  I’m not entirely sure which planet they come from, but here on Earth, tracking an item means seeing where the f*ck it is en-route between source and destination, and not after the fact that it has been delivered. That’s not a tracking system. It’s not tracking anything at all! It’s a reporting system.

Customer Service, Anyone ? Royal Mail Do Not Need It

I returned back on Tuesday 10th of February, thinking that it might be worth trying my luck. Still no letter, but the 5 minute trip to the post office was worth it. I learned a few things about the Royal Mail:

  1. Apparently ALL letters go to the head office before getting routed to the branches, even for letters that failed the first delivery attempt has been made.
  2. Being rude to a staff member of the Royal Mail is bad, frowned upon and there are signs everywhere to tell you not to do it. But, a Royal Mail staff being rude to a paying customer who is speaking softly, slowly and politely is perfectly fine.

During the conversation (where I was treated like I had the plague), all I wanted was clarification on a couple of things:

  1. The branch phone number, including the manager’s phone number is  either engaged or rings endlessly.
  2. In the past when I gave them my phone number, no one bothered to contact me when the letter/parcel had actually arrived.

Now, I was not looking for a dossier on these two facts. All I wanted was a “We’re sorry, but we’ll try our best next time. Thank you”. Instead I got a “so, whatdoyouwantmetodo ?” which was very appealing to hear at 7.45 in the morning. I was turned away again.

The Lie That Reveals Everything

For the rest of the day and following day (10th Feb) I checked the status of the letter on their tracking site every few hours and was told the same thing - “Items are only tracked after they have been delivered”.

However, on 11th Feb morning, the message changed on their tracking website:

We have tried to deliver your item from our ROTHERHITHE Delivery Office before 09:43 on 11/02/09 and we have left a while you were out card.

You can arrange a redelivery online,  call the number on your card to arrange a re-delivery, or collect  the item from your local enquiry office by bringing your card and proof of identification and address.

So, now it can track items before they are delivered. They’ve lied! And guess what ? When I got back home that day there was no “while you were out card”. A second lie!

At this point I had a hunch - that status on their website might indicate that the letter has been delivered to their local post office, and it was actually there physically.

<Geek talk warning>

See, plenty of these tracking systems are essentially the same in the core. There is a finite state machine which reflects the status of an item in the real world, and you need some intervention to move between the states. So, you could have the states “Dispatched”, “On the way”, “Delivered”, etc and on each state have a location attached. You could have a fully automated method to move between the states, or just a manual one.  Most of the time you’d use a bar code scanner to reduce the manual data entry task.

Moreover, most of these systems have a fallback state which gets reached in dire circumstances - human error, system crash, etc, to be able to recover.

My theory is this (there’s no way to prove it): The message I was getting initially which said “items can’t be tracked” on their tracking website is a generic way of saying “we have no f*cking idea what is going on”. The second message which said “we tried to deliver it” was the human intervention that recovered the state of the letter in the system. It probably was someone checking/scanning in the letter at the delivery office and tinkering with the state to say “We tried to deliver” rather than the actual “We have it at our delivery office”.

</Geek talk warning>

And guess what ? I went back to the delivery office the following day, and the letter was there!

It does not end there, and here’s the punchline: while driving back home from the post office, I got a call from them saying that there was a parcel for me. OK, so, they do call and I was wrong. But they called the wrong person. They attached my phone number to the wrong letter.

Lessons Learned

Here comes my analysis of the Royal Mail disaster described above:

  1. It took them 1 whole week to take a letter back from destination to local delivery office which is a slow 5 minute drive.
  2. They (including the systems) were utterly clueless on what’s actually going on.
  3. Being rude to paying customers is perfectly fine.

It all boils down to one word: incompetence. It’s incompetence in every single stage. Incompetence in management, the delivery post man, the lady behind the desk, their phone systems, the works.

Now, I have read Allan Leighton’s (current Royal Mail CEO) book “On Leadership” and in there he goes on about putting the customer first, leading from the front and working as a team. All abysmally executed here. He even has a website dedicated to leadership. I do respect and admire what he has done for Asda in the past and it was a difficult task of bringing one of the sluggish retail brands to one of the top 3 largest ones in UK. He executed that wonderfully. But he has failed when it came to the Royal Mail. My only hunch is that in Asda, it was easy to convert the team culture to one that was more productive. However, with the Royal Mail, their culture is so ingrained that no human being could possibly save it.

The Times reports that Royal Mail is due to slash 16000 jobs to cut costs. They only have themselves to blame. I think its good that they want to cut costs, but I don’t think its enough. For the Royal Mail to be able to delivery more value with less workforce is as good as asking the sun to rise in the west, i.e. “no f*cking way”. It needs more than a job cut. It needs to be revamped and it’s culture re-energised with some grain of simple business principles.

It needs to get rid of incompetence at all levels.

Update: Apparently there are plans to part-privatise the Royal Mail. I, for one, am happy to see some improvement. Time to kick some incompetence out!

Update 2: BBC have an article on the row over privatisation of Royal Mail as well.

Update 3: Andrew Ellson from Times Online writes about his frustrations as well.

Wikipedia as an Innovation Source - The Comparison Pages

February 16th, 2009

There’s no denying what Wikipedia has done for the modern world, and our gratitude for it should not stop at Jimmy Wales, but it should be extended to each and every contributor and reader. Without Jimmy Wales, we wouldn’t have Wikipedia. Without the contributors, Wikipedia would not have grown. Without all the readers, contributors wouldn’t have given the 110% into Wikipedia.

All-in-all it’s a fantastic ecosystem which harnesses a lot of the great minds of the world in one place.

Lets look at it from a slightly different angle - an entreprenuers. Entreprenuers are innovation/process junkies. Their view of the world is not the same as yours and mine. They see the world as a web of intricate systems and they tend to look for improvements and ideas to make things better. Inspiration is found everywhere, whether its to improve the current systems (innovation) or build something brand new (invention).

Here’s where Wikipedia comes in. As it has already been establised, Wikipedia is a big source of information, and I think it can be used as a good (not fantastic) source for market research. Say you’re thinking of entering a certain market, chances are high that Wikipedia might have a comparison page of the various products on the marketplace. You could use these comparison pages, annotate it and it could be the base of your innovation strategy - to bridge the gap between various products in the market place.

Now go look at this long list of comparison pages and you’ll know what I’m talking about. See those comparison pages ? Pick something that you have an idea on, that you’re inspired about, that you want to improve on and innovate around one of those comparison pages. Look at offering something that the current marketplace does not offer. In those comparison pages, there are plenty of gaps in the marketplace. You don’t really have to make sure your product fills in all the gaps, but you could try filling in most of them.

Got a great idea for a Wiki system that you can easily monetize ? Have a look at this and go innovate!

Got a great idea for a file hosting system ? Have a look at this and go innovate!

Got a great idea for an instant messaging system ? Have a look at this and go innovate!

I can carry on with this for a long, long time.

So, what are you waiting for ? Grab a coffee/tea/beer/whatever and start innovating! There are a lot of ideas out there in those comparison pages, and I suspect that there are some really awesome ideas and products just waiting to be discovered.

5 Tips for Building a Web SaaS

February 15th, 2009

I have encountered tons of problems, some small, some large while building XP-Dev.com as a web software as a service (SaaS). To be honest, I was a little too naive and didn’t foresee some of these issues, and I really do hope it will help someone out there who’s thinking of building a SaaS for the masses.

1. Case Sensitivity

Case sensitivity of your unique keys is really important. For example, when you’re building a user database, you need to consider whether User1 is the same as uSeR1 and vice versa. Do note that email addresses are case in-sensitive and you’ll need to be able to cope with that in your application code. If you’re hosting your application on a Linux box, do remember that in general, Unix filesystems are case sensitive, and if you had a directory for User1 on your server, you could have another directory for uSeR1 as well.

On the database side, MySQL has a small bug nifty feature that will actually help you solve this headache a little. If you declare a column as a VARCHAR, searches on it are case insensitive, i.e. if you search for uSeR1, you will get back User1.

If you’re finding some weirdness around Hibernate, MySQL and case sensitivity, do have a look at by past blog about it.

2. Internationalization and Unicode

Just build everything on UTF-8, from the beginning, on each-and-every-file, on each-and-every-request. It will save you a whole load of headache later on when you’re considering releasing your SaaS to the non-english speaking world (and that’s a HUGE motha-** of a world that you don’t want to miss out on).

Use UTF-8 database tables. Depending on your installation, you’ll find that MySQL uses latin1, and that doesn’t bode too well with them accented and asian characters. The trick is to use the ‘CHARACTER SET‘ option when creating your database, and setting ‘charset=utf8‘ when creating tables.

Do use the awesome W3C HTML Validator to ensure that web browsers are reading your SaaS using the correct encoding:

3. Login/Register Lifecycle

Ahh yes, authentication! There’s a ton of research put into answering the question ‘How do I authenticate users on a website ?’. But my gripe is not about the authentication itself - it’s about doing the right thing after authentication.

Here’s a common scenario - User1 visits http://example.com/some/private/service/ which is an authenticated service - i.e. User1 needs to login to example.com to be able to access it. The problem is that some SaaS out there immediately redirect User1 to their ‘dashboard‘ or ‘homepage‘ on example.com - http://example.com/userhomepage.

This will frustrate users as they have to:

  • Remember the initial URL http://example.com/some/private/service/
  • Login
  • Retype http://example.com/some/private/service/ in the browser’s address bar
  • Press Enter.

The same applied if the user has not even registered for your SaaS.

The solution here seems pretty obvious - keep track of the last URL that a user hit before reaching your authentication pages, and upon successful registration or authentication, just redirect the user back to the original URL.

Most web frameworks will have support for this functionality in one form or another. Do look it up and get it in before the site goes live.

4. URLs and Permalinks

Keep everything in nice encapsulated URLs. This is a subjective area (that has been debated to an extent that it’s no longer funny), but I think having URLs that do not contain query paramaters are:

  • Easier to remember
  • Search engine/SEO friendly
  • Cleaner to regenerate in code

For example, instead of having:

http://example.com/some/private?service=login

You could instead have:

http://example.com/some/private/login

If you’re using a modern web server like Apache, Nginx or Lighttpd, they all provide some mechanism of rewriting URLs so you don’t have to modify your code too much.

5. Application Level Permissions Layers

Most SaaS are essentially database driven applications, and they all access the database under a single user. In some complicated setups, this can actually go to 2 users - one for reading and one for writing. An even more complicated setup, each user of the SaaS will have a database login.

All of these are essentially not enough.

And here’s why - in a world where a normalised database structure is all the hype, there’s a high degree of certainty that data for User1 sits on the same table as data for User2. As far as I know most databases don’t really have row level permissioning and hence, having to rely on your database as your permission layer just does not work.

There is one setup where I thought that it might work - give each user a new table or database. But clearly this is a solution that simply won’t scale.

So, what’s the alternative ? Embed it into your application code. The decorator or facade patterns are extremely powerful for implementing this. Moreover, you can do complex permissioning, for e.g. User1 can read the business object during weekends, but not when User2 is logged in at the same time. OK, fine - ts a bad example, but you get the point.

Why bother going through all this trouble ? Well, here’s a generic use case:

MyCalendar app is a web SaaS online calendar offering. Each user can have multiple calendars, and they are all private to the user. To retrieve a calendar, all a user has to do is visit http://example.com/calendar/<calendar id>/ where calendar id is an identifier on a database table.

Say User1 has calendars with calendar ids 240, 252 and 362. If MyCalendar app didn’t have application level permissioning, User2 would happily be able to view all 3 of User1’s calendar.

So, the natural question to ask is “Do users actually try to do that ?”. YES! They will. I’m not sure whether they are curious, or looking for a security hole, but you will find some users exploring the URLs. What I mean by that is, say User2 has a calendar id of 5442. He/She will try to visit the URLs for calendar id 5440-5449, even though there are no direct links to those calendars that they can see (except 5442).

Using a database driven web framework like Rails and Django is all well and good, but remember to implement some application level permissioning if you have any private data.

There You Have It

5 simple tips that will save you a ton of hassle if you’re building an SaaS. As always, feedback is appreciated.

London Transport Snow Fail

February 2nd, 2009

It snowed last night in London. Not a regular snow-and-there-will-be-slush-in-the-morning. It was proepr snow - apparently the most in the past 20 years.

I woke up to the following status on London’s Tube network:

London Tube Lines Status

London Tube Lines Status

Not a good start.

Moreover, on their live news website, the tube map that shows the failed tube lines looks like a regular london tube map:

London Tube Map Fail

London Tube Map Snow Fail

All of this mess due to the snow from last night. I guess I’ll be working from home today.

Edit: I managed to get into work (as my new motto from now on is to take the stairs) ! My usual 40 minute commute took 2 hours and it was freezing cold. To top it off I was impropriately attired for the occasion - forgot my gloves and wore leather shoes that had a thin groove-less rubber soul. As soon as I came into work I had to check that I had all 10 fingers and toes. Phew, all of them intact.

Hubdub, the Market Opinion and an API

February 2nd, 2009

I love the net. It’s full of information and it’s accessible. It’s even more powerful when the information is accessible electronically, through a simple mechanism.

Take Wikipedia as an example. Before Jimmy Wales began Wikipedia, the web was full of information. There were search engines that made all that information accessible and it was good enough as the search engines (especially Google and Yahoo) did dig pretty deep and indexed all that information for the general public. However, Wikipedia took it to a whole different level by two ways:

  1. Harnessing the power of millions of contributors, Wikipedia essentially cleaned up, re-arranged and re-presented all that information into a nice set of wiki pages. These pages were kept up to date via peer review.
  2. They made all that information downloadable, which is just fantastic, as now we have the potential to build on all that information that has been cleaned and re-arranged.

And along comes Hubdub. I first read about them a couple of months ago and just skimmed through it. I remember thinking “it’s just another web application, with some social networking information and a big poll database”. I was dead wrong! It’s not just another social network web application. Right now, I look at it as being the “opinions market”.

Somehow through my blog feeds, I stumbled upon a blog entry by a category editor at Hubdub who has been with them for over a year. She does mention the reasons that made her stay for a year, and that’s when I thought - “maybe I should take a second look”.

If you have a look at Hubdub, it is full of polls, and visitors can bet on a poll going one way or another. To me, it felt a lot like the beginning of the internet - where there was information everywhere but it was segregated. For example, there’s a lot of news information coming out from Google News, BBC, Reuters and all. Then you have Hubdub that captures the market opinion on these events. On top of that you have social news sites that vote on articles based on these events and rate comments. Tie all of these together, clean it, re-arrange it and you’ll end up with a pretty decently news aggregator that might be able to predict the future outcome of events. This idea is far from mature, and there are already some stumbling blocks. for e.g. (not a complete, exhaustive list) :

  • Visitors to these sites might only reflect a small percentage of the general population and will be skewed
  • Groupthink
  • Skewed ratings and poll results

All of this can be solved, but before this idea can move into a concept, Hubdub needs to provide an API. It needs to be able to make all that information sitting on their database accessible. They don’t have to provide it for free as well (I will be happy to pay for it).

Why an API ? Well, crawling and scraping websites is a pain. If Hubdub change their layout, most of the time, the scraping rules fail and you’ll end up with the results from your “prediction engine” all wrong. So, they need an API. They need to provide a nice, neat way of accessing all that information on their polls. Without the API, all that potential will be lost. Just like what Wikipedia did for general knowledge via their database download, Hubdub have the potential of doing the same thing for opinions and polls. We as entrepreneurs/developers/ideas-people will be able to stand on the shoulders of giants and build amazing things by leveraging on the work that Hubdub have done in gathering a community around polls.

If they play their cards right - increase number of visitors (compete.com puts them around 60k users) and provide a decent API - I can see them flourishing. I do have a few ideas on small niches where the information they provide might be useful when aggregated along with other information sources.

They do mention on their FAQs that there is an API coming up and I can’t wait. Hubdub - bring the API on!

Calculating CPU Utilisation in Linux

January 31st, 2009

Metrics are really useful. It lets you monitor performance, and based on those metrics that you’ve gathered over time, you can make informed decisions on improving performance. One of these metrics is CPU utilisation.

Procfs in Linux is full of information, and CPU utilisation can be be calculated from the outputs of /proc/stat. Have a look at man proc for more details.

Here’s a small python app that reads /proc/stat and prints out the CPU utilisation time.

#!/usr/bin/python
import time

FNAME='/proc/stat'

def readBody():
    fp = open(FNAME, 'r')
    lines = []
    try:
        lines.extend([l.strip() for l in fp])
    finally:
        fp.close()
    return lines

def splitBody():
    lines = []
    lines.extend(l.split() for l in readBody())
    return lines

class CPUTime:
    user = 0
    nice = 0
    system = 0
    idle = 0
    total = 0

    def parse(self, line):
        self.user = long(line[1])
        self.nice = long(line[2])
        self.system = long(line[3])
        self.idle = long(line[4])
        self.total = float(self.user + self.nice + self.system + self.idle)

    def __repr__(self):
        return 'user=%s, nice=%s, sys=%s, idle=%s, total=%s' % (self.user, self.nice, self.system, self.idle, self.total)

    def usageUser(self):
        return self._doPercentage(self.user)

    def usageNice(self):
        return self._doPercentage(self.nice)

    def usageSystem(self):
        return self._doPercentage(self.system)

    def usageIdle(self):
        return self._doPercentage(self.idle)

    def delta(self, other):
        self.user -= other.user
        self.nice -= other.nice
        self.system -= other.system
        self.idle -= other.idle
        self.total -= other.total

    def copy(self):
        t = CPUTime()
        t.user = self.user
        t.nice = self.nice
        t.system = self.system
        t.idle = self.idle
        t.total = self.total
        return t

    def _doPercentage(self, a):
        return a / self.total * 100.0;

def main():
    print 'Collecting first sample'

    first = CPUTime()
    first.parse(splitBody()[0])

    while True:
        time.sleep(1)
        second = CPUTime()
        second.parse(splitBody()[0])
        secondCopy = second.copy()
        second.delta(first)
        print 'user=%s, nice=%s, sys=%s, idle=%s' % (second.usageUser(), second.usageNice(), second.usageSystem(), second.usageIdle())
        first = secondCopy

if __name__ == '__main__':
    main()

The source code can be downloaded from http://svn.xp-dev.com/svn/rs_scripts/trunk/get_cpu.py
as well.

Here’s an example run output:

rs@laptop:~/projects/scripts/pub$ ./get_cpu.py
Collecting first sample
user=2.5, nice=0.0, sys=0.5, idle=97.0
user=0.995024875622, nice=0.0, sys=1.49253731343, idle=97.5124378109
user=1.96078431373, nice=0.0, sys=0.490196078431, idle=97.5490196078
user=0.980392156863, nice=0.0, sys=0.980392156863, idle=98.0392156863
user=1.9512195122, nice=0.0, sys=0.975609756098, idle=97.0731707317
user=1.9801980198, nice=0.0, sys=0.990099009901, idle=97.0297029703
user=2.89855072464, nice=0.0, sys=1.44927536232, idle=95.652173913
user=2.42718446602, nice=0.0, sys=1.45631067961, idle=96.1165048544
user=6.34146341463, nice=0.0, sys=1.9512195122, idle=91.7073170732
user=1.9512195122, nice=0.0, sys=2.43902439024, idle=95.6097560976
user=3.98009950249, nice=0.497512437811, sys=1.49253731343, idle=94.0298507463
user=1.94174757282, nice=0.0, sys=0.970873786408, idle=97.0873786408
user=2.94117647059, nice=0.0, sys=0.490196078431, idle=96.568627451

Feel free to take it and do something useful from it. It’s in the public domain.

Taking the Stairs

January 30th, 2009

I have been awfully quiet since the beginning of the new year and I have to appologise. It has been extremely busy at work, and along with the ambitious plans that I have for XP-Dev.com, I never seem to have any spare time left.

Now, one of the things that I have missed out was blogging about my resolution for this year. 2008 has been a real roller coaster for me - both, professionally and personally, and I do want to share one of my observations which happened at the end of December 2008.

Lazy ?

I work (at an investment bank doing IT “stuff”) on the 6th floor of my building, and one day, the lift stopped at the 2nd floor to let someone in. This lady (she looked young, maybe late 20s) steps in and calls for the 3rd floor. Yes, she just went up one floor, and to make matters worse, there’s a fully functional escalator literally 20 metres away from the lefts.

At that moment, I was just thinking “Jeez, one floor? AND there’s an escalator just there. This is just pushing it. She should have just taken the stairs” (escalators in this case).

And that’s when it struck me - 2008 is the year the world paid the price for the finance industry not taking the stairs.

Her action to take the lifts instead of the escalators, cost me and 4 others in the lift a few seconds each, but it was just plain lazy and inconsiderate.

Reflection

I have only ever worked for 3.5 years, all of it in investment banking. In my short professional career, I have been a developer, a mentor, a manager, an architect, and a general noise generator (the actual label was worse, filled with profanity). I have seen systems and businesses fall to their knees, while others have run perfectly, some flourished and even some failures to take off (i.e. projects/businesses that seem to just go on with no delivery/product/end in sight).

Looking back on these 3.5 years, I noticed that the ones that failed had just taken outright shortcuts. The finance industry, in their goal of getting rich fast took plenty of shortcuts. They were not prudent enough to sit back, reanalyse the situation and figure out the right way to move forward (and actually do it even though its hard work).

Everyone is paying the price for it. Jobs are being cut everywhere. Businesses are failing - all due to the finance industry not taking the stairs. Their actions of taking shortcuts to generate revenue has cost everyone else a lot of grief - physical (monetary, etc) and emotional (job loss, security, etc).

Wake Up

Personally, I hate having to do a half-ass job. I hate taking shortcuts. I like to get to the bottom of things and nip the problem in the bud. I have to admit that there have been times when I did take the shortcuts.

So, my goal for 2009 is simple - take the freaking stairs, and you should too. Whenever you’re in a situation that requires a decision, or solving a problem, just keep asking yourself “What is the actual problem? What is the right solution?” and just do it!


Subversion Hosting | Project Management | Bug Tracking | Free Subversion Hosting | Exentrique Solutions