< April 2006 > Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Fri, 28 Apr 2006:

## Poster Art

I've been playing around with Inkscape for nearly ten months and recently sat down to draw the posters for the Yahoo! Bangalore Hack Day. Swaroop has put up photographs of the posters I've drawn. I'm a bit proud of them, mainly because I really can't draw to save my life. So here's the result of about 3 nights of tweaking SVG - with teemus providing real time feedback and spo0nman providing a set of ideas scribbled using gimp.

I'll never be a graphic artist - but at least I can fake it ;)

--
Any fool can paint a picture, but it takes a wise person to be able to sell it.

posted at: 14:10 | path: /yblr | permalink | Tags: ,

## 41 is one less

Just found out that 41 is also an interesting number. It is a seed for two prime series. The first one is the odd prime series of the form :- x2 - x + 41 is a prime for all values of x from 1 to 40. The other one is more interesting and of the same length - x2 + x + 41 for all values from 0 to 39.

Give up the pedestal, 42.

--
There are 42 rules in cricket. But is that a coincidence ?

posted at: 13:20 | path: /misc | permalink | Tags: ,

## Scenes from the 4th floor balcony

Time is nearing 1 AM and there's a cool breeze blowing across. It's actually quite pleasant to sit there and we're discussing all of life's problems. Mostly with sabiokap and really about the difference of really crossing 25. According to him, that's when you really get to loosen up and relax in life - but I don't believe it. Then, the stage is set for the ultimate joke.

```<me> Man, you're in denial.
<sabiokap> No, I'm not !
```

I've never laughed like that in my life. Mister Douglas Adams could have hardly set up a more perfect paradox in context. Please feel free to wrap your brain around it and tell me, could he have answered any other way ?

--
If life is merely a joke, the question still remains: for whose amusement?

posted at: 09:12 | path: /fun | permalink | Tags: ,

Thu, 27 Apr 2006:

## It's all downhill to fifty, now

After a quarter century of not having made it big with Rock 'n Roll (maybe not so badly on the sex and drugs department), Spo0nman has crossed over into the next bracket [25-35]. He's written a touching blog entry about growing up. I've often felt that same disconnection with my age where everybody around seems to have grown up while you are left behind to figure this all out by yourself.

In a year

But as they say, growing up is optional, growing old isn't. And Pankaj, definitely is a case in point

--
The older a man gets, the farther he had to walk to school as a boy.

posted at: 20:10 | path: /yblr | permalink | Tags: , ,

Tue, 25 Apr 2006:

## Gcj with libjit

Tom Tromey has put up information about a function GCJ backend interpreter using libjit. He's not put up the code as such, but here's the blog entry explaining what he's done. But a little digging found me this gcj-jit/jit.cc which could be the Real McCoy.

This is all really awesome for libjit because it adds another good use as well as a lot more test cases. More news later.

--
Your motives for doing whatever good deed you may have in mind will be misinterpreted by somebody.

posted at: 13:45 | path: /dotgnu | permalink | Tags: , ,

Somebody asked me to explain how the kartwheels engine hooked into the Mozilla js engine. But I don't have that code, but I still have code left over from my previous hacks from sometime before foss.in, when Tarique trolled about greasmonkey for links. The hack got dumped because the DOM in elinks is free'd immediately after rendering and the render heirarchy is what remains after the first few seconds. But that code is reincarnated here to serve as a first base for the average C programmer trying to embed javascript in his *unthreaded* application .

Basically the embedding API uses two constructs for reentrant code - JSRuntime and JSContext. These hold the equivalent positions as the ILExecEngine and ILExecProcess in dotgnu. Basically, if I wanted to use a single instance to run two scripts without polluting namespaces, I'd use a single runtime and two contexts. After creating these, the task gets easier and easier (you wish !).

declaring a function: All the functions have a bounding object, which for the seemingly unbound ones is the global method. In a browser the global object is the "window". The declaration for the global method is basically cut and paste and very similar to the other class object declarations so I'll just leave it out for now. The functions are declared using JS_DefineFunctions .

```static JSFunctionSpec glob_functions[] = {
{"print",           Print,          0},
}

JSObject * glob = JS_GetGlobalObject(ctx);
assert(JS_DefineFunctions(ctx, glob, glob_functions) == JS_TRUE);
```

popping arguments: The arguments are received by the function (which is in C land) as a set of jsval* pointers and an argument count. Each function is assumed to handle its own argument handling, leaving us with the option of handling variable number of arguments. My Print function does just that - printing out all the arguments it received.

```JS_STATIC_DLL_CALLBACK(JSBool)
Print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
uintN i, n;
JSString *str;
for (i = n = 0; i < argc; i++)
{
str = JS_ValueToString(cx, argv[i]);
if (!str) return JS_FALSE;
fprintf(stdout, "%s%s", i ? " " : "", JS_GetStringBytes(str));
}
fputc('\n', stdout);
return JS_TRUE;
}
```

declaring objects : Now every object needs a class. More accurately, I haven't figured out how to just construct a simple hash from spidermonkey land. But it suits my purposes to use objects and accessors to implement what I need right now. One of the first things I did in elinks was to put a hook on the <img> element which infact has very little effect on the renderer core. The following code is just pulled out and has the JS_GetPrivate/JS_SetPrivate code removed.

```
static JSClass image_class = {
"image", JSCLASS_HAS_PRIVATE | JSCLASS_NEW_RESOLVE,
JS_PropertyStub, JS_PropertyStub,
JS_PropertyStub, img_setProperty,
JS_PropertyStub, JS_ResolveStub,
JS_ConvertStub,  JS_FinalizeStub
};

static JSBool img_setProperty(JSContext *ctx, JSObject * obj, jsval id,
jsval *vp)
{
char * name = JS_GetStringBytes(JS_ValueToString(ctx, id));
char * value = JS_GetStringBytes(JS_ValueToString(ctx, *vp));

fprintf(stderr, "<image %p>.%s => %s\n", obj, name, value);
return JS_TRUE;
}

```

Having declared our class, we proceed to write a few lines of code to construct a simple object from the class and attach our bound methods to the object. Technically, I can attach the methods to a prototype and provide that to the class definition. But this way seemed easier while I was at it than go through a hierarchy of prototype hashes while debugging method call resolution.

```JS_STATIC_DLL_CALLBACK(JSBool)
img_Show(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSBool show;
if(argc == 0) return JS_FALSE;

assert(JS_ValueToBoolean(cx, argv[0], &show) == JS_TRUE);
fprintf(stdout, "<image %p>.show(%s)\n",obj, show ? "TRUE" : "FALSE");
return JS_TRUE;
}

static JSFunctionSpec img_functions[] = {
{"show",          img_Show,          0},
};

int defineImage(JSContext * ctx, const char * id)
{
JSBool ok;
JSObject * img = JS_DefineObject(ctx, JS_GetGlobalObject(ctx),
id, &image_class,
NULL, 0);
ok = JS_DefineFunctions(ctx, img, img_functions);
return (img != NULL);
}
```

compiling & running js: The easiest way to run the javascript is to use the following two step approach - JS_CompileFileHandleForPrincipals and JS_ExecuteScript. The first function accepts a FILE * and gives you a JSScript* and the second one obviously executes the script you just compiled. With that, your js engine embedding is complete. Oh, and don't forget to call defineImage while parsing the DOM tree.

There are a lot more nuances in there, like GC rooting. The engine GC does not scan your address space and cannot preserve objects which are only referred from your code space. To work around this, you could create a GC root by hand and attach your objects there so that you can prevent them from being GC'd till you're done with it. But remember to just cleanup the GC root when you're done with the object - this works sort of like a pool, only the crashes might be a few minutes later instead of immediately after you free the root (FUN !! ).

But none of them really matter to a newbie taking a few baby steps into VM embedding land and I didn't really do it proper when I did kartwheels either. Matters not, here's the sample code for people to play around with. Also take a good long look at spidermonkey api docs and the MDC Javascript Embedder's guide - they basically cover all my code, though in a different level of detail.

```[gopal@phoenix spidermonkey]\$ make
gcc -ggdb -L/usr/lib64/mozilla-1.7.3 .... testjs.c -o testjs

[gopal@phoenix spidermonkey]\$ export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:.
[gopal@phoenix spidermonkey]\$ ./testjs hello.js
Hello !
<image 0x50f8c0>.src => /tmp/x.png
<image 0x50f8c0>.show(TRUE)
<image 0x50f8c0>.show(FALSE
```

That's basically how it all begins and then after you've been debugging for four hours syncing/locking JS threads with the gtk+ event-loop ... Zzzz

--
The more I want to get something done, the less I call it work.
-- Richard Bach

posted at: 12:14 | path: /hacks | permalink | Tags: ,

Mon, 24 Apr 2006:

## Holy Cow !!

I spent the entire weekend sleeping. Well, that's not quite accurate. After sleeping on friday night, I woke up sometime around 3 AM (missed barcamp that way) on saturday night and started to look for something to do. So I started to finish reading Earth, Air, Fire and Custard. Maybe it was a bad idea to read through the final chapters about a deliberately flawed hero (as pointed out by the Fey) especially when I was in a really bad mood. But I speed read my way through this one.

The book is pretty interesting, though I suppose I should read the "The Portable Door " and "In Your Dreams" to actually make sense of the entire Sophie Pettingel situation. I think the word retro-continuity would be the right one, where the current events are related to the ones that happen afterwards which turn around our natural causation ideas of "before and after" on its head. But that is only a natural consequence in a universe that lets you travel across time.

The omniscience of Van Spee sort of drives itself on the old thread of physical determinism which, if you've read through Freedom Evolves, restricts all instants to only one physically possible future. Also revealing the fridge to be Laeritides sort of weakens the plot a bit, especially since he is the Godfather (that could be said with a space in between and an ampersand) to Paul Carpenter. The presence of such a cosmic policeman undercover indirectly implies that God isn't omipotent and throws in a few other philosophical paradoxes for the true believers.

Anyway, basically Paul is a loser. Tom Holt wastes no opportunity to make this clear and does it in a few hundred pages. Also he puts in a few interesting jabs about people's judgement. The part about love at first sight and all that is a clear dig at the basic human tendency to judge a book by its cover. Oh and to understand the title of this, please look at what the fridge says to Paul.

Despite the happy ending, it did nothing to improve my mood and I continued to sleep after I was done.

--
Oops, I always forget the purpose of competition is to divide people into winners and losers.
-- Hobbes in a sarcastic mood

posted at: 20:01 | path: /books | permalink | Tags: ,

## Happy 25th Anniversary

This day, back in 1981, my parents tied the knot. And then set about working hard and raising a family. Through the hardships of their initial years, through all the uncertainities of my health, studies and through all the recent turmoils and health scares - they've held fort and been terrific role models for me.

Happy anniversary.

--
We have not inherited the earth from our parents,
We've borrowed it from our children.

posted at: 17:01 | path: /me | permalink | Tags: ,

Sat, 22 Apr 2006:

## Yblr Hack Day

Today was Yahoo! Bangalore's hack day. After having literally killed myself debugging spidermonkey js magic for an entire night, this was my chance to actually let the world see my cute little application run real Konfabulator widgets. The hack itself isn't too spectacuar, it merely combines some widely available libraries, spidermonkey, zziplib, libgdk, curl and libxml2, to run the widgets. Unlike all the efforts of dotgnu, there was no complicated binary formats, nor were there any limitations of performance. Basically - it just worked.

So after pulling in a few widgets and throwing out all the animation and other eyecandy stuff out, I was able to get a decent group of widgets working. The most spectacular of which was the Yahoo! News Reader. Here's a screenshot with corresponding clickys for the widget sources.

But just like all my other efforts, this project was also DOOMED. And just like all the other screwups that punctuate my life I have nobody but to blame but me. I did a hurried demo of the application using a windows machine via VNC. I was probably too negative (as teemus pointed out) or maybe I was all hung over from not sleeping, it was a lukewarm performance at best. I expected the code to speak for itself and I failed to impress anyone with the potential of this hack.

For a few moments, I felt crushed. From that point onwards, there was only one path to closure for the whole project. I had to throw away all that code and keep walking without a glance back. I know I have the strength to do exactly that and do it without flinching. And I did it.

Even if I'd kept this codebase, the world could've never seen it opensourced as it is a competing with a Yahoo! product. But the code isn't lost to the world completely. Two people mailed me asking for the code and I sent them the code as an attachment. But for their mailboxes, the world has no trace of kartwheels now.

I do not know why, but I feel liberated.

--
"Plan to throw one away. You will anyway."
-- Fred Brooks, The Mythical Man Month

posted at: 02:12 | path: /yblr | permalink | Tags: , ,

Wed, 19 Apr 2006:

## And Earth is a Libra

I picked up Good Omens a while back. The reason I bought it was because I saw the twin pairs of the hardbounds and in a moment of book lust decided that I'd buy the paperback. And a few feet away, perched on top of a bookshelf was the cheap paperback edition. From desire to demand and satisfaction in five minutes.

The moment I opened the book and read the first three pages, I knew I needed this book. The last time I felt this pulled in by a book was when I read the this is not her story in H2G2. These are those fateful lines - read them and understand.

```... and was able to announced triumphantly that the Earth was created
on Sunday the 21st of October, 4004 B.C, at exactly 9:00 AM, because
God liked to work done early in the morning while he was feeling fresh.

This too was incorrect. By almost a quarter of an hour.
...

Secondly,the Earth's a Libra.

LIBRA. 24 September-23 October.
You may be feeling run down and always in the
same old daily round.
```

The basic idea of antichrist as being neither good or bad, but merely a mass of potential was interesting. Especially interesting are the side jokes, like Death's comments about Elvis or the hell hound transformed into a mongrel. Also there are the philosophical question of an angel and a demon co-operating as is observed between solidiers who have more in common with each other than with their superiors. Side references to the uncertainity of the result of Doomsday also raise questions about religion without directly denying the omnipotence of God. A lot of interesting things compressed into a paperback, and that's why I like it.

Also got my hands on the The Truth, which is quite in the league of Going Postal. Quite enjoyable, except for the portrayal of Sachrissa which could've been a little toned down (bosoms and black dresses, y'know). And quite an interesting insight into the world of Unorganized crime in Ankhmorpork. That book was hard to put down but when you're through you're through. The typos in the news paper motto was funny - the truth shall set you fret and the Worde family motto - mot juste.

Now, I have Thud left to read. I guess I'll wait for the paperback to come out.

--
<OldMonk> in india, we do not think... we know

posted at: 19:40 | path: /books | permalink | Tags: , ,

Tue, 18 Apr 2006:

## Need those images

When I first read about Greasemonkey, I never realized how much power exactly that added to the hands of the common browser. Gone are the days when you had no choice but to put up with whatever's served. So when I noticed that planet.foss.in had stopped showing images with some css, I did what every greasmonkey aware user does - wrote an un-hider for images. I just went a step further (thanks in no amount to Kushal's latest huge images) and forced all images to be < 480px in width.

--
Dinosaurs aren't extinct. They've just learned to hide better.

posted at: 17:44 | path: /hacks | permalink | Tags: , ,

Sun, 16 Apr 2006:

## I tried to go home ...

I tried and I tried - but when I got there, I realized I was a few years too late.

--
The way to love anything is to realize that it might be lost.

posted at: 19:11 | path: /me | permalink | Tags: ,

Mon, 03 Apr 2006:

## Seeds of Rebellion

Rebellion is inevitable. I don't mean the political kind with weapons, leaders and death. I am talking about the much more intrinsic outpouring that most of us associate with teenage angst. The basic instinct that metaphorically makes us feel happier running into the darkness with eyes shut rather than walk into the tunnel of future groping and feeling the walls.

Rebellion is the first side effect of a growing mind - shaking off the training wheels carefully tied on your life cycle by your parents. Consider it the original sin if you want, but the first act of your free will is hardly likely to be an act of good. There are many who have said that the truth shall set you free, but for generations told to tell the truth, lies are what really sets them free from the apron strings.

The first kiss, the first cigarrette, that first mug of beer - they all change more things than their immediate effects. They are things looked upon quite badly by them and therefore become things to do to spite the world with. The basic thread of "I do what I want" drives people to do what they don't want as well.

Then one day, as quickly as it began, rebellion dies. Like a phoenix, it is reborn into what we prefer to call purpose. Same thing, new bottle - but Purpose needs no strutting or posing, it acts. Cause and effect comes into play - the word consequences creep into your mind and the clock of the human life clicks into the doldrums of young adulthood, where nothing much happens but everything important seems to be revolve around that fact.

I've walked around a couple of colleges in the last year. I miss the rebellion that used to thrum underneath the seemingly calm veneer of college day-to-day. Maybe I'm tuned to a different wavelength of a past. Maybe they changed what the rebellion means and forgot to tell me. But I just don't feel the vibe - I just get a disturbing sense of obedience from these future adults. The world's going to be really strange for me if people just obey without threat of consequences or reward for keeping in the lines. No stick or the carrot, merely orders and obedience.

The seeds of rebellion are planted deep. They are watered by the tears of everything denied to you and rooted in all your potential. Pass through the gates and join the club.

--
Humanity has advanced, when it has advanced, not because it has been sober,
responsible, and cautious, but because it has been playful, rebellious, and
immature.
-- Tom Robbins

posted at: 15:12 | path: /philosophy | permalink | Tags: ,

## Applications Unknown

FOSS spawns a huge number of applications, anyone who has seen freshmeat can confirm that. Very few of them really reach usability and even fewer are well maintained. So here are some I found lying around in my own harddisk, along with the rpms mirror I pulled out sometime back.

Ever since I saw XGL (more correctly compiz) doing extra magic during the kororaa demo at NITC, I've been wanting to try it out. But this one was a surprise - 3ddesktop. It is basically a 3d desktop switcher that could be hacked around to work like XGL has - but minus the actual X updates across the multiple faces.

```[gopal@phoenix ~]\$ 3ddesk --acquire=1

[gopal@phoenix ~]\$ 3ddesk --mode=cylinder --nozoom --goto=2

```

It is the most awesome thing I've ever seen work out of the box. Even without restarting X11, it just started working. The screenshot is of carousel mode with zoom enabled. You can see my four desktops and the various things on them. OpenGL rules.

The night sky in Bangalore is orange. We have too many glowing streetlights to actually see the sky. While I was in NZ, I remember walking around in the garden at 2 AM looking at the stars I've never seen before. I've marked out the Southern Cross in Celestia and now I can watch them anytime I want. Anyway, a set of spots with no connections hardly makes any sense to the average viewer. Then there's that small blue planet that is hardly even in the middle of nowhere that we are quite interested in.

But before I started bitching about the lack of marked constellations in Celestia, I ran into something that's even more awesome. This one is a virtual planetarium on your desktop - Stellarium. This thing literally blew my mind away. There is no other program I've ever seen that makes me want to plonk down hard cash. If I ever go to a college to talk again about the coolness of software, I am sure as hell going to demo this particular application. Head and shoulders about the rest, that's what this one is. This is a bloody video game, that is what it is. There is even a windows build for it.

All the following images are screenshots captured from Stellarium. If I'd pulled the ones without markings, you could misunderstand them for real photographs. If you don't believe me, look at the bigger versions.

I don't know how many of you have played an old DOS game called Xargon. But I am pretty sure you guys have seen one of the Mario series at least. So, supertux is a side scroller of the very same sort. Except for the lame save file style - which is a plain-text lisp macro file, I love the game. Maybe I might love it better because of the lame save file *wink* *wink*.

Then floated before my very eyes, something that was even more annoying than anything before (and probably after). Something that burns CPU just to render on screen and even more because of all the composition on the backbuffer. I give you xpenguins. They even have themes, like the Simpsons with Bart & Lisa. The most awesome part is when the penguins fall too far - they die with a lot of gruesome blood and fly away as a angels. I literally died laughing when Bart mooned standing over a root terminal.

There are serious tools in there as well, like redir. This is a port deflector which accepts connections and forwards them elsewhere. Looks to be a lot cleaner than using netcat/ssh for the job as I've always done. But yeah, those are almost on every *NIX box - this might not be. Or hping which can finally send SYN pings which aren't blocked by most boxes. Technically you can take down entire blocks of webservers using that simple tool - not Yahoo!'s or any decent company's servers, but not everyone knows what Accept Buffering means. For the really paranoid security dudes, there's the knock which lets you script up your port knocking. How about if I hit 3333 and 6666 twice within 10 seconds, the firewall lowers the connections to ssh-22 for next minute - well, then I'd really need knock around or I'll be writing LOTs of code in the link layer to detect hits on closed ports. And ssh proxy-command has the ideal thing for it - nc host port1 ; nc host port2 ; nc host 22 .

Also when you walk around a wifi network, you can't do without kismet or in a pinch, ssidsniff. Last cool toy around is the fakeap which lets you fake the existence of hundreds of 802.11 accesspoints with a few thousand beacon frames. I wonder what would happen to the poor guy who tries this at a conference - killed by a thousand laptop blows ? Or maybe run driftnet on a host with lots of traffic and see how many naughty pictures people browse.

It is already the next day now and I still haven't played around with torcs, dircproxy or qdvdauthor. More importantly, I haven't really tried out all the network tools that are so important to my basic mode of operation. Maybe sometime later.

--
We are all in the gutter, but some of us are looking at the stars.
-- Oscar Wilde

posted at: 11:44 | path: /hacks | permalink | Tags: ,

Some of the world prefers to know their destiny (if there is such a thing) from tea leaves. I, for one, prefer to drive mine using coffee beans and chaos (code and chocolate optional). Needless to say, I sat down at my box planning to write something totally random, pointless and useful only to my curiousity - as befitting the first of mad new year's. On a side note, did they call all of us Indians who celeberated new years last week fools ? Anyway, I wrote something that would read RPM .hdr files as dumped on my disk by yum. The docs were pretty useless and so was all the samples on my box - but I read through the pullheaders.py inside yum and discovered most of the secret calls used.

As it turns out, there is no function around which will accept a filename for a .hdr file. The closest I found was rpm.headerLoad which seemed to accept a string and then complain about a bad header. The code for rpmlib is pretty heavily documented though completely useless for my particular purpose. After I discovered the secret Gzip calls inside the old rpmutils, I began to suspect what headerLoad actually takes in might be a gzip decompressed buffer of data rather than just a filename. From that point onwards it was a peice of cake.

```import rpm,gzip