The Aliens Rap

February 3, 2010 – 12:25 pm

Following up on the epic 10 minute rap summary of Robocop, the same team has released Aliens:


open at youtube.com

Watching this reminds me what a great film Aliens turned out to be and how Avatar (by the same director) pales in comparison. It’s not that Avatar was terrible but nobody is going to be making 10 minute rap songs about it in 25 years.

quick update: Hey, they’ve done Terminator 2 as well!

Film Review : Avatar

January 3, 2010 – 9:03 pm

James Cameron has always been an interesting film maker. Although on one level most of his films could be classified as pulpy genre-related fare, they usually have a more interesting subtext lurking below the explosions. Previous Cameron films have investigated such themes as mother/daughter relationships, humanity’s fear of the unknown, musings on fate and predestination, and whether it is morally acceptable (and perhaps even admirable) to slum it with a good looking lower class boy for a few weeks before you get married even though an ocean liner might not be the best place to do so. So it is with a heavy heart that I have to say Avatar is a slight disappointment.

avatarThe planet of Pandora (Who names these planets? What were they thinking?) has some stuff that humans want to mine. Unfortunately, the best place to get it is right on top of where the indigenous population (8 foot tall skinny blue people called the Navi) live in harmony with their world. The Navi are distrustful of the humans, so in order to investigate the Navi a bit more, the humans create the titular avatars – mindless Navi bodies that certain individuals can “drive around” remotely. The main character is just such an individual, and he (or his avatar) quickly becomes involved in the local tribe. Although the humans would prefer that the Navi move on without violence, it is clear that a military solution, led by a crazed marine, might be more expedient…

It is almost impossible to spoil anything about Avatar’s plot, no doubt you have already guessed the direction it which it unfolds. It is a shame that for all the risks involved in making what is apparently the most expensive movie ever made (it certainly looks like it), the story is as safe as an after-school special. The film could have made some interesting points about colonialism, or environmentalism, the military, or even feminism, but instead chooses to unspool a conventional yarn where the good guys are selfless and the bad guys are crazy and evil. It is not that is it a bad story per say, just something we have all seen many times before.

I saw Avatar in 3D, it is by far the best 3D experience so far. The lush jungles and mist-shrouded peaks of Pandora look amazing – Avatar is simply the greatest visual treat I have ever seen. The contrast between the sharp grey lines of the human base with the colourful, glowing environment outside is very well rendered. James Cameron has always been interested in portraying technology and Avatar is no exception – a nice touch is that all of the displays that the humans use during the movie are also in 3D. There are a thousand little details like that I loved about Avatar, it is just a shame that the whole thing isn’t as great as the sum of its parts. However, anyone who shares Cameron’s love for helicopters and giant robots and things being blown up by helicopters and giant robots will be thrilled.

Highly recommended if you can see it on the big screen in 3D. Otherwise only recommended if you like this sort of thing (but who doesn’t?)

The Phantom Menace Was Not a Very Good Movie

December 17, 2009 – 5:40 pm

I own all of the Star Wars DVDs except for one – The Phantom Menace. Even the weakest of the others have a certain charm, but TPM was stupid through and through. Even the title is stupid! I have yet to work out exactly what the titular menace actually was. Although the story includes several menaces, none of them seem particularly phantomastical. Unless the menace was supposed to be Palpatine’s amazingly convoluted plan, but that plot point doesn’t really bear fruit until the second film.

Anyway, I haven’t given The Phantom Menace much thought since it first came out but this guy certainly has:




Part 1
Part 2
Part 3
Part 4
Part 5
Part 6
Part 7

Even if you ignore the affectations of the reviewer, he has some pretty insightful points about how TPM fails as a movie.

The C++ Boost Libraries Part 6 – boost::any

December 6, 2009 – 3:41 pm

In C++ if you have a variable that you say is of type “Person” (for instance), you can be fairly certain (more or less) that it always actually contains a Person (or perhaps a subclass of Person. If you have a container of Persons, then you know (more or less) that every member is also a Person (or a subclass).

This is all very good, prevents a lot of runtime errors, and generally makes C++ a great language if you care about correctness. But sometimes, very rarely, you actually want to store a whole bunch of messy, unrelated types in a container without trying to ram them into some sort of class hierarchy. Parsers are a good example of this. It is often convenient just to chuck tokens of various types into a data structure for later processing without worrying too much about the specific type (string, int, float, etc).

boost::any is a small class that can hold values from almost any type, designed for just such messy applications. Using boost::any is very simple:

1
2
boost::any a1 = std::string("Moose");
boost::any a2 = 6;

Of course, getting the values back again is a little harder.

1
2
3
4
5
6
7
8
9
try
{
	std::string v1 = boost::any_cast< std::string >(a1); // this works, a1 is a string
	std::string v2 = boost::any_cast< std::string >(a2); // nope, will throw an exception at runtime
}
catch ( const boost::bad_any_cast& e )
{
	// tried to any_cast into something that wouldn't go
}

Of course, you can query a boost::any for the typeid of the stored object. Just don’t do it when Scott Meyers is in the vicinity.

1
2
3
4
5
std::string v;
if ( a1.type() == typeid(std::string) )
{
	v = boost::any_cast< std::string >( a1 ); // this should never throw, since we checked first
}

A single boost::any is perhaps not that useful, but a container of them can store almost anything we want:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
typedef std::vector< boost::any > AnyVector;
AnyVector values;
 
values.push_back( 5 );
values.push_back( std::string("Hello") );
values.push_back( 5.3 );
 
try 
{
	for ( AnyVector::const_iterator p = values.begin();
			p != values.end();
			++p )
	{
		if ( p->type() == typeid(int) )
			cout << "Int = " << any_cast<int>(*p) << endl;
		else if ( p->type() == typeid(std::string) )
			cout << "String = " << any_cast<string>(*p) << endl;
		else 
		{
			cout << "Unhandled type: " << p->type().name() << endl;
		}
	}
} 
catch ( const boost::bad_any_cast &e )
{
	cout << "Bad any_cast<>" << e.what() << endl;
}

Any type that you put into a boost::any must be copy constructable (the any makes a copy, not a reference). You also have to make sure that its destructor doesn’t throw (but of course you do that anyway!)

Although I wouldn’t recommend boost::any for everyday use, it does come into its own when the only alternative is a huge class structure or (even worse) void *s.

Python and The Very Slow Server

November 28, 2009 – 2:23 pm

I don’t usually do a lot of Python programming, but I always enjoy it when the opportunity arises. Python is in no way a “clean” language, it has all sorts of warts and limitations that mean that it tends to not get used for big projects. Despite this (or maybe because of it), Python remains my go-to language for Getting Small Things Done Quickly. It is impossible to overstate the utility of just being able to start coding a function by bashing away at the python console – nothing else has given me the same sense of instant gratification since I started programming in BASIC back in the 80s.

The other big advantage of Python is the useful utility libraries that come with it as standard. Want to send twenty thousand emails? Just import smtplib. Want to generate code based on data from a spreadsheet? Import csv and away you go. Need a file that is exactly 32Mb is size? No problem. These are real examples from my job where Python has saved me many hours.

The most recent use I have put Python to is a slow server. For various murky and uninteresting reasons I need a rate-limiting HTTP server, one that I can easily control the speed at which it sends data. Enter Python’s very handy BaseHTTPServer module, which allows you to create custom HTTP servers with only a few lines of code by subclassing a request handler. Although the BaseHTTPServer is fairly useless for serving real files, it is perfect for this type of thing since it does all the boring work of parsing headers and returning status codes.

I don’t care about the contents of the data, just its size and how long it takes to serve. Since I will be varying these parameters a lot, I decided to make them part of each request so that each request could take a different amount of time – this means I don’t have to restart the server between each test run. Modifying the code to serve actual file data would be very simple.

I enjoyed writing this server so much that I regret that it didn’t take longer. Now I actually have to use it for its intended purpose, which I can assure you is not going to be as pleasant.

Here is the complete Python source:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# A very simple HTTP server designed to for testing situations where the data returned
# is not important but the rate at which it comes down is. This server can be started
# using the command: python delayserver.py
#
# Once started, it will listen for requests on port 8000
# Requests should be of the form http://<address>:8000/size=<bytes>,duration=<seconds>
# where: <bytes> is the size of the response data
# and    <seconds> is how long you want it to take (at minimum, it may take longer)
#
# Notes:
# * The timing is pretty inaccurate for small byte sizes, this isn't a problem for
#   what I need it for
# * Press ctrl-c to stop serving
 
 
import time
import BaseHTTPServer
 
class MyHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
 
	def do_GET(self):
		request = self.path.strip("/")
		duration = 1
		size = 1024
 
        	validRequest = False
		params = request.split(",")
		for p in params:
                    temp = p.partition("=")
                    if (temp[0] == "size"):
                        size = int(temp[2])
                        validRequest = True
                    elif (temp[0] == "duration"):
                        duration = int(temp[2])
                        validRequest = True
 
                if (validRequest == False):
                   self.send_error(404)
                   return
 
                self.send_response( 200 )
                self.send_header( "Content-Length", str(size) )
                self.send_header( "Pragma", "no-cache" )
                self.end_headers()
                self.slowWrite( self.wfile, size, duration )
 
 
        def slowWrite(self, output, size, duration):
                bytesWritten = 0
                startTime = time.time()
                while ( bytesWritten < size ):
                        now = time.time()
                        if (duration != 0):
                                desiredBytes = ( (now - startTime) / duration ) * size
                        else:
                                desiredBytes = size
                        desiredBytes = min( size, desiredBytes )
                        if (desiredBytes < bytesWritten ):
                                time.sleep(0.2)
                        else:
                                while (bytesWritten < desiredBytes):
                                        output.write('A')
                                        bytesWritten = bytesWritten + 1
                                output.flush()
                now = time.time()
                self.log_message( "Request took %f seconds",   now - startTime  )	
 
if __name__ == "__main__":
    http = BaseHTTPServer.HTTPServer( ('', 8000), MyHTTPRequestHandler )
    print "Listening on 8000 - press ctrl-c to stop"
    http.serve_forever()

I should point out that I am by no means an expert at Python, so take this code with a pinch of salt.

Pacman

November 27, 2009 – 11:00 am

Remember kids – winners don’t do drugs.

Catan – The First Island

November 3, 2009 – 9:38 pm

Catan ScreenshotI love the Settlers of Catan board game, so when an iPod version appeared in the App Store for $6.49 I grabbed it straight away. Dubbed “Catan – The First Island“, the app includes everything in the core game, I assume more games based on the Catan expansions are on the way.

The app plays a pretty good game, the interface is fairly straight forward and trading between players is handled well. Some rule variants are supported, like starting with a city instead of a settlement or different point targets. There are even different ways of distributing the resources for wusses who can’t take random chance. The computer players put up a fair challenge, and you can play hot-seat multiplayer but there is no internet play – an obvious omission.

Unfortunately, Catan also has some fairly annoying flaws. Firstly, the game is buggy. On both my first two games the computer player refused to finish its turn, leaving aborting the game the only option. The other 3 games I have had have worked smoothly so I still don’t know what I did to trigger that bug. Loading a saved game also sets some of the options back to the default, which is a pain but not game breaking.

Speaking of saved games, Catan does not automatically save your progress when you dismiss the app to go back to the iPod main menu. When you re-enter Catan it pops you back at the title screen with no way to resume unless you manually saved the game, something you can only do during your turn. This is intensely annoying, not to mention against Apple’s App guidelines and I hope the fix this if nothing else in an update.

The graphics are just OK, they get the job done without being very attractive and the board animation looks terrible. The whole package seems just a little unpolished – it works but needs just a little more attention to detail. The only thing that really saves Catan as an App is the mechanics of the game itself, which still shine. Perhaps after an update or two “Catan – The First Island” will reach its potential, but right now it is only for die-hard Catan fans.

A disappointment, only recommended if you like this sort of thing.

The Wellington Podcast

October 24, 2009 – 12:16 pm

Bevan McCabe, raconteur and man-about-town, is producing a podcast about this fair city. The first episode has just been released and it turned out rather well.

There is more information at the associated Wellington Podcast Blog, but the daring amongst you can just downloaded it directly (16Mb mp3), or subscribe to the Wellington Podcast using iTunes.

500 Impressions in 2 Minutes

October 19, 2009 – 11:01 pm


View at YouTube

This guy is incredible, how does he do that?

Also worth watching, from the same guy:
Wolverine in 30 Seconds
Unemployed Hitman
Terminator Salvation in 60 Seconds
StarTrek in 47 Seconds

Film Review : Moon

October 18, 2009 – 10:04 pm

Think your job is monotonous? Spare a thought for Sam Bell who comprises the entire crew of the lunar base that supplies the Earth with Helium3. Sam looks after the giant automatic mining machines that rove the Moon’s surface, sending back the recovered fuel to a world he hasn’t seen in years. The only thing to talk to is GERTY – a banal robot that helps to keep the base functional.

Hardly ideal working conditions, but if that wasn’t enough real-time communications with home have been cut off. Sam is only able to exchange short, recorded messages with his wife and mining company superiors, and the isolation is beginning to get to him. The good news is that he only has a few more weeks to go before his three year contract is up and he can return to his family. But even a week can be a long time for a man in such a fragile mental state…

For a low budget sci-fi film, Moon holds up very well. The tone is more reminiscent of more thoughtful films such as 2001 A Space Odyssey rather than the more usual alien infested fare. The plot moves at a fairly slow pace, but the lead actor (Sam Rockwell) and spectacular effects (the outdoor lunar surface looks particularly good) go a long way to make up for it. The one thing I thought was a little grating was that Sam was a fairly unlikable character to watch at times, stubborn and a little dim, but that can be explained by the tense situation – the film does a good job of putting you inside his one-note life.

Apparently Moon cost only 5 million dollars to make, but manages to both look more impressive and tell a better story than its blockbuster siblings. Highly recommended if you like this sort of thing.

Roller Derby

October 10, 2009 – 11:39 pm

Wellington is truly the cultural capital of NZ. Last weekend I attended the first art exhibition I have ever had to queue to get into; this weekend: Roller Derby!
Read the rest of this entry »

Tsunami

September 30, 2009 – 10:36 pm

It is not everyday that I awaken to the radio telling me that Civil Defense has been activated due to the imminent arrival of a Tsunami.

Luckily the effects of the Tsunami on New Zealand were slight to non-existent, but not totally unnoticed. The following chart is from the excellent GeoNet web site. GeoNet (amongst other things) maintains a system of tsunami gauges around the country for just this sort of event.

detide

The graph on the GeoNet site is a moving window so I have copied a static version here. I took graph snapshot at about 11pm, you can clearly see the waves hit different parts of the country in succession start from about 9:30am at Raoul Island (I didn’t know where it was either). Luckily for us there was nothing over a metre.

Samoa was not so fortunate as we were in NZ, with many fatalities in low lying areas despite a very speedy evacuation.

An Ad in The Economist

September 24, 2009 – 10:51 pm

Being an Important Publication, The Economist has Important Ads for Important Job Openings or Important Services used by Important People.

danddlawyers

“Hello, D&D Lawyers. How may we help you today?”
“My 3rd level fighter was dissolved by a Gelatinous Cube because the cleric wouldn’t use his last healing potion on me. My damages include 1 blue gem, a +1 dagger and monetary losses of over 3 plat. How soon can we bring this to trial?”

Public Health Does Not Suck

August 18, 2009 – 11:57 pm

As the song goes, we don’t know how lucky we are in this country and one of the things we take for granted is our public health system. It may not be the most well-oiled machine, but if something needs doing then it gets done in a timely manner and nobody ends up bankrupt. New Zealand (along with most of the rest of the Western world) has decided that individual health is a public problem, so the public will support the individual if they get ill. It works out much cheaper for everyone, but that is just a nice bonus.

I have been watching the recent furore in the US where President Obama is busy trying to introduce something similar there. This being the USA (a strange place), half the public seems to be convinced that public health is some sort of evil plot to destroy capitalism, enslave the population, and end the American way of life™. These people are, of course, idiots but they are not wrong about the effects of public health being far-reaching.

In New Zealand, we have a mixture of public and private hospitals. Going public usually means joining a waiting list but is much (much!) cheaper, and urgent stuff gets done straight away. Private hospitals are more expensive but are usually much nicer to stay in and you don’t have to wait so long. The actual quality of care is comparable; it is common for medical professionals to work in both public and private hospitals so in many cases the same person will be performing the operation in either case. Health insurance is considered a bit of a nice-to-have.

Compare and contrast with the US: hospital care there is ridiculously expensive, much more so than the average private hospital in NZ. The reason for this is that everyone (everyone who counts, at least) has insurance. It doesn’t bother the insurance companies that the rates are so high because they arrange bulk discounts with the hospitals, a very cosy arrangement that benefits both parties but not the public. By law hospitals cannot refuse urgent treatment even if someone comes in without insurance, but the hospital charges the inflated amount anyway because they know that the few people who do manage to pay off the full amount will make up for some of the deadbeats.

But isn’t health insurance a great thing that everybody should have? Well, health insurance is a funny business even by funny insurance standards. If you insure a car and it breaks, the insurance pays out unless the car broke due to a known defect, in which case the manufacturer’s warranty will cover it. But with health insurance, a defect is called a pre-existing condition which no insurer will touch with a barge pole – and the manufacturer is conspicuous by His silence. Anyone unlucky enough to have a chronic long-term illness is an anathema to insurance companies – they don’t want to know. Someone who continually crashes their car will pay higher and higher premiums until they are forced to learn to drive or give up car ownership, but an ill person does not have that option.

One effect of high health-care costs that I haven’t seen mentioned elsewhere is the inflation of lawsuits. We have all heard the stories about people getting injured in car crashes (for example) suing the manufacturers of the car (or the city) for millions of dollars, even if they seem to be at fault. These lawsuits are not all about greed (although that may be a factor as well) but are a consequence of paying hundreds of thousands of dollars in health costs. Often the insurance company or hospital will encourage the lawsuit just to get their money. It is a vicious circle.

I do not envy Obama. If he succeeds in his goal he will be remembered as a hero, but he seems besieged by loons, many of whom seem to be protesting against their own interests. If they react so badly to an NZ-style public health system, I shudder to think what would happen if they ever found out about ACC!

Anyway, my friend James is a (sane) American is trying to get a pro public heath website off the ground – National Health Care Does Not Suck. There is not much there at the moment, but hopefully it will turn into a nice repository of positive experiences with public health. On the other side of the coin, try this series of testimonials about bad experiences with US-style hospitals.

We don’t know how lucky we are in this country.
We don’t know how lucky we are.

Seals at Red Rocks

August 17, 2009 – 12:04 am

In my continuing quest to explore as much of my new home city as possible, yesterday I went for a walk around the south Wellington coast with a couple of friends. Starting from Owhino Bay there is a beach-side path that leads around the coast. Actually it is not a path. It is a 4 wheel drive track, so you constantly have to move to let big cars and off-road motorcycles passed. I don’t really mind 4WDing as a hobby and gladly got out of the way of the impressively muddy machines with knobbly tires, but many of the vehicles coming back the other way looked suspiciously clean. I resent sharing a track with tryhards.

Anyway, walking along the beach eventually gets you to a place called Red Rocks. There are some rocks there and they are indeed quite red, but the real reason for the trek was see the seals.

seals
click for a larger view

The seals were well camouflaged and did not photograph well, but I can assure you that the above photo contains over a dozen of them. Honest, you can see them if you look hard enough!