< July 2007 >
SuMoTuWeThFrSa
1 2 3 4 5 6 7
8 91011121314
15161718192021
22232425262728
293031    
Mon, 30 Jul 2007:

Browsing through my list of unread blog entries, I ran into one interesting gripe about lisp. The argument essentially went that the lisp parenthesis structure requires you to think from inside out of a structure - something which raises an extra barrier to understanding functional programming. And as I was reading the suggested syntax, something went click in my brain.

System Overload !!: I'm not a great fan of operator overloading. Sure, I love the "syntax is semantics" effect I can achieve with them, but I've run into far too many recursive gotchas in the process. Except for a couple of places, scapy packet assembly would be one place, I generally don't like code that uses it heavily. Still, perversity has its place.

So, I wrote a 4-line class which lets me use the kind of shell pipe syntax - as long as I don't break any python operator precedence rules (Aha!, gotcha land). The class relies on the python __ror__ operator overload. It seems to be one of the few languages that I know of which distinguishes the RHS and LHS versions of bitwise-OR.

class Pype(object):
  def __init__(self, op, func):
    self.op = op
    self.func = func
  
  def __ror__(self, lhs):
    return self.op(self.func, lhs)

That was simple. And it is pretty simple to use as well. Here's a quick sample I came up with (lambdas; I can't live without them now).

double = Pype(map, lambda x : x * 2)
ucase = Pype(map, lambda x: string.upper(x))
join = sum = Pype(reduce, lambda x,y: x+y)

x = [1,2,3,4,5,6] | double | sum
y = "is the answer" | ucase | join 

print x,y

And quite unlike the shell mode of pipes, this one is full of lists. Where in shell land, you'd end up with all operations talking in plain strings of characters (*cough* bytes), here the system talks in lists. For instance, the ucase pype actually gets a list with ['i','s' ...]. Keep that in mind and you're all set to go.

Oh, and run my sample code. Maybe there's a question it answers.

--
Those who do not understand Unix are condemned to reinvent it, poorly.
                -- Henry Spencer

posted at: 13:22 | path: /hacks | permalink | Tags: , ,

Fri, 27 Jul 2007:

For those who've not been keeping track of what I've been upto, I did manage to make it to OSCON. A couple of days too late, but in time to get there, revamp my slides (after I sat through a couple of php sessions) and give a kickass talk. The last minute jet-lagged efforts to tailor the slides to the crowd was very much worth the effort.

But the fun part of the talk was about four minutes into the talk when Amarok decided to splash up an OSD message which said in loud bold letters - I Wanna Have Your Babies. Panic ... brain skips a beat. Well, there was nothing to do but close Amarok and really make people forget they ever saw it. I think I succeeded in that task - nobody's reminded me about that yet, but enough people have said that it was entertaining. And that's a new experience for me :)

In conclusion, I came, I saw ... I talked.

PS: slides and bazookatooth on IRC reminded me that Amarok said "Girlfriend/Avril Lavigne".

--
Confidence is simply that quiet, assured feeling you have before you fall flat on your face.
                -- Dr. L. Binder

posted at: 22:53 | path: /conferences | permalink | Tags: ,

Mon, 23 Jul 2007:

I just spent the last eight hours reading Harry Potter and The Deathly Hallows. Feeling totally underwhelmed about the book in itself - even though it is not as disappointing as the Order of the Phoenix was, it still has too many rough edges. The story is perhaps a bit too predictable and the other characters beyond Harry are marginalized into conversation peices. Not to mention the multiple dead ends in narration which do not serve as credible plot twists. Read on if you like spoilers.

What's the deal with the whole fuzzing the wand thingy ? I can totally understand the one true wand (*cough*) deathstick theory, but the wandlore rule-bending requires some extra suspension of disbelief. The list of characters acting out of character is also irritating - I mean, why would Kreacher do an about-face on the mudblood attitude or Percy drop back into the Weasleys ? Seems too convenient to me. And then there were the people dying pointlessly. Except for Mad-eye (and maybe Dobby), nobody had a death which was even a blip in the plot line. Maybe there's a certain realism in killing off random characters.

There are even bigger plot holes. But it would have been more compelling to not put words into Dumbledore's mouth after his death. Especially the part about Snape being on Dumbledore's side, shows him up as a puppet master extraordinare rather than the benevolent wizard that we saw in the previous books. And what's with Gryffindor's sword ? First it gets stolen by Griphook and suddenly it falls out of the sorting hat again ? And it is not exactly Gryffindor's sword to begin with ? As someone who liked Harry Potter in his initial adventures, this book feels too weak and watered down.

My advice ? This is a book to be borrowed rather than bought.

--
The covers of this book are too far apart.
                -- Ambrose Bierce

posted at: 07:53 | path: /books | permalink | Tags: ,

Sun, 22 Jul 2007:

I thought I'd invented this term. I'd thought it was my small bit of original jargon to contribute. I even had about seven pages of scribbled over notepaper dedicated to the topic - several hours worth of cogitation on the topic from airport lounges, cramped airplane seats and other places of extreme boredom. Pages and pages of attempts to distill out the idea from an amorphous concept, which the two words which by themselves cannot contain.

But everything that's worth saying has already been said. Despite being original, I discovered, to my surprise, that I'm not the first one to use "honorary guy". Well, rather than waste effort explaining how I feel, let me point you to this this cartoon (oh, the irony). But before I rain on my own parade, let me try to unload my mental baggage.

Being the new kid on the block isn't easy. Especially when you are entering an insular psuedo-meritocracy. And by psuedo-meritocracy, I mean that the pecking order is regulated by assumptions of your merit before you get to prove yourself. Somehow anybody testing such waters is likely to find it cold and assume a rather defensive toe-in first approach to exploring the community. And that makes for uncomfortable beginnings everywhere - and beginnings are such delicate times.

People who are thrown into such situations broadcast very strong vibes, which are there for any intelligent human to pick up easily. Perhaps this is my personal bias, but the strongest of those vibes is that of a girl entering a primarily male dominated community, feeling defensive and wary. The message sent is probably a very tentative "Hi, here I am", but due to an outgroup homogeneity bias, the message comes across as a self-entitled demand to adapt to the presence of the newcomer.

Being the nice guy that I am, I usually comply. The effects aren't pretty. Instead of being myself, I revert to some fallback stereotype male persona. This ranges from the shy guy, the shuffler or the patronizing alpha male. The first two finds me as a stoic blinker (oh, yeah ... smile at me) and those girls who are relieved to find me the latter are generally marginalized to footnotes in my eyes. And those who actually hate me for patronizing them actually fills me with sadness & hope at the same time.

And then there's the minority who do not broadcast these messages, the ones who are comfortable being themselves and in turn just "let me be", without ignoring me altogether. These are people I generally treasure as friends - men and women, both. These are people whose opinion I take for face value, for that's not driven by any facade I present to them. And due to a lack of vocabulary, I picked "honorary guy" to refer to women of this group.

But rather than stereotype these people into a new bracket, what the term "honorary guy" really does is to suspend judgement based on stereotypes I've accumulated over the years. Sort of short-circuit out the homogeneity biases and treat them like the individuals they are. I guess I need a better word.

And as for the rest of them, I'm just being as little of myself as I can. Shut up, shuffle or condescend - pick one. After all, you asked for it.

PS: Umm... Dorothea had mentioned it on her blog, last year. Same arguments, different conclusion ... .

--
The surest way to corrupt a youth is to instruct him to hold in higher esteem those who think alike
than those who think differently.
                                                   -- Nietzsche

posted at: 07:46 | path: /observations | permalink | Tags: , ,

Sat, 21 Jul 2007:

In a development which is becoming depressingly familiar, my travel plans are in a mess. As of right now, I have no flight tickets, not hotel booking and not even an ETA on when both these things will be fixed up - and the conference starts on Monday. It's not like this is the first time or even the the second time this has happened.

But what's really different this time from those two is that finally for once Yahoo! is paying for my travel. For the previous two journeys, I had booked my tickets myself (and blowing up a year's savings each time), which ensured that I had a travel agent to call up and bug. And both times I did manage to get where I wanted and everything did work out nicely. But ever since I heard the "We'll check again on monday" on Friday afternoon, I've sort of given up.

But two out of three ain't so bad ...

--
One possible reason that things aren't going according to plan is that there never was a plan in the first place.

posted at: 07:53 | path: /conferences | permalink | Tags: , ,

Sun, 15 Jul 2007:

A few months back I bought myself a cycle - a Firefox ATB. For nearly two months before heading out to Ladakh, I cycled to work. One of those days, I carried yathin's GPS along with me. So yesterday night, I dug up the GPX files, out of sheer boredom (and inspired by one of shivku's tech talks). After merging the tracks and waypoints, I managed to plot the track on a map with the help of some javascript. Here's how it looks.

I have similar tracklogs from Ladakh, but they have upwards of 2000 points in each day, which do not play nicely with the maps rendering - not to mention the lack of maps at that zoom level. I need to probably try the Google maps api to see if they automatically remove nodes which resolve to the same pixel position at a zoom level.

I've put up the working code as well as the gpx parser. To massage my data into the way I want it to be, I also have a python gpx parser. And just for the record, I'm addicted to map/reduce/filter, lambdas and bisect.

--
If you want to put yourself on the map, publish your own map.

posted at: 10:45 | path: /hacks | permalink | Tags: , , ,

Mon, 09 Jul 2007:

Recently, one of the php lists I'm on was asked how to implement a stable sort using php's sort functions. But since all of php's sort functions eventually seem to land up in zend_qsort, the default sort is not stable. The query on list had this simple example which illustrates the problem clearly.

bash$ php -r  '$a= array(1,1,1); asort($a); print_r($a);'

Array
(
    [2] => 1
    [1] => 1
    [0] => 1
)

The basic problem here is to produce a stable sort which still operates in quicksort O(n*lg(n)) time. Essentially, falling back onto a bubble sort is ... well ... giving up :)

Schwartzian transform: The programming idiom, named after Randal L. Schwartz, is a carry-over of the decorate-sort-undecorate lisp memoization into perl. The real problem here however was putting it into a php syntactic form which was clean and as similar to the original as possible. For example, here's how the python version of the code would look like (despite the fact that the current python sort is stable).

a = [1,1,1]
b = zip(a, range(len(a)))    # decorate
b.sort()                     # sort
a = map(lambda x : x[0], b)  # undecorate

array_walk() magic: Coming from a world of constant iterators, I had read the array_walk documentation and sort of read the "Users may not change array itself ..." as boilerplate. But as it turns out, the callback function is allowed to change the current value *in place* and for that purpose it gets a reference to the value. With that in mind, array_walk becomes a faux in-place map/transform function.

$a = array(1,1,1);

function dec(&$v, $k) { $v = array($v, $k);}
function undec(&$v, $k) { $v = $v[0]; }

array_walk($a, dec);   // decorate
asort($a);             // sort
array_walk($a, undec); // undecorate

And there you have it, a lispism made famous by perl, implemented nearly exactly in php.

--
Whoever knows he is deep, strives for clarity;
Whoever would like to appear deep to the crowd, strives for obscurity.
                        -- Nietzsche

posted at: 08:06 | path: /php | permalink | Tags: ,

Been a while since I got back, but somehow it feels like a let-down to be back home. Add to that four interminably long hops, after which I've travelled from the northern most state of India, to nearly the southern most tip (tinymap). That doesn't make for a good mood. But still, as I sit here, most of what happened seems like a distant blurry day dream.

So, in short, I did a bunch of things, took a lot of interesting pictures (more to come) and had a lot of fun.

Still haven't gotten rid of the "your work is worthless" back-of-the-mind "why bother" voice (yes, the one which keeps saying "you'll get paid anyway" and "they don't pay you nearly enough for that") - eventually I'll have to shake off that coders' block & make work fun again.

Except for that extra bit, the rest of me is back, as expected :)

--
Removing the straw that broke the camel's back does not necessarily allow the camel to walk again.

posted at: 02:14 | path: /travels | permalink | Tags: , ,