Sunday, 20 April 2008

The Element Song: various versions

Got home at 2.30, after watching DJ Shadow + Cut Chemist at Luna Park
in the city... ( then checked my email... noticed a link about Tom Lehrer, who's famous for the Element Song, a crazy romp through the periodic table, sung to the tune of Gilbert and Sullivan's, "I Am the Very Model of a Modern Major-General" from Pirates of Penzance (thanks to Bob Funchess for the song title)

end result: just spent 30 minutes going through youtube, checking out
various versions of The Element Song.

Damn you Google blog!

(and he also did that song about "silent e" for Electric Company! OMG.)

my faves so far:

the original (audio only):

great version at a talent show:

sung by a 4-yr old (who kinda sounds like Martin Price from the Simpsons):

showing the elements' location in the table:

this isn't a version.. but still interesting rapping with *some* of
those elements..

Saturday, 19 April 2008

OpenSocial for MMOGs?

Woke up at 5.30 am, after dozing off last night without having dinner. Torrential rain pouring when I woke up but it's stopped now. Random browsing. Finally saw that Judd Apatow "Backlash" video that's been in an Opera browser tab for >1 month - shameless, self-aware viral marketing... lol. i think.

Came across an great post on another gaming site, "Player vs. Everything: When will the players leave WoW?", discussing why people aren't going to be leaving WoW anytime soon.

Interesting how the social aspect - in this case networks of friends from all over the net - is such a big factor in the "stickiness" of these games, whereas before it was completely based on the gameplay. It makes it much harder for rivals to make a significant dent in the market. Not only does your game need to be much more compelling, but you need to factor in that networking aspect, which goes beyond coding wizardry or eye candy.   You can't just fix pain points, or be slightly better.  You have to make it compelling enough not just for one new player, but all that player's friends to play and stay with your game. 

If you have a new player, how do you make it easy for them to move over as much of their current network to your game?   Signup bonuses? Almost-free copies of the game, which you can't really play standalone? (I think WoW already have this?) In-game equivalents of pyramid schemes? Those horrible Facebook apps do it by spamming everyone you know - actually, it's not the app, it's you doing the spamming! But how the hell will that apply to a MMOG?

It's quite similar to the stickiness of the current "web 2.0" hotspots like MySpace, YouTube... once you've built up relationships and conversations in one area, it'll be very difficult to get out and start anew, since you've built up all this content and would be loath to just throw it all away. Social networks are the new vendor lock-in. (yes, someone else came up with that)

The only sites I can think of that make it a bit easy to migrate are the blogs, but mainly because the content is fairly generic (text, tags, comments!) and easily restructrured. I can't see this model ever being applied to games - "Why sure, we'll let you move on to another MMO, no probs!"  OpenSocial for MMOGs, anyone? Of course, the question here becomes: is there anything at all that is portable across different games?

Saturday, 12 April 2008

How to run code when your Java program is being terminated? Use ShutdownHook!

The starting point for this was a problem I have at work, where we have a program that is using ScheduledExecutorService, and is meant to run continuously, but we also want to run some code when the program is terminated with Ctrl-C or a 'kill' command.

At first, I thought that a try-finally would give me what I wanted. A little bit of testing proved me wrong. The try-finally structure can handle exceptions, and ensure that code enclosed in finally is called, but only in the case where the process is running normally, and not terminated externally. The statement inside a finally{} will not execute if the JVM is terminated.

The ShutdownHook is what I needed, which was added in JDK 1.3.1.  The method to use is Runtime.addShutdownHook().  The shutdown hook is pretty much any code you put inside the that you pass to this method.

public class FinallyTest {
public static void main(String[] args) {

final int thisNumber = 9;
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
System.out.println("I am now calling my shutdown stuff. EVERYTIME!");
System.out.println("This number: " + thisNumber);

try {
boolean loopIt = true;
int i = 0;
System.out.println("Now entering infinite loop.");
while (loopIt) {
try {
} catch (InterruptedException e) {

} finally {
System.out.println("Finally has been called!");

Running the program, and then killing it gives me (this is on OS X, on an iMac):

krangsquared$ java -cp . FinallyTest &
[1] 5735
krangsquared$ FinallyTest.main
Now entering infinite loop.

Okay, we now have a process Id. Let's kill it! 

krangsquared$ kill 5735

krangsquared$ I am now calling my shutdown stuff. EVERYTIME!
This number: 9

[1]+ Exit 143 /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java -cp . FinallyTest

The only catch to this is that this will not work if you terminate the program using "kill -9".  And I haven't checked this yet on Windows to see what happens if you kill it using TaskManager. (is there a "kill -9" equivalent on XP?)

Hope this helps someone out there! Or maybe someone who has a better idea or suggestion can make a comment. I need all the help I can get.  :)

Btw, I've found a blog post with a nicer way of doing this - instead of dumping a whole lot of stuff in a as an anonymous inner class (insert. closures. proposal. here.), have another Runnable inner class to contain all the shutdown code, then pass that in to the constructor of a new Thread that you pass to addShutdownHook().