Uncategorized

Playing God with Scheme

Pretty sensitive issue this - whether man should be allowed to play God or not. I was a debater once, and I’ve pretty much debated this with dozens of arguments from each side. One thing you can’t argue with, though: playing God is fun.

I was playing around with Scheme today (for the uninitiated and/or the young, that is a programming language). I was pretty uninitiated too, which is why I had never bothered to try out Scheme before… but this is the closest to playing God that I have come. Here’s why.

Weird but cool syntax: Almost everything in scheme feels like it must have been created around the beginning of time. Scheme is to C++ what Sanskrit is to Hindi. For instance, here’s how you add two numbers in Scheme:

(+ 2 3)
5

This seems simple enough to follow at first - but then you realize everything in Scheme follows this rule - and so if you want to write an absolute value function, this is how you do it:

(define (abs x) (if (< x 0) (- x) x))

It all goes downhill from there.

Warp the world: The scheme book I was reading unwisely told me that anything and everything in Scheme was changeable. I did not read a sentence further and went ahead and wrote this out:

(define (+ a b) (* a b))
Setting compiled read-only variable+ can yield to incoherent state
+

This basically tells the interpreter that I want addition to mean multiplication. Despite the warning that I was entering a demented world, I was overjoyed that this appeared to work. And, sure enough:

(+ 5 10)
50

Bending the fabric of reality: Upward to enlightenment, I realized that + was just a name, and could really point to anything. We often hear these days that “everything is an object”. But really, in Scheme, “everything is what you want it to be”. And so, after turning my world upside-down, I turned it inside out.

(define + 2)
Setting compiled read-only variable+ can yield to incoherent state
+

Which says I want + to be a variable with value 2. For an ideal God, of course, the world would just carry out orders without cursing, but hey, I was just playing God! And was indeed bending the world to my will. And so I can now enter this, which looks positively alien, but is perfectly logical and returns a nice round figure:

(* + (- + +) (/ (* + +) +))
0

By this time, of course, subjects of the now-warped-and-bent-beyond-recognition world were, as you can imagine, feeling like Neanderthal man presented with the supernova of the Crab Nebula (or bash users presented with the Windows command line), and I thought it was about time to un-warp the world again. Even without restarting the interpreter, this is quite easily done:

(define (+ a b) (- a (- b)))

…and there was light :D (though of course the original + procedure can take any number of arguments, I’ll figure that out someday)

If you’re feeling down, I heartily recommend an episode of playing God to get you feeling on top of the world.

Uncategorized
fun
programming

Comments (5)

Permalink

Its time

.flickr-photo { border: solid 2px #000000; }.flickr-yourcomment { }.flickr-frame { text-align: left; padding: 3px; }.flickr-caption { font-size: 0.8em; margin-top: 0px; }


Its time, originally uploaded by nigham.

Uncategorized

Comments (3)

Permalink

Kororaa Xgl Live CD

Kororaa Screenshot 3

The latest linux buzz is Xgl, a new graphics subsystem which Novell is pushing, with uber-awesome graphical desktop effects. I decided to try out Kororaa, a Gentoo-based live-CD distribution which runs Xgl. Xgl, along with AIGLX will form the Linux response to Quartz extreme and Aero Glass on Mac OS X and Windows Vista respectively.

The eye candy is definitely impressive. Best seen through this video by Novell. Transparency, cube faces as desktops, squiggling motion of moving windows, 3-D rotating effects, its all there. It works, and works very smoothly. If anything, I was really impressed by the performance.

What I was really impressed by, though, was what I call the “natural fall” of the UI. Lets say I’ve dragged the desktop cube to the position in the screenshot above. When I release it, the cube will rotate back to the “nearest” face or desktop. It won’t do that instantly or in at a constant speed though - it accelerates to the nearest desktop, overshoots it slightly and bounces back. Similarly with scale windows (the equivalent of Expose in Mac OS X… all open windows are scaled and tiled to fit on the desktop) - there is a bouncing effect before the scaled windows fall into place.

The other apps on the CD are the usual gnome apps. Its possible to make any window as transparent as you want - but thats hardly the most effective usage of Xgl. Basically, once this is adopted by distros, developers will need to incorporate good UI design keeping the new options in mind.

More screenshots here.

Cross-posted on eminor.

Uncategorized

Comments (0)

Permalink

Bug Oscars 2006

This happens to me about once every year or two. I come across the hardest or the weirdest bug I’ve ever faced in my whole life.

I still remember one of the first - in class 8, I was making a BASIC program to show large banners on the screen. At that time of course, I wasn’t aware that the word “font” existed. My idea at that time was to print a normal line of text on the screen, read off the normal text one pixel at a time, and basically put n square pixels in the place of one pixel. I was lucky enough to have not only a computer, but a printer at my place at that time, so just after enlarging the text I could simply hit PrintScreen (which in those days actually used to print the screen!) and have a nice large banner in front of me. I still remember the first thing I printed - “I Beat Jaffar!” - Jaffar, for those who remember, being the evil Wazir in the very first edition of Prince of Persia.

The bug I was trying really hard to eliminate was that I didn’t want the normal-size (small) line of text to be printed along with the large banner. After leafing through the GW-BASIC manual for a few days, I found the command that would allow me to not set the pixels of the normal text to black after I’d applied the enlargement. Not bad, for a kid of fourteen in the days of no Internet. Kids of age fourteen these days, of course, do far more practical things - like writing scripts to steal money online.

Today’s bug - which won the top spot by making me sit at work until 3 AM on Holi, involved me trying to deploy a PHP webservice (a wrapper for an algorithm implemented in C++) on a much older system running Red Hat Linux 9 and PHP 4.2.2. Yeah, almost 20th century stuff. Don’t ask me why. The code worked as expected on my Fedora Core 4 box with PHP 5.0.4; however I was also using quite a few programs (gnuplot and imagemagick to generate images, and the GNU scientific library) for which only older versions are installed on RH9. Anyway, after some testing and replacing some newer PHP functionality with old compatibility functions, I thought I was more or less done. Not by miles.

I was using PHP’s exec() function to wrap system commands including my own compiled executable. The bug - half the system commands worked as expected, and the other half didn’t. My own executable was running fine, taking its input and generating its output as necessary, but gnuplot and convert were just not working. Long (really long) story short, after wasting hours on the Internet, forums, PHP safe mode definitions, and resetting environment variables, I figured the problem was simply this. PHP5 on FC4 flushes its output buffer sooner than PHP4 on RH9. Of course, the fault was purely mine, since I’m supposed to flush buffers before using their output - but PHP doesn’t exactly lend itself to code safety, and the code had worked flawlessly both on my Mac and Fedora - which of course, was the real problem… only after exploring every other option did I check if my code had gone wrong somewhere.

Moral of the story for me - don’t be sloppy while coding, even if code still works. Moral of the story for developers - never, ever make it easier for dumb guys like me. Thats not progress, just a precursor to lazy (and ultimately destructive) coding habits.

Uncategorized

Comments (4)

Permalink

Happy holi!

.flickr-photo { border: solid 2px #000000; }.flickr-yourcomment { }.flickr-frame { text-align: left; padding: 3px; }.flickr-caption { font-size: 0.8em; margin-top: 0px; }


Colors at the Mysore Market, originally uploaded by deen.

Uncategorized

Comments (3)

Permalink

MediaCentral for Mac OS X

Convert any Mac (well, 800 MHz G4+ Mac) to a media center. Awesome piece of software. I’m seriously thinking about buying the USB Powerbook remote to really use this well on my 20-inch Dell. Of course, you can control stuff with the keyboard, but that ain’t as much fun as lying on the bed and doing it, eh?

Life with a Mac. It just keeps getting better.

Uncategorized

Comments (2)

Permalink

Origami: O-blimey!

When I first heard all the hype and excitement around Microsoft’s Origami project, I have to admit - I thought it would be a slightly innovative, sort of good looking, but only marginally useful device. I have to admit, I was wrong.

It turns out that it lacks any innovation, is ugly beyond belief, and completely useless. Ladies and gentlemen, behold the Ultra Mobile Personal Computer, or UMPC. I have to wonder which department at Microsoft names these things. They’ve really got a whole lot of creativity in there. If only the iPod were called the Super Mobile Music Player, what a phenomenal success it would be today.

I thought that after the XBox 360, Microsoft finally had some good designers. As for this piece of… never mind. Lets just say I’ve seen Salora black and white TVs in India that look better. Lets try to stay positive, shall we, and examine what Microsoft (and associated partners, Samsung and Asus) have to say about it thats “good”.

Ultra Mobile, goes where ever you go? Dear God, this thing is the size of half a sheet of copier paper and measures 15 cm x 20 cm. Contrast this against the Mac Mini, a desktop computer, which measures 16.5 cm x 16.5 cm (of course, the Mac Mini is thicker). The point is, this ain’t going into any pocket of a piece of clothing that you own, unless you’re Godzilla. Which means you get to carry it in its own case, and might as well get a nice 10-inch notebook like the VAIO TX series (which has a rocking 7+ hours of battery life as opposed to the UMPC’s measly 3 hours), and you’d basically be as mobile.

Runs a “fully functional” Win XP Tablet PC edition, which means you can basically run any Windows program on it, as opposed to most PDAs (which UMPC intends to replace). What is anyone going to run on this thing, given that it has no keyboard? Microsoft has made the mistake (again) of releasing a new hardware platform without even thinking about what software people would need for it. You aren’t going to type in your year end report using an onscreen keyboard or handwriting recognition. When the first Tablet PC XP edition was released with hardware, it did have at least some new features like the journal program and solid handwriting recognition. And yet Tablet PCs have failed to capture the market.

Apparently GPS software will be available for it, which of course is already available for most PDAs running Windows Mobile. And we read at MacWorld that PopCap Games will release Bejeweled 2 and Zuma for it. Exciting, no?

When PCWorld asked the lead executive behind the Origami Project why anyone would buy this device, here’s what he said:

“…laptops are often too cumbersome for casual users to lug around, especially if they just want to access the Internet or download photos from a flash storage card while on vacation. On the other hand, a PDA is too small for a satisfying Internet-browsing experience.”

Lets plan a vacation, dear. $500 for the airfare, $200 for the hotel, $300 for food and shopping, and oh, $800 for the UMPC without which our vacation will be such a failure.

Innovation? The UMPC runs a two-year old operating system on an Intel Celeron chip, with, as far as the eye can see, buttons and LEDs all around competing for the ugliest duckling award, which of course, is won hands down by the what looks to me like a speaker. This from three of the largest firms in the industry - Microsoft, Intel and Samsung. Anybody wonder why I’m an Apple fanboy?

Uncategorized

Comments (5)

Permalink

Sing it for me, Abba…

You can code, on your drive, having the time of your life
Write that script, watch that feed, put in the random seed…

Friday night and the work is slow…
Stuck at the comp no place to go…
Typing in a frenzy, breaking in the spring
You gotta get that ping
Nothing else will get you by
The night is young and the coffee’s nigh
With a couple of reboots, everything is fine
You’re in the mood for a game
And then you hear that name…

You are the working geek, leaden feet, oh you stupid freak
Working geek, feel the heat, its the hard disk seek
(oh yeah)
You can code, on your drive, having the time of your life
Write that script, watch that feed, put in the random seed…

Uncategorized

Comments (6)

Permalink

What’s your poison?

.flickr-photo { border: solid 2px #000000; }.flickr-yourcomment { }.flickr-frame { text-align: left; padding: 3px; }.flickr-caption { font-size: 0.8em; margin-top: 0px; }


Whats your poison?, originally uploaded by nigham.

Uncategorized

Comments (6)

Permalink

Game on!

d2linux

Diablo II: Lord of Destruction, on Linux, using WINE. Bliss :) No better way to get high just after a deadline!

OK, here’s what I did. I’m using Fedora Core 4, by the way.

  1. Install wine. All you need to do is yum install wine
  2. Run winecfg
  3. Go to the “Graphics” tab. Check “Emulate a virtual desktop”, make it 800×600 (max resolution of Diablo II)
  4. Go to the “Drives” tab. Normally C: and Z: should be added. Click on Add, D: should be added, set the path to /media/cdrecorder (or whatever directory you mount your cdrom into)
  5. Insert Diablo II CD. It should automount, otherwise mount it.
  6. I will assume /media/cdrecorder is your cdrom directory. From anywhere outside .media/cdrecorder, run wine /media/cdrecorder/SETUP.EXE
  7. Install as usual. When the installer asks for other discs, simply type eject at another prompt, and put in the new CD. Remember you must mount the CD (or wait for it to be mounted) before clicking OK inside the installer.
  8. Run the video test and choose Direct2D (HAL) as your mode (I ran into problems with Direct3D. Maybe it’ll work after some tweaking, but hey, this is Diablo).
  9. Exit the installer.
  10. Insert Diablo II Expansion CD and install as you did Diablo.
  11. It’ll complain about not finding the CD drive, forget it for now.
  12. Download your favourite patch from Blizzard.
  13. Download a NOCD crack for your D2LOD version from GameBurnWorld.
  14. Your fake Windows/Diablo directory is most likely ~/.wine/drive_c/Program Files/Diablo II/. Install the NOCD crack as needed into this directory.
  15. In KDE, go to Control Center -> Desktop -> Window Behavior and set Alt + Left Click on Window to Nothing. Unless you want to play Diablo without picking up items.
  16. You’re all set. Just run wine ~/.wine/drive_c/Program\ Files/Diablo\ II/Diablo\ II.exe and kick some monster ass!

Cross posted on Eudyptula Minor, a Linux cooperative blog I’ve recently started contributing to.

Uncategorized

Comments (3)

Permalink