All posts by Chris

[Book] Thrice upon a time

Thrice upon a time by James P Hogan is a short novel centered around a time machine. Fortunately this time machine differs from your typical H.G. Wells affair and can only transmit and receive information. While this can still lead to several paradox’s it does make it harder to kill ones grandfather. The actual theories explored by the characters as they uncover the capabilities of this machine make for an interesting read.

One of my favourite theories concerns parallel universes:

Suppose you send last nights lottery results to yourself in the previous day. Back in the previous day an alternative reality is created where you get the results and win the lottery. Well that’s great… except that doesn’t really help the you who just sent the winning numbers.

I can’t exactly recall who (or what) recommended this book to me but thanks!

A new version of software X is ready to install

How come every Windows application has to provide its own upgrade system? Logging on to my machine can consist of several prompts of how new updates are ready to install, firefox needs to restart, antivirus definitions have been downloaded, and by the way would you like to update these plugins?

I can’t even play a game of Rainbow Six Vegas without it checking for an update first.

Ubuntu Linux handles this much much better. Most (if not all) of your installed applications are managed by a central repository. Only one update program is needed and it doesn’t ask you to reboot every twenty minutes.

I propose a similar system for Windows.

First step is to create an open specification which details:

  • how to register your application with the update system
  • format of application version information and how they are to be retrieved
  • how updates are performed
  • user interface guidelines (when to show notifications, information to show, etc)
  • what to do in the event of competing update systems

Second step is to create an open source implementation based on that specification. This is important as it gives people something to play with straight away. It also doesn’t lock them into your upgrade system and allows for outside improvements. If they don’t like it, they are free to use another implementation (or even create their own!).

An updater systems falls into the same category as installers; they are complicated and hard to do right. You shouldn’t be creating your own installer, so why should you create your own updater?

Instead concentrate on your own product and stop bombarding me with update notifications!

A client of works just got SideSwipe’d

In this mornings New Zealand Herald; the SideSwipe section contained the following paragraph:

Pete from Tauranga, and 25,000 others, trotted along to see Eric Clapton at the Mission concert in Napier on Saturday night. “A great opening act,” he says. “But what a bummer when a computer ‘error message’ popped up on the huge screens designed to give a better view of the stage. Woops!” – New Zealand Herald

This text is acompanied by a photo of the incident. Unfortunately I can’t find the photo online and it scans terribly. Although just looking at the photo I can tell that the screen was definitely made by monstaVision.

An odd collection of assorted images

With the help of a plug-in and several strategically placed tweaks I’ve managed to convince WordPress and Gallery to play nicely together.

Here’s my terse guide if you would like to follow in my footsteps. I’m going to assume that you are actually reading the provided installation materials and not solely relying on my terrible guide.

1) Install WordPress

This was quite a while ago, so I’m not going to be much help with this one. Follow the documentation and you’ll be fine.

2) Install Gallery

Installing Gallery is surprisingly easy. The install script is great and tells you exactly what is wrong and how to go about fixing it. Once installed I had no problem going through and configuring everything… well except for themes. I couldn’t really find a layout I was happy with, and I’m not looking forward to hacking around with the provided templates.

3) Install plug-in

Installing the plug-in in the same fashion as all WordPress plugins. Download, extract into WordPress directory, activate plugin, done. When configuring the plug-in you provide the URL to your gallery and it auto configures based on that.

i) If you’re using sub domains (e.g. blog.mydomain.com and gallery.mydomain.com) then you may have issues. I was able to solve this by disabling Gallery’s URL rewrite feature.

ii) Make sure that your WordPress user has the same name as the Gallery user. If not they won’t match up and the automatic logging in won’t function correctly. WordPress won’t let you rename the admin account but Gallery2 will.

iii) I ended up hacking up the template to add the Gallery “page”. There is a nicer way by using yet another plug-in. I’ll leave it as an exercise for the reader.

You can view my gallery by visiting the handy gallery link along the top bar. I’m still adding images so consider yourself warned.

[Book] The Emperor’s New Mind

The Emperor’s New Mind by Roger Penrose is concerned with answering the question of whether artificial intelligence is infact possible. Are our minds capable of being modeled by an algorithm or is there something far more complicated going on?

In a quest to answer this question Mr Penrose covers a variety of subjects ranging from turing machines to general relativity and quantum physics. While most (if not all) of the material is looked at in terms of computability, I found this did not distract from giving a good overview of each field.

Definitely a worthwhile read and a very good introduction to modern physics. However, it is not light reading and can get quite complicated in places.

For science fiction based on quantum physics: Greg Egan’s Quarantine.

Greetings from 2007

Happy New Year

Muriwai Beach, Muriwai, New Zealand
Muriwai Beach, Muriwai, New Zealand

Yet another photo, this time of the west coast (Devonport from my previous post is on the east coast). Actually this isn’t one photo but two. I cheated and stitched them together using Hugin. Unfortunately I forgot to lock the exposure between shots which meant some further tweaking with the GIMP was required. It turned out amazingly well considering I wasn’t really going for a panorama at the time. Which just proves the digital photography mantra of quantity over quality.

Muriwai Beach is not only a good spot for swimming, camping, and surfing; there is also a short walk to a Gannet colony. For more information have a look on the ARC website.

Happy holidays

I’ll sneak in a quick post before the new year and wish you all a merry appropriate holiday. Those of us in the southern hemisphere get to spend this time frolicking in the sun and enjoying the outdoors. This is in contrast with northern hemisphere dwellers who have to deal with a frozen wasteland full of ice and monsters.

North Head Devonport
Overlooking Devonport with Auckland CBD in the distance

Art imitating life

In the New Zealand Herald this morning:

Countdown to the auckland city council elections

Which is based on the clock I helped develop:

Downtown Auckland Clock

For those interested there are actually four sections to the clock: days, hours, minutes, and seconds. Each of these sections consist of a series of digits, the quantity being dictated by the value being shown. So seconds requires eight digits, while hours only needs four.

Each digit is made up of twelve monstaVision modules in a three by four configuration. While the clock is only displaying red digits; the modules themselves are actually capable of full colour, full motion video, and outputting over 5000 cd/m2 of light. These are the exact same modules that you see in giant LED screens.

Behind the scenes we have a single Linux box with a dedicated connection to the Internet. This box runs our video server software and renders characters with a true type font, using the freetype library. We use the Internet connection for remote monitoring and synchronizing to an atomic clock daily.

[c++] Cross thread communications

With GUI development it is not unusual to have several threads of execution running at one time. Normally one of those threads is dedicated to handling the user interface, while the remaining are used for auxiliary tasks. Unfortunately this can cause problems if you need to update the GUI from one of those other threads.

Typically SendMessage (part of the win32 api) is to used to notify the GUI thread, which then looks at the message id and acts accordingly. As you add more messages you need to add more message ids. Then there’s the greater problem of passing data between threads and the associated synchronization problems.

Fortunately there is another way using our old friend the command pattern:

///  update text box text from another thread
void MyGuiClass::UpdateTextBox(const std::string& text) {
	class GuiCmdUpdateTextBox : public GuiCmdBase {
	public:
		GuiCmdUpdateTextBox(MyGuiClass& gui, const std::string& text)
		: gui_(gui), text_(text) {  }

		virtual ~GuiCmdUpdateTextBox() { }

		// function operator is called by the GUI thread while processing the message
		virtual void operator()(void) {
			gui_.TextBox.SetText(text_);
		}
	private:
		MyGuiClass& gui_;
		const std::string& text_;
	};

	// send a message to the GUI thread and block until it has been processed
	gui_send_command( GuiCmdUpdateTextBox(*this, text) );
}

Using this method we have both the message sender (gui_send_command) and handler (GuiCmdUpdateTextBox::operator()) within the same function. This is a huge win, considering that we’ve also solved the data passing issue as it is neatly bundled up within the functor. You can see exactly what it is doing and what is needed to do it.

As for the magical wrappers that make all this happen:

/// pure virtual base class for GUI commands
struct GuiCmdBase {
	virtual ~GuiCmdBase() { }
	virtual void operator()(void) = 0;
};

GuiCmdBase is a straight forward pure virtual functor. By using a virtual function we no longer have to manage message ids.

/// send a GUI command across threads
void gui_send_command(GuiCmdBase& cmd) {
	// 1) add item to queue
	// 2) notify GUI thread that there is an item on the queue
	// 3) wait for command to be processed
}

gui_send_command is responsible for the actual sending and as such is library dependent. You have to queue the command to be processed and then notify the GUI thread. While you could just pass the pointer directly to the GUI thread this can be a very bad idea. Especially in win32 land where other applications can send you messages… In those cases I prefer a simple queue that you can retrieve pointers from.

// GUI thread message processing:
case MSG_GUI_CMD:
{
	GuiCmdBase* cmd = get_next_guicmd_from_queue();
	if (cmd) (*cmd)();
	break;
}

Once notified all the GUI thread has to do is call the provided functor.

I’ve successfully used this technique with win32, Qt, and wxWidgets.

Car on car deathmatch

Sigh… some guy ran into my car yesterday.

My poor car

I was cruising down the road passing parked cars when a car lunged at me from a drive way. Instinctively I had started slowing when I saw him but assumed he would stop… which he eventually did but it required my help. Fortunately one of my passengers knew exactly what to do and helped with gathering witness and driver details.

So for those of you who are unfamiliar with what to do:

  • Always carry a pen in your car. Every one has paper, no one has a pen. Witnesses don’t have pens and neither does the other driver. Typing details into your cell phone sucks.
  • Get your vehicle off of the road. The last thing you want is another accident. Car bits go in the boot.
  • Get the other cars number plate and make sure they are also off of the road.
  • Look for and gather witness details. The other driver isn’t going anywhere but the witnesses might.
  • Consider calling the police. If the other driver is going to be a problem or the situation requires it then make the call.
  • Get the other driver details. You want a name and phone number at the very least. Also make sure you get a look at their drivers licence. I even went as far as writing down the licence number but it is also useful for checking spelling of their name. AA Insurance also recommends getting their address and insurance company details.
  • Take photos! Of your car, theirs, the number plate, them, everything! Most cellphones have inbuilt cameras so you might as well use it.
  • Once that’s all done you need to check if your car is still road worthy. I was lucky as I only lost my left indicator, we also managed to pull off enough other stuff so that nothing would fall off and the wheel wasn’t hitting anything.

Then soonish you should:

  • Collate all the information you’ve gathered and call your insurance company. They will tell you how to proceed. I’m with AA and they’ve been really good. If you don’t have insurance then you shouldn’t be on the road.

So my poor car is in at the panel beaters until late next week. I’m told most of the damage is superficial. Better yet while cleaning out my car this morning I discovered a fifty dollar voucher in the glove box. I’m unsure how old it is but it hasn’t expired. So wooooot.