Archive for October, 2008

In Black And White

Monday, October 6th, 2008

They say that every picture tells a story. I wish I could find out the secrets held by this one.

My sisters and I

Say cheese!

Phoonk

Monday, October 6th, 2008

Horror movies seldom frighten me and I did not watch Phoonk hoping that it would. I was hoping, though, that it wouldn’t move me to fits of laughter (which it unfor­tu­nately did).

There’s no doubt that Ram Gopal Varma’s genre of horror is way better than the tradi­tional Ramsay Brothers’ formula. Even so, low expec­ta­tions is no excuse for making a mediocre film. Phoonk is a mixture of ideas taken from The Omen, The Exorcist and others, with an occasional attempt at cuteness. The under­lying theme is the usual one: a man who doesn’t believe in the super­nat­ural and his gradual trans­for­ma­tion into a believer. Perhaps this movie was aimed at an audience unfamiliar with those classic themes, but a little origi­nality would have been more than welcome.

I am also disap­pointed with the background score of the film. This is one of the most impor­tant elements of any movie, and is especially impor­tant for one that claims to scare its audience. Consider any well-received movie and you will find a fantastic score played at the right time and place, subtle yet effec­tive. In the case of Phoonk and such other films, there’s nothing but a suppos­edly scary piece of music played loudly at random inter­vals, making it quite hard to listen to the dialogue.

Cinema is a compo­si­tion of light and sound that requires careful timing, a plot built up at the right pace and a series of climaxes that enthralls the audience in one way or the other. Phoonk tries to be a ‘scary movie’ from the begin­ning to the end, and not surpris­ingly, it fails at this task.

Flashback

Sunday, October 5th, 2008

Is there meaning attached to a picture taken years ago? Is it alchemy that trans­forms the ordinary into sweet paradise, years after we move on? Is it mere human weakness that we crave the moments that we can no longer have? This must be one of life’s great mysteries.…

View from my hostel room at DAIICT (http://www.daiict.ac.in)

View from my hostel room at DAIICT (http://www.daiict.ac.in)

Scripting Magic

Sunday, October 5th, 2008

It’s amazing how much can be achieved with the help of a few scripts. If you come to think of it, scripts are the original mashups that Web 2.0 has vener­ated in recent times.

Today, I decided that I would have a “Now Listening” box shown on my blog — I’m not sure if it is visible at this moment — which would display the name of the artist of the currently playing track on my computer. So here’s what I came up with -

  1. A Bash script that would use DCOP to query Amarok, deter­mine the currently playing song, and update a tempo­rary file accordingly.
  2. A small PHP script that would read the file and display this infor­ma­tion, but only if it is available.
  3. A set of CSS rules to format the gener­ated XHTML.
  4. A cron job to execute the script every minute.

Voila! It’s done…almost like magic.

A Fun Way To Spend A Saturday

Saturday, October 4th, 2008

Don’t try this at home, kids.

  1. Open a console window on your trusty old Linux box.
  2. Find a WordPress plugin you don’t need.
  3. Start typing rm -fr /path/to/wordpress/plugin-name.
  4. Instead, type rm -fr /path/to/wordpress and press enter.
  5. Oops.
  6. Spend a few hours setting up your blog all over again.
  7. Sleep.

Step #5 is the part I love the most.

Roller Skating Crash Course

Saturday, October 4th, 2008

Disclaimer: I skated for the first time in my life this week, for not more than an hour. Every­thing I say in this post is based on personal experi­ence, so use your own judgment before doing something silly and injuring yourself. The respon­si­bility is all yours.


The ‘quad’ roller skates are simply shoes with four wheels under­neath. You wear the shoes and, instead of walking, you skate (or fall).

They say practice makes perfect, which is certainly true to some extent. However, like any other sport, there is a technique to doing it right that is far more impor­tant. Here’s a break­down of what I discov­ered this week:

Bend your knees

This is true for almost any sport. Bending your knees automat­i­cally forces you into a crouching position, moving your weight ahead of your feet. This ensures that you don’t fall backward, which is painful and dangerous. The instinc­tive reaction to falling forward is to put one foot ahead and stop the fall, which is exactly what you need to do to start skating.

Gather momentum

The simplest and probably the only way to gather momentum is to put one foot ahead and put your weight on that single foot. You have your knees bent, right? The trick here is to apply pressure on the foot not directly straight ahead but towards the side. That is, you push your right foot forward and towards the right, and then your left foot forward and towards the left alter­nately. This provides some control over your motion.

Moving your feet

Moving your feet

Don’t straighten up

…unless you know what you are doing. If you are moving slowly, it is alright to straighten up temporarily, but you need to bend your knees again before stepping again.

Don’t put you weight on both feet

Consider your normal walk: your front foot presses against the ground, while your back foot provides support. It’s the same principle at work here. Naturally, you can’t put pressure on both feet, other­wise your feet will drift wider and wider apart until you do the splits.

A possible misun­der­standing by the novice is to imagine that the wheels would magically carry him ahead. In reality, the best analogy to roller skating is walking, except that the ground is rolling away behind you. Ergo, you need to lift up one foot at a time and place it ahead.

P.S. — How often do you get to use the word “ergo” in your posts?

Idempotence In System Architecture

Friday, October 3rd, 2008

A useful paradigm that should be consid­ered when a stateful software system is to be designed is idempo­tence. Leaving aside its exact defin­i­tion in mathe­matics and computer science, idempo­tence can be roughly described as a system charac­ter­istic whereby, calling an opera­tion multiple times is equiv­a­lent to doing it exactly once.

For instance, setting the value of a variable X is an idempo­tent opera­tion, because setting its value to be Y several times has the same effect as setting it just once. On the other hand, incre­menting its value is not an idempo­tent method because the result depends on the number of times the opera­tion is called.

Imple­men­ta­tion

Before delving into why you might want to have idempo­tence, let’s have a look at how it can be imple­mented. One way of doing it is like this:

Design a state machine

A state machine identi­fies every unique state that the system can exist in, with a clear indica­tion of which states the system can transi­tion to from any given state, and under what conditions.

Design a minimal API

An appli­ca­tion program­ming inter­face is the gateway for external systems to interact with the service. We start by designing a minimal API, identi­fying all the methods that could change the state of the system. It is best not to clutter the API with non-critical methods at this stage.

Expressed differ­ently, an API method repre­sents a single transi­tion in the state diagram. For example, a system could have states such as Ready­ToP­ur­chase and TaxAdded. The addTax() method, if successful, provides the transi­tion from the first state to the second. This method can never be applied a second time, because by then the system has already moved on to the next state.

An impor­tant restric­tion on the API is that if the state has some attrib­utes, they must be maintained metic­u­lously and checked against incoming requests. Suppose the addTax() method takes a parameter called amount. If the method is called again with the same amount, then the expected response is success, since the system is indeed in a state that the function call was supposed to move it to. However, if amount is different, then the response should be a failure, or at least some kind of partial failure — other­wise, the client will assume that the new tax amount had been added. A state should never change its internal attrib­utes once they have been set.

Transi­tions should be atomic

It goes without saying that transi­tions need to be atomic, so that multiple requests do not corrupt the state while the system is transi­tioning. This can be achieved easily by acquiring a lock on a mutex at the start of a transi­tion, and releasing it on completion.

Why Idempo­tence?

Naturally, it is a good idea to ask why we are putting in so much effort. While this may seem inordi­nately complex at first, you will soon discover that such a design actually simpli­fies the system tremen­dously when there is a great deal of concur­rency. When there are a large number of processes or threads commu­ni­cating with each other and the number of messages exchanged is huge, idempo­tence provides a guarantee of sorts about what the system can or cannot do. The state machine approach allows you to simply worry about the system in its current state, rather than the system as a whole. As a debug­ging technique, the devel­oper simply needs to say, “This was the previous state A, and now it has moved into this new state B — what combi­na­tion of parame­ters caused such a transi­tion?” Idempo­tence makes this approach even more robust, ensuring that the system works in the face of message dupli­ca­tion and errors.

This robust­ness also allows the design to sacri­fice a reliable commu­ni­ca­tion layer in exchange for speed. For example, TCP (which has a larger overhead) can be replaced with UDP, since the appli­ca­tion is resilient to message loss and duplication.

Zeitgeist

Wednesday, October 1st, 2008

Call it curiosity if you will. That little dropdown list that pops up every time I start typing into Google’s search box makes me wonder what people are searching for, and more impor­tantly, why. Here’s a list of terms begin­ning with how to that a lot of people are inter­ested in:

  1. how to tie a tie
  2. how to kiss
  3. how to lose weight
  4. how to draw
  5. how to make money
  6. how to write a resume
  7. how to play guitar
  8. how to make a website
  9. how to get pregnant
  10. how to play poker

Inter­est­ingly, how to make a website has the largest number of results, whereas how to write a resume has the least, amongst these search phrases. I am not sure if these are ordered by popularity, but if they are, then I guess these days the average Internet surfer is more inter­ested in knotting a tie than learning to kiss — especially when you consider last year’s statis­tics.

And while you’re there, does it seem strange to you that who is god is the most popular query of that type? Are we getting more pious these days? Don’t worry, who is satan is not too far behind — it holds the tenth spot.

A Quick GIMP Beveled Logo Guide

Wednesday, October 1st, 2008

This is the no-nonsense guide to creating your very own awesome beveled logo using GIMP, something that looks like the image shown here. There are detailed guides floating around in the series of tubes known as the Internet, but this is for those who are put off by tedious expla­na­tions and figures. Naturally, you need to be know the basics of GIMP if you want to under­stand this guide.

So here goes:

  1. Create a new image slightly larger than the desired image size with a trans­parent background.
  2. Make a rectan­gular selec­tion the size of the actual logo, convert it to a round-edged rectangle and fill the selec­tion with the highlight color (for example, the red on the edge of the logo).
  3. Dupli­cate the layer twice.
  4. Fill the lower­most layer with black, and blur it in order to create a shadow effect. It needs to spill out from behind the main logo slightly. Scale up the layer a few pixels if requried.
  5. Scale down the top most layer by around 10 – 15 pixels, and apply a slightly darker shade gradient to it. (for example, a darker shade of red). The gradient should be subtle and slightly asymmet­rical. Blur this layer just a little, so that it merges with the middle layer which is just below it.
  6. Create a new text or image layer to add your logo to the image foreground.
  7. Save your file.

That’s it — you’re done!