Thursday, June 12, 2008

Python fun

On Sunday I had great fun writing some cool python code. Finally I think I got what lambda is good for.

I will mention one bit here. I found an elegant solution (at least in python) for one piece of code that I could never write with sufficient elegance.

A typical problem would be to create a string out of an array of words by separating them by commas. To solve this problem you always have to take care of the one corner case - the first element or the last element of the array. The code would be clean if every element could be followed by the comma OR every element could be preceded by the comma (depending upon your choice). So either you have to use a flag to detect the first pass of the loop and not use comma before current element. Or eat the extra comma after you have come out of the loop. In any case, I always resented the loss of elegance in this type of code. Here is how I would write it in C:

int numbers[MAX] = {2,3,5,7};
first = 1;
for (int i=0; i < max; i++){
if(!first){
sprintf(str,",%d",numbers[i]);
} else {
sprintf(str,"%d",numbers[i]);
first = 0
}
strcat(string,str);
}


Result: "2,3,5,7"

I found a one liner to do this in python:

fruits = ['apple','banana','orange']
print reduce
(lambda x,y: '%s,%s'%(x,y), fruits)


Enjoy!

Sunday, June 08, 2008

OSiM'08 Berlin, Germany

If you remember my posts [1,2] from OSiM'08 USA in San Francisco back in March, here is an update for you.

The March conference in SFO was the first one of OSiM's in US. However they have been active in Europe for some time now. On September 17-18 of this year they will have the 3rd annual conference at Berlin, Germany.

One thing to note about it: For next 3 months the conference will be publishing a blog. .... and I will be running it. :)

Wednesday, June 04, 2008

Of games

Found this fantastic game trailer of 'Fallout 3' while glancing through the reviews of Playstation 3 games.


Monday, May 26, 2008

"Wine" tasting

Sometimes I wonder why I get so late in trying certain things, even though I know about them all along. One of such things is "Wine". I have been using Linux as my primary desktop OS for around 3 years now. I used to play PC games on Windows before that. After switching to Linux it became an occasional affair on a dual boot system. And lately (for around year or so) it has completely stopped.

But last night, out of the blue I decided to give Wine a try to play some of the games I have. I have played three games halfway through their storyline - Halo 2, Warcraft III - Reign of Chaos, Need For Speed - Most Wanted. I installed Wine on my Fedora 8 system last night and installed Warcraft III with it. It installed alright and started smoothly as well. However the scrolling around the map was very sluggish and made the regular tasks very difficult to perform. I applied the registry tweaks suggested in WineHQ, but no help. Only today when I read the WineHQ forum posts again, did I find the -opengl option. When I ran War3.exe from command line with -opengl option, the map scrolling became smooth. The map still doesn't scroll smoothly when mouse pointer touches the edges. However I have a hunch that it might have to do with me using Compiz. It's not a big problem, I liked using keyboard. Sound also doesn't work right now. I could successfully complete one campaign. Unfortunately it crashed while saving the game state.

But overall I am glad I can play games again without rebooting into Windows. Another cool thing was I could start playing from the stage where I left it on Windows. I just had to copy the "Program Files\Warcraft III\save\Profile1" folder from Windows partition to the new Wine installation. I love it when software programs don't unnecessarily complicate things under the name of sophistication. I couldn't have restored my old game data if Warcraft creators had decided to encrypt or mangle this data and save in some non-intuitive location deep down the directory structure.

Saturday, May 24, 2008

Today's slashdot and open source

If you read today's slashdot, you couldn't have missed these two news being posted one after the other. It supplements my previous post on open souce.



Two biggies of the industry opening up. Cisco's news isn't that big, these days it doesn't make sense to develop protocol libraries behind high walls anyway. This however shows that the big companies will be seeing the value in open source; or the futility of keeping the source closed.

There is another news on slashdot that is an interesting read: The Rise of Geekdom.

I think the following para from the article describes the geek phenomenon very well.

But the biggest change was not Silicon Valley itself. Rather, the new technology created a range of mental playgrounds where the new geeks could display their cultural capital. The jock can shine on the football field, but the geeks can display their supple sensibilities and well-modulated emotions on their Facebook pages, blogs, text messages and Twitter feeds. Now there are armies of designers, researchers, media mavens and other cultural producers with a talent for whimsical self-mockery, arcane social references and late-night analysis.