Jan 182009
 

We are still only in the low lands of boost territory but already we are coming across useful discoveries. Today’s stop is boost::assign, one of those clever little pieces of code that makes life easier for everyone. Often you just want to load up a container with some small amount of data. The STL containers do not make such a task particularly easy:

vector<string> faceCards;
faceCards.push_back(“jack”);
faceCards.push_back(“queen”)
faceCards.push_back(“king”);
faceCards.push_back(“ace”);

What a pain in the neck! With boost::assign it becomes:

vector<string> faceCards;
faceCards += “jack”,”queen”, “king”, “ace”;

Neat.

It gets better. A lot of the time you want to fill a container with some data for testing but you don’t really care what that data is:

list<int> data;
// data will contain 1,2,5,5,5,5,5,5,5,5,7
data += 1, 2, repeat(8, 5), 7;

Or even:

list<int> randomData;
// data will contain 1,2,(8 random numbers),7
randomData += 1, 2, repeat_fun(8, &rand),7;

Of course, other containers are supported. This example uses the more flexible insert function (there are other functions for inserting at specific points for containers that support such things):

map<string, string> maoriColors;
insert(maoriColors)(“ma”, “white”)
                   (“whero”, “red”)
                   (“kakariki”, “green”)
                   (“kowhai”, “yellow” );

As with all the boost libraries, a lot of thought has gone into to making the interface safe and flexible. The library can even be extended to non-standard containers if the need should arise.

All the best magic tricks are really just smoke and mirrors, boost::assign is really just functions that secretly return functor objects and operator,() abuse. Unlike most magic, knowing how it works makes it even more delightful; the library is very well documented.

Although boost::assign is useful anywhere, it really shines in simple throwaway programs and test harnesses, where small, simple and easily modifiable code is the goal. I keep finding more and more places to use it.

Jan 132009
 

Although I like to think of myself of a jack-of-all-programming-trades, I must admit that I am mainly a C++ man. I have dabbled in the seductive dark side of Java and C#, but still prefer the mad poetry that C++ code can generate. A few years ago, C++ was showing signs of its advanced years but this has changed with the Boost libraries – a set of weird and wonderful additions to the C++ standard libraries that really bring C++ into the current century.
Continue reading »

Jan 052009
 

My first-generation MacBook laptop had only one problem – its first generation 60 gig hard disk. Actually it used to have two problems, but I installed more memory in it ages ago. 60 gigs doesn’t go far in today’s world of movies and huge software packages, so I felt it was time to upgrade. One trip to the store and a $167 EFTPOS transaction later and I am the owner of a new 320 gig hard disk, which seems to be the current sweet spot for price vs. capacity for 2.5 inch drives.

Thankfully Apple have made the job of replacing a MacBook’s hard disk extremely easy, and they provide step by step instructions. All you need is a 10c coin, a Philips #1 screw driver, a piece of stiff card, and a secret tool not mentioned anywhere in the instructions!

torxscrew

The surprise turns out to be a manner of fastening of which I was hitherto unaware – a TORX screw. TORX screws are used to hold the metal shield surrounding the drive in place, with the screw heads slotting into the bay runners – these must be removed from the old drive to fit the shield to the new drive.

Luckily I happened to have a #1 TORX bit in my tool kit, but finding an unfamiliar screw while a $3000 computer lies in bits on the dinner table is not an experience I wish to repeat.

driveinfo

After replacing the drive, I booted from the Leopard install disk, ran the Disk Utility to format the drive and then restored my data from my Time Machine drive. The end result is that my computer is set up exactly the same way as it was before, except I now have 250 gigs of free space to play with. Much better.

Oct 112008
 

First some facts…

Fact 1:
None of us can remember the passwords for the dozens of web sites we re all registered on. That is why web browsers all optionally store logon information and automatically fill out logon pages when we revisit a site.

Fact 2:
Web browsers do all support a special type of input control type specifically for passwords. Nothing entered into a password field is displayed, any characters are all displayed as asterisks. This prevents the password from being observed, either when it is first typed nor when it is automatically entered on subsequent visits to the page.

Fact 3:
Most web browsers allow you to type Javascript code into the address bar. This code is run in the context of the currently displayed document and has access to the object model.

Hmmmmmmmm…
Continue reading »

Sep 032008
 

So Google is going where angels fear to tread, and has released a browser of their own: Chrome. This is a very interesting move; I can think of a few reasons why Google might think a custom browser might be a good idea:

  • although everyone thinks of Google as a search engine they are really in the cryto-marketing field. Firefox plugins that remove ads must be a worrying development for them.
  • anything that helps people view more web pages is a win for Google, since more pages viewed equals more ad impressions.
  • having their own browser gets them a seat at the table when new web-standards are being created.
  • Google has a vested interest in promoting internet commerce, releasing a secure browser with safety features built in supports that goal.
  • most browsers have a search box that redirects to Google or another search engine. Chrome has a search/location bar that only redirects to Google – AdWords ahoy!
  • perhaps even sneakier, the search bar widget uses Google Suggest, so it is sending back information to Google as you type. I am sure Google can think of useful things to do with this information.
  • the search/location widget is a very interesting idea in its own right, effectively minimising the utility of domain names (which can be spoofed or camped.) Expect to see lawsuits fly when people work that their expensive .com domain name is not worth as much as they thought if this idea catches on.

I used Chrome for a couple of hours today at work (luckily I am in a line of work were this is not considered goofing off.) The interface is very clean and slick, even better than Safari. Having the location bar as part of the tab rather than above it make a lot of sense, and Chrome does it much better than IE, which I have always found visually confusing. I also like the way that Chrome uses the window title bar when full screen, giving you an extra few pixels of vertical height.

Chrome uses the infamous WebKit HTML layout engine, as seen in Safari and various Linux browsers. It is very fast at complex pages and supports all the fancy -webkit extensions to CSS. Sadly it does not include the excellent graphics renderer that comes with Safari, so fonts and images still look jaggy. Also, no support for @font-face – come on!

The network code seems pretty tight. Browsing through proxies worked well (a lot better than Safari) although it never seemed to do automatic NTLM authentication like IE.

There are a few omissions. Weirdly, Java applets do not seem to be supported. I am not sure if that is deliberate, or just something they haven’t gotten around to yet. No Mac version as yet, although it is apparently on the way.

Finally I must observe that commissioning a comic book for announce a product launch is one of the weirdly cool things I have ever seen.

Aug 142008
 

Apple has finally gotten its act together and added movies to the New Zealand iTunes store. Most older films are available to both rent and download outright, and the selection seems pretty good if not totally complete. The prices are not too bad either, you can definitely do better but they are not outrageously high.

Still no TV episodes though – what’s up with that?

Jul 232008
 

To celebrate my blog reaching 100 published posts, I decided to buy it a new font. After researching font creation for a couple of days, I decided that it was all too complicated and sought professional help: Fontifier is a web service that takes the pain (and believe me it is a pain) out of making a font. For the princely sum of 9 US dollars and 10 minutes effort you too can have a reasonable looking typeface.

The font I got back after uploading my sample sheet was OK, but I wasn’t happy with some of the letterform and the kerning was not very good. Enter FontForge, an open-source font editor. Although a little buggy and a lot hideous, FontForge let me fix up the problems without too much trouble.

And now for a rant about embedded fonts: I see today that Microsoft is trying to resurrect their EOT font embedding technology. This was the next big thing 10 years ago – a way for the browsers to download custom fonts for display while supposedly protecting the font from being pirated. What it is in practice is a non-standard font format that is a pain in the neck for legitimate users and no hinderance to the fiendish font-pirates at all. Everybody saw this 10 years ago, which is why you have never seen a page with embedded EOT fonts even though the technology has been around for a decade – nobody can be bothered.

The upshot is that IE8 will not support standard OpenType fonts in stylesheets. This is terrible news – if you are viewing this page using Safari on the Mac then you are seeing text rendered in my handwriting. This is purely decorative (it is so, shut up!) but I can think of several more practical reasons why a page may want to embed a custom font – think mathematical equations or hieroglyphs. With two completely non-compatible font formats, few authors are going to make the effort, and everybody loses.

May 292008
 

I updated to the lastest version of WordPress last week and I thought it was time for a new look. Unfortunately I have noticed that the RSS feeds don’t work in quite the same way as they did before, and although I like the general look of this theme there are some things that bug me a little. I will be dusting off my php coding skills and making some modifications over the next few weeks.

May 212008
 

Nintendo have finally released some original games to their online store. Having a couple of hours and $18 spare, I decided to check it out by buying Star Soldier R, because I have always been a sucker for 2D shooter games.

Star Soldier R

While the game looks good and plays well, I cannot say that it was worth the money. The big problem is that there is just not enough of it. Instead of several large levels that you might see in a traditional shooter, Star Soldier R has only 2. The challenge is to score as many points as possible in 2 or 5 minutes (depending on the mode). This could have worked if there were a variety of levels to play in, but you always start from the same place, shooting the same enemies. On top of that, the power-ups are pretty unimaginative.

All this makes the game feel more like a demo than a full game – it gives you a short taste of fun then cruelly shuts you down just as you feel you are getting somewhere. As it stands, Star Soldier R is just not good value even at its reduced price of 800 points.

Not really recommended.

May 092008
 

I was about 15 when I first read The Cuckoo’s Egg by Clifford Stoll, and it left a pretty big impression on me. Something about Stoll’s endearingly rambling tale of ingenuity in the face of what turned out to be a case of major international espionage really opened my eyes, and I think the book should be required reading for anyone considering a career in programming.

TED talks are something I have only recently been introduced to, but it turns out they have been around forever. Consisting basically of some dudes asking some other guys to give some short talks on stuff at a conference, TED has managed to attract some big names speaking about the big issues, with the odd juggler thrown in for good measure. Over 200(!) of the TED talks are available online, either through YouTube or as a podcast, and I highly recommend them.

Being a fan of both Clifford Stoll and TED Talks, imagine my delight when a podcast of Stoll giving a talk at TED showed up in iTunes. Here he is talking about – well he talks about a lot of things…

By the way, I strongly agree with his views on the roll of computers in education.

Mar 312008
 

A couple of weeks ago was using my old computer and discovered some long lost files from over a decade ago – back when my main computer was my trusty Amiga500. Although the laptop I am typing this on is easily hundreds of times faster and more capable in every way, I sometimes get nostalgic for the good old days.

Anyway, along with a few MOD files, my fourth year honors project, and assorted junk, I found a copy of this:

wizards.png
Wizard’s Isle Title Screen

Wizard’s Isle was a text adventure game I wrote one week during a summer that I spent gloriously unemployed (1995 according to the copyright notice). It is written in AMOS and runs perfectly in UAE (the emulator, not the country) – right down to the awful title music.

The premise of the game is that you have been sent to the titular island to ask the two wizards who live there for help with the strange events that have been occurring in the kingdom, but during the voyage your ship was caught in a storm and sunk. The game opens as you wash up on the wrong side of the island.

Playing the game again for the first time in 13 (thirteen!) years is a weird experience, like walking around the house you used to live in. I am amazed at how much I remember – I completed the game on my first attempt although it is rather easy apart from a couple of idiosyncratic puzzles. I remember putting a lot of effort into the writing, and apart from the spelling mistakes it holds up well, I think. Having said that, I don’t think I will be writing another text adventure anytime soon.

I have the files on my laptop, anyone who is interested can email me for the Amiga disk image.

Mar 262008
 

The browser wars are starting to hot up again. Apple is making a late play for cross platform browsing by releasing Safari 3.1 onto the world. Safari is MacOS X’s bundled browser – on the Mac it has always been pretty good, but the recent Windows versions have been terrible. Safari 3.1 is actually decently stable, and introduces Windows users to some nice features.

For a start, even on Windows Safari uses the Mac’s font rendering technology. Although opinions differ, I much prefer the Mac’s method of rendering fonts, to my eyes it is easier to read and more attractive. By comparison, standard GDI fonts in other Windows applications look spidery and harsh.

Safari’s other claim to fame is diligent adherence to up to date web standards. Features such as the canvas tag and SVG images are built in. Even better, advanced CSS properties such as animation and transforms allow for some cool effects – and some lame ones.

The Windows version of Safari does have some problems. A long standing issue is Safari’s reluctance to work with HTTP proxies. 3.1 is better than previous versions but still displays a distressing preference for crashing in a heap. Connecting directly to the internet works fine however.

It is hard to see exactly what Apple is trying to achieve with the Windows version of Safari. It seems unlikely that Safari will gain much traction against IE and Firefox (especially with Firefox 3 on the horizon). I suspect that Windows Safari is mainly intended for web developers – the more people who have access to Safari the more likely websites will be developed that work properly with Apple’s browser – including the all important iPhone. In any case, having another option, especially such a capable one, is not a bad thing.

Feb 132008
 
iTunes

Nestlé may catch some flack for pushing milk substitutes on developing countries and of having used forced labour on Cocoa farms in the recent past, but to give them credit they really know how to throw a promotion. At the moment, marked packs of Nestlé confectionary brands contain a code to get a free song at the iTunes store.

The great thing about this promotion is that it even extends to things like KitKats which cost less than the $1.79 iTunes charges for a song (I just bought one on special for 99 cents). This is an offer that is impossible to pass up for anyone who likes music or chocolate.

Supposedly the offer is only good for 5 songs per iTune account, but nothing seems to actually enforce this* – I just purchased my 6th song. I recommend using this service to buy only upbeat exciting music in the hope that this will help burn off the huge number of extra calories you will be consuming from the chocolate bars.

* UPDATE: Sadly, this hole seems to have been plugged – now iTunes won’t let you redeem more that 5 codes.

 Posted by at 10:05 pm