Archive for March, 2008

JQuery Fun

Wednesday, March 19th, 2008

I’m doing more and more work with JQuery lately, and as I mentioned several times before I’m totally loving Javascript again. It is really a very concise and terse framework so it doesn’t really take long until you start feeling like you know it inside out. But it is very powerful and learning to use it properly, and efficiently will probably take me a while. Last time when I was raving about it I did it without any neat code samples to show you how cool it is, so this post will have a few.

One nice thing about this framework is that it is all about closures. Most of the JQuery functions take a pointer to a callback function as an argument, and the selectors automatically loop through DOM instances they match forcing you to write very different code. For example, if I wanted to add an onClick event to all links on my page with regular javascript I would probably do something like this:

function addOnlclickToLinks()
{
    myLinks = document.links;
    for(var i=0;i < myLinks.length;i++) 
    {
       myLinks[i].onclick = return onClickFunction();
    }
}
 
function onClickFunction()
{
    // the on click code goes here
}
 
 window.onload = addOnClickToLinks

It’s readable, and understandable code, but it looks messy. JQuery saves you tons of typing and really makes the code more ellegant:

$(document).ready(function() {
    $("a").click(function() {
        // on click code goes here
    });
});

This is a totally new way to code, and it forces you to think in a much different way. After doing this for a while, you come to rely on this new way of coding to the point where it trips you up. For example, the other day I wanted to do something like this:

$("input.someclass").after(function() {
    if($(this).val() == foo)
    {
        // do somethign complex
    }
    else
    {
        // do something else
    }
 
    return something;
}());

What I want to do here is to generate element called something based on the value of the selected input - and the process may actually be quite complex, requiring several lines, or multiple function calls. The sample above doesn’t work because I’m using the $(this) selector in the wrong context. To the best of my knowledge, the way to achieve this sort of thing would be by doing:

$("input.someclass").each(function() {
    if($(this).val() == foo)
    {
        // do something complex
    }
    else
    {
        // do something else
    }
 
    $(this).after(something);
});

The each function actually iterates through all the selected elements, and runs the passed function in the context of each one. At least I think this is how you would do it.

Either way, it is really a much nicer way to program and the way you select DOM elements and interact with them is consistent across platforms. If you still haven’t tried JQuery, I highly recommend checking it out. Javascript is really a great language - it has a somewhat traditional syntax (braces and semicolons, ftw) but all the awesome features of a modern highly dynamic scripting language like Python or Ruby. The only thing that is holding it down these days is the inconsistency in which it is interpreted across browsers. JQuery fixes that issue, and draws on some of the cool dynamic features of the language to really make your life easier.

KOTOR 2: The Sith Lords - First Impression

Tuesday, March 18th, 2008

I got some really good suggestions in the Recommend a RPG thread. Some of these titles are older games that are not so easy to locate, but I’m planning to give several of them a whirl. In the meantime I got Knights of the Republic 2 on my hands. I loved the first part of the game, so I decided to pick up the sequel.

I’m currently 5-6 hours into the game, and I decided to jot down some preliminary notes about my first impressions. Keep in mind that I barely scratched the surface of this game so these impressions may change once I get to the “good stuff” or the “boring stuff” whichever comes first.

Firstl, I wanted to note that if you played KOTOR, you will be right at home with KOTOR2 interface because hardly anything has changed. The game runs on the very same engine, and other than minor tweaks here and there, it looks and feels identical to the original. This is not necessarily a bad thing. I guess Lucas Arts figured that there is no need to fix something that is not broken. )

This time around you actually create a Jedi character from start and you get to choose you Jedi class (guardian, sentinel, consular) which impacts your beginning skill set. I kinda liked the way original KOTOR made you create a character with regular background first, and then got you into the Jedi business but oh well. Naturally you start with no cool force powers and no light saber. It is explained that you’ve been exiled from the Jedi Order and stripped of your powers after the Mandalorian Wars. You are also, the last Jedi in the galaxy as all the others wiped themselves out in the civil war that followed the Mandalorian conflict. If this was not enough, there is some odd looking Sith Lord chasing after you and trying to kill you, and there is a bounty on your head.

You find out all about this shitstorm hovering over your head, as you wake up on some random mining station in your Jedi PJ’s suffering from a mild case of amnesia. Shortly after you realize that almost everyone on the mining station died in some mysterious circumstances.

Jedi PJ's

It sounds like a hell of a beginning, but it’s not. For the first 4 hours of the game you are essentially running around the desolate station watching holo-recordings, talking to the 2 other surviving NPC’s and fighting the same 2 types of droids over and over again. The progress is very linear and you have very little choice left to you. In fact, the first few hours of game play have none of the ambiguous conflicting quests which force you to make moral choices which affect your alignment. You do get light and dark side points, but at times I felt it was a bit contrived. Let me give you an example.

At one point early in the game you find a prisoner locked in a holding cell of the station. He is obviously a key character and you will need him to unlock your further progress. Leaving him in the cell is not really an option, but depending on how you talk to him you will get light or dark alignment points. But the dialog options are a bit constrained. You can be either nice and trusting (to the point of being naive) or very rude and suspicious with almost no middle ground between the two. It’s a bit silly if you ask me.

You will destroy many of these spider droids

There are also some odd puzzles in this early level - there are two doors locked by a complex voice-print or security code. To unlock them you have to run all around the station and listen to many minutes of holo-logs to discover the right code combination or record enough voice samples to defeat the lock… Or you can just destroy the computer terminal right next to that door. WTF? It kinda takes away the satisfaction of solving the damn thing when you know you could have simply skipped it right away.

To add insult to the injury, most of those first few long hours you will be running around alone missing out on all the tactical aspects of team combat. You only get to put a team together in the last 20-30 minutes on the station. Not cool. If this was supposed to be like an extended training mission, it was the longest training I have seen lately.

Go Team!

Fortunately after you get out of that mining station, the game returns back to the familiar, open ended mode in which you can walk around, talk to various NPC’s pick up interesting side quests, and get conflicting mission assignments from opposing factions.

Too bad I don’t really care for my two first company members. One is some shifty petty criminal, while the other is some very cryptic, mysterious old woman who seems to be force-linked to you in some strange way. I don’t trust either of them, and neither one is particularly likable. The lady has a stick up her ass, and speaks in riddles all the time, while the dude just annoys me. Maybe they will grow on me in time though. I remember that the Jedi chick from the original game used to annoy me until I figured out you can flirt with her. P

Finally and Open Ended Environment

So far I’m not terribly impressed with the overly linear first few hours of the game or the 2 non droid company members I have met so far (the little utility droid is ok in my book). Still, it’s not a bad game - it has entertained me enough to keep me playing despite all these nitpicks I listed above. I think I reached the point where the missions will get more interesting, and the plot will start picking up soon. I still have no lightsaber, and there are plenty of open slots on my company screen to host some interesting new characters that I could use instead of greasy slimebol and grandma jedi. )

Novint Falcon

Monday, March 17th, 2008

I was skimming through the PC Gamer today, and I saw a review for an interesting gaming device - the Novint Falcon. What is it? Well, let me paint you a picture:

WTF??

This incredibly, awkward, odd looking contraption is essentially a force feedback joystick which works in full 3d, encompassing the the X-Y plane traditionally used by mice (up-down, left, right) and the X-Z plane (ie, forward-back, left-right) usually configured with joysticks. How do you use it? It seemed a little bit confusing to me so I decided to look for some videos of it in action. Apparently you wiggle that little ball in the air, moving it left, right, up, down and also pushing and pulling it away or towards you. Check out Veronica Belmont playing around with it:

I have two observations about watching this. One is that Veronica is kinda hot, but that’s besides the point. Second is that the Falcon looks incredibly uncomfortable. I’m sure that the tactile feedback is interesting but I can’t imagine using this device for an extended period of time. For one, there is no support for your hand. Most joysticks have solid base letting you rest your hand on it, and mice are used on a flat surface where your hand is naturally supported. The falcon on the other hand has you holding the controller in mid air. Carpal tunnel in the making if you ask me.

The buttons seem to be in very awkward position, and the whole device looks both overly bulky and at the same time somewhat fragile and delicate.

Don’t get me wrong, I have nothing against the innovative new experiments with the I/O hardware. If you can bring us a brand new method for interacting with our games, more power to you. For example, Wiimote was a slam dunk! Excellent idea, great execution and support. People who don’t even play games are loving it.

The Falcon seems like a great concept at first - I love the idea of unifying the X-Y and X-Z controls, and taking the force feedback to the next level. But the execution seems to be less than promising. Look at poor Veronica - despite of what she is saying, she looks extremely uncomfortable using that thing. Besides, even if the construction was different, and the control was more comfortable and intuitive, I think it would still fail. Why?

Well, let’s look at the facts. The device costs $239, and virtually no games support it. The website features Half-Life 2 and Quake 4 mods adopted to work with Falcon, but I doubt any big (or small) game dev studio would even consider building in support for it, because only few potential customers would need it. It’s like a self defeating loop - no one will buy it, because there are no games for it. No one will make games for it because no one is buying it. Unless you are a gaming giant (like Nintendo) there is only one way to get out of this loop - make the device so cheap that people will buy even if there is only few games that support it, and no prospects for growth in that area. If many people buy it just for shits and giggles you may reach a critical mass at which point game developers will notice your device and start utilizing it. But if it’s more expensive than a high end mouse, you have a problem.

Also, you are really better off making an exclusive deal with one of the big console makers. You have the innovative controller, they have the captive market. If they support your controller, you have it made. If they don’t, the console segment of the gaming market is still big on expensive gaming peripherals. Majority of PC on the other hand gamers are perfectly content with mouse+keyboard combo, and never even considered purchasing additional input device for the purpose of gaming.

The Road

Saturday, March 15th, 2008

I have this strange fascination with post apocalyptic stories. I love zombie movies, and MadMax like pictures despite their obvious cheesiness. I loved Margaret Atwood’s Oryx and Crake, and I’m glad that I picked up I am Legend after watching that unfortunate Will Smith movie which btw had nothing in common with the book, with exception of the title and the name of the lead character. So when I have seen the blurb for Cormac McCarthy’s The Road and looked through it’s glowing reviews I was sold immediately.

The Road Cover

The book paints a vivid and yet disturbing picture of a world in which civilization has collapsed. Some unnamed, and unreferenced cataclysm has scorched the earth and changed the world forever. The novel starts many years after the catastrophe but the planet still haven’t recovered. The conditions are essentially those of a nuclear winter - the sky is shrouded, sun is never clearly visible, and the temperatures rarely climb above the freezing point. When it’s not snowing, it’s raining. When it’s not raining, the wind is blowing around fine grained gray ash, that makes breathing difficult. All the life is gone - there are no birds in the sky, no fish in the rivers and all the vegetation either withered away due to the perpetual twilight, or got scorched away by raging firestorms years ago.

Cities are populated by hollow, plundered, rusting, roting or burned buildings. Every store, and house has been looted years ago and everything is in the state of decay. A man and his son are traveling through this empty, sad and desolate world trying to reach the sea. They are always on the verge of starvation, as finding food is becoming more difficult every day. What is worse, they are not the only survivors. There are other people out on the roads, and they are also starving and are ready to do anything to survive. Anyone they meet is a potential threat - as the last human remaining communities seem to sustain themselves either by warfare and banditry or through cannibalism.

Unlike most of stories that deal with post apocalyptic scenarios, The Road is not some moralizing cautionary tale. We never find out what destroyed the world. It could have been a nuclear war, but it could have also been a force of nature - for example an asteroid impact akin to the one that wiped the dinosaurs in the past. No one knows, no one cares. This is not what the story is about - the story is about the human condition. It is a moving tale about survival, love, fatherhood and growing up in a world that has gone mad. It it is about desperately preserving the very essence of humanity against all the odds.

It touches upon many interesting topics - for example strange form of generation gap that exists only in this new reality. The father still remembers the world as it was before the catastrophe, but his young son has never experienced it. He only knows it from his fathers stories, and he suspects that he made up or embellished half of it. Contrasted with the bleak and harsh reality he knows, the fairytale sunny, overpopulated world full of teeming wildlife, and technology seems as alien to him, as the reality described in the book is alien to us. As the two travel together they see starkly different worlds.

Furthermore, how do you instill morality, goodness and kindness in a child in a world in which these values are only faint memories of a temperamental old man. Especially if this man can be as savage and brutal as the bandits and cannibals, when he is forced to defend his child.

There are no names in this novel - nameless characters move through nameless places. McCarthy stripped all the unnecessary geographical details from his narrative. The world is dead, the cities stand vacant, the rivers are empty - who cares what they are called. It wouldn’t make a difference - not to the characters at least. He concentrates on things which are important to them - like the weather conditions, the food they eat, or are able to find, the overpowering sense of danger, the omnipresent decay or the evidence of unbelievable depravities committed by the other survivors.

It’s thought provoking, moving and disturbing - and in a sense beautiful. The only thing that I didn’t like about it was the ending - the very last page or two [spoiler]where the boy is taken in by the strange man he meets on the road and his familly[/spoiler]. It just seemed anticlimactic. After all the stuff they went through [spoiler]he just finds a “normal” family, and lives happily ever after[/spoiler]? I don’t know, to me it just didn’t gel with the rest of the book. Perhaps I was really expecting either a very morbid, or very ambiguous ending - for example [spoiler]the boy taking the road alone this time, walking off into the gray ashen wasteland - this marking his passage into adulthood[/spoiler]. But alas, this is what we get. And since this conceptual glitch doesn’t show up until the very last 2 pages of the novel, I really think it’s not that bad.

If you haven’t read it, and you like this sort of post apocalyptic stories, definitely pick it up. But here is a word of warning - despite the premise, there is actually not that much action or suspense in this book. Or rather the suspense builds very gradually over many pages, and it is subtle. If you are looking for an action packed page turner, you will probably be disappointed.

Banking on the success of the adaptation of McCarthy’s other novel “No Country for Old Men” Hollywood already decided to create a movie based on “The Road” supposedly with Arragorn Viggo Mortensen in the lead role. I’m not really sure if Stareagorn could really pull this off.

I can’t wait to see how they fuck this one up. I wouldn’t be surprised if they decided to animate some of the cannibals and make them all monstrous and mutated, or made the father an ex navy seal and have him carry an M4 instead of the pistol. P Most likely the movie will totally suck - but then again, we’ll see.

Creating Encrypted USB Drives with TrueCrypt

Friday, March 14th, 2008

I discovered a neat TrueCrypt trick the other day while searching for products that would encrypt flash drives on the fly. I never noticed it before but it has an option to create a “travel disk”. It’s right there in the tools menu, as you can see on the screen shot below:

Travel Disk Option

It will essentially turn your chosen external drive into a self contained vehicle for TrueCrypt encrypted volume. It will copy all the files necessary for encrypting/decrypting the volume to the drive, and set it up to use the windows auto-play feature. So you just plug it in, type in your password and can start working with the encrypted files. The process is amazingly simple - so easy even a Caveman can do it. ) You just pick the drive, and choose whether or not it should auto-mount a volume on startup (yes it should):

Creating the Travel Disk

Then you click create. That’s all you really need to do. One thing this process doesn’t do is actually creating the TrueCrypt volume file on that drive. You have to do hat separately - I wrote about how to do this earlier. I created mine ahead of time called it files.tc and plopped it in the root directory of my flash drive. All I had to do then, was to point the above dialog at it. If you don’t have a tc volume yet, you can just type in a file name in that box, - it won’t complain that it doesn’t exist. You can add the volume later.

Once you hit create, bunch of files will get copied to the selected drive:

Files on the Drive

The autoruns.inf is the interesting one. As most of you know, this file contains the commands used by the Windows auto-play functionality. This is what it really contains:

[autorun]
label=TrueCrypt Traveler Disk
icon=TrueCrypt\TrueCrypt.exe
action=Mount TrueCrypt volume
open=TrueCrypt\TrueCrypt.exe /q background /e /m rm /v "files.tc"
shell\start=Start TrueCrypt
shell\start\command=TrueCrypt\TrueCrypt.exe
shell\dismount=Dismount all TrueCrypt volumes
shell\dismount\command=TrueCrypt\TrueCrypt.exe /q /d

In fact this is the only place which references the file name you entered in that dialog box. You can easily change it to anything else and it will work. Inside the TrueCrypt folder you get the guts of TrueCrypt. These few binary files are what does the encrypting/decrypting in the background:

TrueCrypt Core Files

I can give this flash drive to anyone in the world, and as long as they are running Windows XP (I don’t think 2k autoruns flash drives) they will be able to work with it. All you do, is just plug it in, and you see this dialog:

The Automount Dialog

If you choose the TrueCrypt option you will be greeted by the familiar (well, familliar to me) TrueCrypt password dialog:

Password Dialog

If you give the correct password it will mount another drive on your system, which will be the encrypted volume:

New Volume

The two drive thing may be confusing to some lusers at first but it opens up the correct one automatically in explorer on startup. Besides, they can easily identify that one drive has some cryptic system files, while the other has their data.

From there it just works seamlessly as always - anything you move, copy to or create on the virtual drive will be encrypted. What encryption will be used? It is up to you. The encryption type is not tied to your copy of portable TC but to the volume you created. If I remember correctly I used 128 bit AES-Twofish combo on mine, but you can pick your own.

The nice part about this is that I can easily take another tc volume (different encryption algorithm, different password) stick it on my flash drive, name it files.tc (or modify the autoruns.inf with the new file name) and it will work just as well. Or I can copy the TrueCrypt folder and the autoruns.inf file to another drive, and it will work as well. I can essentially create a script that will crank these out at will, without even having TrueCrypt copy installed.

I’m considering making this mandatory for the folks at work. They do get a lot of use out of the flash drives - and the do handle confidential stuff sometimes. So this seems like a perfect solution. The only caveat is removing the flash drive from your system.The standard Windows “Safely Remove” dialog won’t work because the .tc file as well as the TrueCrypt binary will be in use. So removing the stick is really a 2 step process:

  1. Right Click on the TrueCrypt icon in the taskbar and choose “Dismount all Encrypted Volumes”
  2. Remove the Flash Drive using the usual method

The “Dismount Command” actually shuts down TrueCrypt which is nice. Otherwise it would be a 3 step process. I’m sure that most people in the world can deal with a single manual step when they are getting high grade encryption for free. But my users are not most people - they are the people who will cry about it. But there is not much that can be done about this other than just removing the drive without actually making sure the write buffers are flushed into the thing. I’m concerned that when working with a TrueCrypt volume, pulling out the flash drive prematurely my be doubly hazardous than usual - I have no clue how these encrypted file handle corruption and unexpected write errors.

So I suspect I will have to do a 2 hour phone in training session on this, write up a manual with step by step screnshots (hey, I already have most of them here - nice) and then just be prepared to field phone calls asking how to dismount the damn thing for the next 7 months.