Dilbert.com

Oh yeah!. With the power of DBus and libpurple APIs it is possible to give your boss the illusion of managing you. Just run the following script (under WTFPL). Tested with jabber accounts in a live office environment :P .

#!/usr/bin/env python
# By Sudharshan S, released under WTFPL

import dbus
import gobject
import time

class PointyHairedBoss:

    def __init__(self, boss_id, source, frequency=30):
        self.boss_id = boss_id
        self.source = source
        self.frequency = frequency
        bus = dbus.SessionBus()
        _pidgin_proxy = bus.get_object("im.pidgin.purple.PurpleService", \
                                                       "/im/pidgin/purple/PurpleObject")
        self.purple = dbus.Interface (_pidgin_proxy, "im.pidgin.purple.PurpleService")
        # FIXME:
        account_id = self.purple.PurpleAccountsGetAllActive()[0]
        self.boss_conversation = self.purple.PurpleConversationNew(1, account_id, self.boss_id)
        self.boss_im = self.purple.PurpleConvIm(self.boss_conversation)
        print self.boss_im

    def start_nonsense(self):
        question_list = open(self.source)
        for q in question_list:
            self.purple.PurpleConvImSend(self.boss_im, q)
            time.sleep(self.frequency)

if __name__ == "__main__":
   # Change the jabber id and the path to your questions, with an optional frequency
   o = PointyHairedBoss("foo@gmail.com", "questions")
   o.start_nonsense()

When it comes to fitness, I am one of those nerdy couch potatoes with a rather rotund tummy. Burning away calories has become an important priority now and boy, do I miss those Lays and the local Iyengar Bakery Bun Butter Jam and Puffs. For the last week, I have been waking up early and jogging for 30-40 minutes (I also got a good pair of running shoes). Should increase the workout time as weeks progress.

Oh, I also got a new job :D ….


Why Python?

11May09

Ever had that feeling of insignificance? The feeling that your very existence is a microscopic peanut in the grand scheme of things. By grand, I mean the Whole Sort of General Mish Mash. I am going through that right now. We are, according to our own theories an extremely smart species, yet for every answer we discover, 10 more questions creep up like one of those annoying LOLCATS shouting ‘OH HAI’. What the hell is the purpose of life? Why do we exist? What is our place in this infinite Cosmos (See the embedded video)? Its incredibly creepy even to think that our entire life is just a mega-complex probability equation, which most likely is too complex for our puny brains to comprehend.

Yeah, so basically what I am coming at is simple. Party now, Life is too short to be spent over unnecessary complications. Or in other words Frigging Use Python!!!!

(Strip from XKCD)


Brainfuck is one of those turing complete languages that has no apparent use in the real world. But hey, being very very simple with a limited grammar, writing an interpreter should be easy. So here it is, under WTFPL. The code works (I hope so) with the examples from the Wikipedia article.

#include <stdio.h>
#include <error.h>

#include <config.h>

static char cellspace[30000];
static char *data_pointer;

int process_command(char command, FILE *file_ptr)
{
	char c;
	long pos;

	switch(command) {
	case '>':
		++data_pointer;
		break;
	case '<':
		--data_pointer;
		break;
	case '+':
		++*data_pointer;
		break;
	case '-':
		--*data_pointer;
		break;
	case '.':
		putchar(*data_pointer);
		break;
	case ',':
		*data_pointer = getchar();
		break;
	case '[':
		pos = ftell (file_ptr);
		while(*data_pointer != NULL) {
			fseek (file_ptr, pos, SEEK_SET);
			c = getc(file_ptr);
			while( c!= ']' && c != EOF) {
				process_command(c, file_ptr);
				c = getc(file_ptr);
			}

		}

	}

}

int interpret_source(const char *source) {

	/*
	 *  Allowed brainfuck commands are,
	 *  > 	increment the data pointer (to point to the next cell to the right).
	 *  < 	decrement the data pointer (to point to the next cell to the left).
	 *  + 	increment (increase by one) the byte at the data pointer.
	 *  - 	decrement (decrease by one) the byte at the data pointer.
	 *  . 	output the value of the byte at the data pointer.
	 *  , 	accept one byte of input, storing its value in the byte at the data pointer.
	 *  [ 	if the byte at the data pointer is zero,
	 *      then instead of moving the instruction pointer forward to the next command,
	 *      jump it forward to the command after the matching ] command.
	 *  ] 	if the byte at the data pointer is nonzero,
	 *      then instead of moving the instruction pointer forward to the next command,
         *      jump it back to the command after the matching [ command.
	 */

	char command;
	FILE *file_ptr = fopen(source, "r");

	if (!file_ptr) {
		fprintf(stderr, "Error: No such file %s\n", source);
		return FALSE;
	}

	while((command = getc(file_ptr)) != EOF)
		process_command(command, file_ptr);
	fclose(file_ptr);
	return TRUE;
}

int main(int argc, char **argv)
{
	/* Init data_pointer to the left most cell */
	data_pointer = &cellspace[0];

	/* Use getopts? */
	if (argc > 1)
		interpret_source(argv[1]);
	return 0;
}

2-3 back came a sad and shocking news (atleast to me) that Openmoko has sacked/let go of 50% of its work force and has ceased all developments for GTA03. Furthermore Openmoko has stopped funding FSO. Both of which were grim developments to hear.

On a brighter note, FSO has started work on the Vala/C implemention of the reference Python implementation named cornucopia, which mainly aims at the general defragmentation of all the middleware code out there for handheld devices. Whats more, the first subsystem to be ported to this new codebase will be odeviced, which happened to be my project for the Google Summer of Code 2008.

For more, check this recent blog entry by Mickey.

Patches all the way :D


Got a new bike

23Mar09

I know I am pretty late but finally I got myself a new Yamaha FZ. A nice revvy pickup and wide tyres is making me go ‘whee’ over long sweeping curves.

Drinks about a litre every 40-45 kilometres

Pics soon :)


About 10 minutes ago, my brain switched from neutral to first gear and started pondering about ways to teach someone how to program (Not that I am particularly good at programming in the first place :D ).

For example, how would you explain the concept of variables, references, names. etc, which seemingly form the corner stone of programming language syntax. Sometimes this can make you struggle a bit when you are switching languages.

Consider the following,

>>> a = 10
>>> b = a
>>> id(a)
37688272
>>> id(b)
37688272

One teency weency thing I learnt the hardway was the fact that when the interpreter evaluates ‘a = 10′, it creates a “box”, slaps the label ‘a’ on it and puts the integer 10 in it. Consequently, something like swapping of two numbers becomes as easy as,

a, b = b, a

This is actually emphasised on most, if not all Python tutorials I have come across. This didn’t sound all that important when I learnt Python for the first time.

Then I found C to be doing things differently (Am I even right?),
Take this for example,

#include <stdio.h>

int main(int argc, char **argv) {
	int x = 5;

	/* This however creates a new "box"
           containing the value 5 and a name y */
	int y = x;

       	printf("Value of x = %d, Address of x is %x\n" \
	       "Value of x = %d, Address of y is %x\n", x, &x, y, &y);
	return 0;
}
--------------------------

Gives the following output, where x and y are named on different boxes and yet have the same values.
Value of x = 5, Address of x is 98e6cecc
Value of x = 5, Address of y is 98e6cec8

Hmm, This is where I hit it. Suddenly realisation dawned. Sun shone again. Birds twittered. The darkness was gone. I suddenly found myself telling “Its called the pointers.. stupid!”

Now, to mirror the the Python “box” analogy (not exactly) well, a  in a language like C, we have to our disposal the good old pointers.

#include <stdio.h>

int main(int argc, char **argv) {
	int x = 5;

        /* Pointer to the "box" that is name 'x'. */
	int *y = NULL;
	y = &x;
       	printf("Value of x = %d, Address of x is %x\n" \
	       "Value of y = %d, Address of y is %x\n", x, &x, *y, y);
	return 0;
}

This would give me,
Value of x = 5, Address of x is c07ec844
Value of y = 5, Address of y is c07ec844

where ‘*’ and ‘&’ are the de-reference (value-of) and reference (value-at) operators.

So folks, Is it right to think along the lines of “a box at c07ec844 is labelled ‘x’ with the integer value 5″ when I see something as mundane as “int x = 5″ . It did help me to understand pointers better, but are there any better analogies when speaking about variables, references etc. than say, picturing a row of shelves with lots of boxes, each of which can have multiple sticky notes with names at a given point of time.


For the last few weeks, my productivity has dipped to an all time low. Progit is to be blamed. Suddenly I find myselves hitting refresh to see what’s ‘hot’ leading to more time reading blogs and articles, and less time actually getting some work done. So, from this point on I am activating a self-imposed ban on progit.

Lets see how long I last urge :D .

EDIT: Bleh…. Gave up, ban lasted 12 minutes


Legolas Greenlead

Legolas Greenleaf

Legolas Greenlead

Legolas Greenleaf

Legolas Greenleaf long under tree
In joy thou hast lived. Beware of the Sea!
If thou hearest the cry of the gull on the shore,
Thy heart shall rest in the forest no more.

My favorite character from Lord of the Rings. Not as good as the original, but I drew these after a very long time.. :)

I also felt like creating a deviant profile for myself.


Went for a little holiday to Kerala (Kochi, Guruvayoor and Calicut). My dad wanted to go to Kerala and catch up with a few of his college buddies and Me, I wanted to visit the lanes and streets of Calicut where I had roamed as a very little boy. After all, I had lived there for 8 years and Kozhikode hasn’t changed a lot to be honest, except for fresh coats of paints. A new building here and there, one or two demolished. But most of my favorite spots still remain, PaiCo, Alakapuri, Lions park, my school :D , the local chips store, the ’samooham’, winding lanes of chalapuram..etc..

The best part is, I met my LKG class teacher out of sheer luck. Woot, its been 14 years and still she remembers me :D (I must have been very very ‘notorius’), After all she had the patience to teach me that ‘C’ follows ‘B’…..

Geetha

And not to forget the ‘Anna kada’ as I used to call it, Still the same…

dsc04529NSS school… :D ,

NSS chalapuram

Tali Shivan Temple.

tali

P

Sunset at the beach with little karthik,

sunset…and, couldn’t help myself :P

Hillarious?..