Friday, April 24, 2009

Resurrecting Adrian

Adrian was the name of the game which me and my friends swamy and vamsi, have written in 2003. We were studying 3rd year in IIIT-Hyd, and there was a game design contest announced. We immediately jumped on board and wrote this game - Adrian - in flat 7 days (actually more nights :P). It was awesome for a week's effort, and we won the first prize for it.

We had to borrow my friend's CPU for a week, since the graphics card on which we could actually program was very expensive and beyond our means. Unfortunately, after the contest, the development stalled as we cannot afford the graphics cards. Later I was able to afford one, but then, I was working full-time, so that left little time for game development.

A week ago, I got a mail from a guy who played the game and liked it. That prodded me into going back and look through the code and realized I was as excited about it, as I was when we first got the idea. So I decided to resurrect the game, and immediately moved the code to Google code for version control, and started working on it. The latest code and developments can be seen here.

I am also working on giving this game a newer home somewhere on the net. This might take a while as I plan to first improve the game etc. The old website of the game can be found here.

Wednesday, April 22, 2009

Out of Space on Picasa? Dont fret yet!


If you go on enough vacations, this is bound to happen sooner than later. You will be uploading pics and then realize that suddenly you ran out of the allotted 1GB on Picasaweb. And you dont want to shell out $20 for additional space! So, although you can go and delete old albums or some pics, it is very time consuming. For example I have over 20 albums and am not prepared to delete any in total. I tried going through them to remove less interesting pics, but lets face it - it is a very tedious task!

So here is a simple way, just use the Picasa software and use the "Import from Web Album" feature to download an album to your local machine. Then edit the settings and reduce the resolution to 1024x768, and then upload them back. You would have retrieved over 50% of the space from previous resolution!

Thats it... oh and while we are on the topic, check out my Gallery at http://picasaweb.google.co.in/chbhanukalyan :P

Sunday, March 29, 2009

Debugging Memory Allocations

Debugging memory allocations etc is always a pain, especially if you have memory leaks which dont cause errors directly. There are a wide variety of tools which facilitate detection, the most useful being Valgrind. The tool is awesome, and it definitely helps in this task. Also GNU libc has a wide ranging support for just this task.

But unfortunately you are not always lucky, and might find yourself working on systems other than Linux. Like FreeBSD. (Well you might have guessed that I am no fan of FreeBSD). Although Valgrind has a port to FreeBSD, it coredumps on startup. So in such dire circumstances you are left with no choice but to start from scratch.

Well everyone knows the standard mymalloc method, which is just a wrapper for the standard malloc call. However here is a more efficient method of doing it. Use the linker option "--wrap,malloc" which will make any references to malloc point to __wrap_malloc() (which you will be writing) and to call the actual malloc from inside your wrapper just call __actual_malloc().

The other option is to use the LD_PRELOAD, which loads your custom library, so any malloc calls are resolved to your wrapper calls. To call the actual malloc(), use the statement - "dlsym(RTLD_NEXT, "malloc");", which will give a function pointer to the actual malloc().

I know the blog is not too comprehensive on how to use these 2 facilities, but now that you know what can be done, just google them :)

OPEC - Why it no longer calls the shots

"Are you nuts?" might be the first response of anyone who sees the title. Afterall everyone knows that the single factor which definitely affects the spot price of an Oil barrel on the floor of the NYMEX, the most, is an OPEC meeting. So let me elaborate. OPEC is powerful, but not as much as it once used to be. If anyone remembers the 1973 Oil shock - which brought America and most of the world to its knees in a decade long bout of stagflation, you will now know how much less power it wields today.

So what can be the reasons for such a powerful body's influence to wane? To understand the reasons, you need to understand the composition of OPEC. OPEC stands for Organization of Petroleum Exporting Countries. It is a cartel of 12 countries, the main member being Saudi Arabia accounting for over 25% of world reserves. Other countries like Venezuela have much smaller reserves. So now lets take a look at some of the reasons for the waning of its effects.

Production: Although OPEC used to control a lot of Petroleum production, New reserves discovered in the Gulf of Mexico, and Russia opening up its vast Oil reserves have reduced OPEC's global output to under 40%.

Price Issues: OPEC members have divided interests over Oil prices. While the naive reader might think that a higher price is in the best interests of all suppliers, things are more complicated. Saudi Arabia has much more Oil in the ground compared to other members of OPEC. So while a higher price helps in the short term, it will also accelerate development of alternative technologies, which will eventually reduce the world dependence on Oil. So OPEC members with less Oil in the ground, could not care less about the future, and want to make more money with less oil, and hence want higher prices. Saudi Arabia, on the other hand, wants the world to continue its addiction with oil, and hence would not want to invariably prop up alternative fuel technologies. This attitude is summed up by a quote by a Saudi Oil Minister as "The stone age didn't end because we ran out of stones". Even towards the end of 2008, Saudi broke ranks, and declared it will pump over its OPEC imposed production quota, to reduce the Oil prices which were in the stratosphere.

Infighting: Also after a great show of unity in the 1970s, the major OPEC nations turned against one another. Firstly the 8 year Iran-Iraq war distanced the Shia Iran from the rest. Later, Iraq which was trying to service its war debts more easily by rising Oil prices was rebuffed by Saudi and Kuwait which pumped out more Oil and depressed global Oil prices, finally provoking Iraq to invade Kuwait and eventually Saudi, if it were not for America's intervention.

The Iraq Factor: Although Iraq is a member of OPEC, it is not taking part in production quotas since 1998. And with the highly increased American influence, it is much more likely to do US's bidding at least in the near future, which most probably will not coincide with the official OPEC stand. Also after a long time, Iraq is comparatively stabler and will start pumping more and more Oil, increasing supply and indirectly reducing OPEC's influence.

America: And finally lets not forget US's Gunboat diplomacy by having a couple of warships and aircraft carriers patrolling the Gulf. Although Saudi is an ally, the war ships let it know its position, and the emergence of a Shia Iran, right next to its borders as well as a discontented population, rising Islamic terrorism against the ruling sheiks would make Saudi more reluctant to anger it ally America. And America is much more interested in the Gulf after the 1973 Oil Shocks.

These are some of the reasons why OPEC is less powerful, but lets not get carried away, It is still the single most powerful factor in determining global Oil prices. So let us hope that the dependence on Oil will decrease soon enough.

Tuesday, March 24, 2009

Oil prices scrapping the bottom - Lost Lessons


Now-a-days, Oil price is the last thing on people's mind, with an Election just over in the US, the economy in the dump, and theories about a very prolonged recession - which has even been compared to the Great Depression of the 1930s. Sure enough, it seems like almost no one remembers that oil prices were topping $147 just a few months ago... The commodity bubble has burst at last, and has dragged the price of Oil back into $50 range now.

So what now? Will the prices continue at $50? Obviously not. Once the downturn is over, the OPEC countries will actively seek their pound of flesh. So here is a golden chance for Obama to right many wrongs that were done earlier. Instead of seeking short term quick fixes for bumping up Oil production by offshore drilling or invading other countries, a comprehensive plan to rid America of its Oil addiction needs to be worked on.

Although the end of the cold war made the world a much safer place, it inevitably resulted in America losing its focus on Science & Technology. Ofcourse the top technology companies are still US-based ones, but they are private. And private companies tend to be short sighted for obvious reasons. And real technologies take time to mature and generate profits. It is the federal govt's responsibility to fund such long-term technologies, which will help tap into renewable resources.

The recession is showing at least some signs of waning, so once again a message from the Oil crisis is being lost. Renewable sources are the way to go, and still more research and funding into better batteries, solar power, etc is needed. Lets hope Obama does not lose sight of the future while trying to save the present.

Thursday, February 12, 2009

Kernel Crash? Get the dying moans...

So you had a kernel crash, when you were not around, and could not see on the console what the issue was. Or it happened on a server, which has a hardware watchdog which reboots the machine if it has crashed. So here is a way to get the messages which the kernel spit out before dying...

First of all you need to have enabled kernel crashdumps... there is no reason not to. So you are all set and the next time a crash happens the core is saved in a file called vmcore. Now fire up GDB and run the following commands

(gdb) set logging file ~/gdb.out
(gdb) set logging on
Copying output to ~/gdb.out.
(gdb) set print elements 41216
(gdb) set height 0
(gdb) p (char*)__log_buf

The file gdb.out will now contain the messages, open it in and replace all instances of '\n' with a real newline (using something like ":%s/\\n/\r/gc" in vim), and you will see something like this

<4>ide-floppy driver 0.99.newide
<6>usbcore: registered new driver hiddev
<6>usbcore: registered new driver usbhid
<6>drivers/usb/input/hid-core.c: v2.6:USB HID core driver
<6>PNP: PS/2 Controller [PNP0303:KBC0,PNP0f13:MSE0] at 0x60,0x64 irq 1,12

Happy Debugging! (I KNOW it wont be HAPPY :P)

Saturday, December 27, 2008

Getting safe water on Long Treks

Water is very essential during trekking, and neglecting that can cause serious dehydration. For short treks, you can carry most of the water you need for the entire journey in bottles. But for extended treks, this becomes more difficult, especially if camping or cooking is involved. Water is heavy, since a litre of it weighs a kilogram, it quickly overwhelms the carrier.

Water from natural sources like streams or by melting snow can be used for drinking and cooking purposes, however a few precautions are mandatory, to prevent unwanted diseases from drinking contaminated water.

The most effective of all these is to boil the water. The water need not actually boil for an extended period, just getting it to boil should suffice. This will render the water safe to drink. But this is also a complicated and time consuming procedure.

The other method is to buy Iodine beforehand at your local medical store. For a recent 3 day trek I bought BetaDine(R) iodine bottle for about Rs 113 at the local medical store. You can buy Tincture of Iodine also, but it has less concentration. It was a normal 100ml bottle, and can potentially clean hundreds of liters of water. Just add 8 drops of it to a liter of clear water, and wait for 30 mins for the iodine to kill most of the microorganisms. Iodine is not poisonous in higher doses, so you can safely increase the dosage without any side-effects. double the dosage, if you see visible contamination or if you want quicker response time. After 30 mins, there will be a slight after-taste to water due to iodine. I personally did not mind the taste, but for those of you who do, you can carry Vitamin C tablets. You must add them AFTER the 30 mins, otherwise iodine will not be effective (since the Vitamin C tablets convert iodine to iodide, removing the taste). I would suggest using iodine in normal water once before the trek to know clearly how you feel about the taste of it, and see if you need Vitamin C or not.

WARNING: Do NOT EXPOSE IODINE TO SUNLIGHT! It renders it ineffective!

Iodine tablets are also available I suppose, although I havent tried them.

I also suggest having a backup scheme to purify water, to prevent any unexpected incidents like the bottle accidentally getting exposed to sunlight or breaking.

Check out this link for more details on other water purification methods. Remember, by not carrying a lot of bottles, you are also not polluting the environment with plastic!