Jul 302009
 

I have just upgraded to the latest version of WordPress. Usually this is a simple procedure, but this time something went wrong – attempting to view the blog threw up a blank page!

Luckily I could still get to the admin pages, so I knew my database was still OK (of course I hadn’t bothered with a backup, so I was worried for a minute.) A couple of other people had the same problem on the WordPress forums, but no solution was forthcoming there.

It turns out that part of the upgrade process had overwritten my index.php file with an almost empty file that contained only comments. Whatever caused this problem (db upgrade? Who knows?), it went away when I copied the file afresh. I am starting to see why most people use a dedicated blog hosting service…

I think everything is working now – let me know if you see anything weird.

Jun 132009
 

Safari 4 has been out for a couple of days now, and I must say I am enjoying using it. On the Mac, Safari has always had a great overall browser experience but Firefox always managed to stay my weapon of choice for viewing the Internet. This may change, Safari 4 is a very nice piece of software.

Apple is clearly wanting to make Safari an integral part of the Mac experience – Safari is very well integrated into the Mac OS (you can use Spotlight to search your history, passwords are stored in the keychain, etc), and the UI has all the polish you would expect from Apple. I particularly like the graphical Top Sites view that Safari presents when you first start it.

One thing I have always liked about Safari is the way it renders text and graphics. It always seemed to be just that little bit more polished than other browsers – correctly anti-aliasing fonts and respecting the embedded colour profiles of images. In my opinion Safari is still the best looking browser.

Apple are making a big song-and-dance about how Safari 4 is much faster than other browsers. What they mean is that they have included a very good Javascript JIT compiler which speeds up script-heavy sites by a large margin. This is excellent news, but Safari is hardly alone in focusing on Javascript performance and very recent versions of other browsers have very similar performance.

On Windows, Safari is something of an oddity. It works just as well and still renders sites better than most other Windows browsers, but its awkward neither-Mac-fish-or-Windows-fowl UI doesn’t help. The Windows version also lacks the smooth GUI animation that makes the Mac version so pleasant to use. Apple are doing their best to push Safari onto iTunes users, but I can’t see it taking off except among web developers, Safari’s built in web development tools are very cool.

There are still a few problem areas. Safari doesn’t seem to enjoy displaying animated GIFs, which often stutter before they are fully loaded. It very occasionally beachballs for a second on some pages, not all the time but enough to be annoying.

Finally, another rant about the HTML video tag (since the last one got quite a bit of attention): Safari supports the video tag but farms out the video to Quicktime. I suppose this is better than nothing, but you can tell that it is not well integrated. Videos do not show up in the list of page assets and it is clear that Quicktime is downloading the video itself, bypassing the browser’s cache. On top of this, performance is quite poor when the Javascript controls are used. The video quality is top-notch, but the experience is disappointing.

It sounds like I am dumping on Safari, but really they are minor niggles in a sea of greatness. I still think Firefox has the edge (particular Firefox3.5, which is shaping up nicely) but you could do worse.

Jun 042009
 

The Secret of Monkey Island consumed a lot of my time back in the day, it is one of the best (and funniest) games ever produced. I have wondered for a while now why some of the old adventure games haven’t been dusted off and republished for the new consoles – the Wii in particular seems well suited to the genre. It seems somebody has had the same idea:

That’s the second biggest monkey head I’ve ever seen!

Update: Ron Gilbert, the author of Monkey Island, has posted a very interesting “director’s commentary” for the original Monkey Island.

May 282009
 

Back in the day there was no standard way to publish video on the web. You could put any kind of video file you wanted on the server, but there was no guarantee that your readers would have the correct plugin required to view it. Everyone had to have a bunch of plugins installed to have any hope of viewing the majority of video files.

Flash video solve this problem. Flash was installed on nearly every computer anyway, so once they added a video decoder it seemed obvious to provide video content in Flash, even if it was in many ways not as good as the older plugins. Flash video uses massive amounts of processor time and slows down everything else on your computer. On the other hand, websites like Flash because it is easy to skin the player to fit in with the look of the site, and it makes downloading the raw video file (slightly) more difficult.

The <video> tag is supposed to replace Flash by linking to video files in the same way that the <img> tag links to images. In practice this is more complicated than it sounds because videos typically require the ability to skip and rewind content. This means that the browser must be prepared to download different parts of the file and cache things carefully to maintain performance. But these problems have long been solved.

I have been waiting for the big sites to make announcements, and today seems to be <video> day all over the internet. Both YouTube and Dailymotion have demo pages up showing <video> content:

YouTube’s HTML5 Page is designed to show how the <video> tag can replicate the functionality of their famous Flash-based player exactly. Unless you looked at the source (or your OS’s process monitor) you would never know you were using a different player.

The Dailymotion HTML5 Demo is even more impressive, using the <video> tag in combination with fancy Javascript to post-process the video and extract frames.

All this is very cool, but the two demos reveal the video tag’s fatal flaw : codecs. When the video tag was proposed, all browsers were supposed to support an unencumbered decoder named Ogg Theora (no seriously, that’s its name). There were just three problems:

  • Ogg Theora’s quality was not as good as other codecs
  • Although Ogg Theora was designed to be free of patent issues, it was felt that it may be a bit of a lightning rod for litigation.
  • Certain companies may have a vested interest in seeing their own codecs used.

So the requirement to support Ogg Theora was dropped. This means that although all HTML5 browsers will support <video>, there is no guarantee that they will be able to play and particular file. Firefox (at least the 3.5 beta) plays Ogg Theora, but Safari plays H.264 (a superior but expensive to license codec) but not vice versa. For instance, one of the demos above plays in Firefox, the other plays in Safari. This puts us in the farcical situation of having no standard way to publish video, exactly where we started.

There is also the small point that the most widely used browser (IE) does not support the video tag, and probably won’t for years. I predict that Flash video will be around for a while yet, and I am not happy about it.

May 092009
 

My previous blog entry on TXTing provoked this response from my friend Lloyd:

…[I] figured out that longest word typed with only the upper letters in the QWERTY keyboard is not only TYPEWRITER but also includes several 3 other words: PERPETUITY, PROPRIETOR and REPERTOIRE. The longest in the middle line is: GALAHADS and nothing from the bottom line but 2 character element symbols like: Zn

Obviously this is some sort of geek challenge. I accept!

Using Python I replicated Lloyd’s results for the top row of the QWERTY keyboard:
PERPETUITY, PROPRIETOR, REPERTOIRE, and TYPEWRITER

Lloyd’s result for the middle row is highly suspect – GALAHADS is the plural of a proper noun. www.thefreedictionary.com does cite a couple of references, but it certainly isn’t in the dictionary I am using. My results are:
ALFALFA and HALALAS (a unit of currency in Saudi Arabia)

There is nothing of note on the vowel-forsaken bottom row.

The longest words that can be typed using only your left hand are:
AFTEREFFECTS, DESEGREGATED, DESEGREGATES, RESEGREGATED, RESEGREGATES, REVERBERATED, REVERBERATES, and STEWARDESSES

For the right hand I get:
HYPOLIMNION (the bottom layer of water in a deep lake)

It seems that Lloyd and I are not the only ones to try this experiment, Wikipedia has completely different (and even more obscure) words listed.

Apr 222009
 

phoneThe question came up at work: what is the longest English word you can TXT using only a single key on your phone assuming no fancy predictive text?

Using a list of my favorite 147948 words (the same dictionary used in WordMap) and a few lines of python the answer is easy to find.

The longest word that can be typed with a single key is “deeded“.

Awesomely, second place is a tie between “abaca” (a species of banana) and “effed” which is not actually in any reputable dictionary but damn well should be.

There are nine 4 letter words: “tutu“, “noon“, “moon“, “mono“, “high“, “feed“, “deed“, “baba“, and “abba“.

Remember, knowledge is power.

Mar 262009
 

I have been quietly impressed with the progress web browsers have been making in recent years towards the goal of supporting a wide variety of applications. The promise of web-apps rivaling traditional desktop applications seems within reach after nigh-15 years of ballyhoo. Most recent browsers have extremely fast Javascript support and highly optimized DOMs, allowing a good level of interaction.

Of course, there a times when moving <div>s around just doesn’t cut the mustard. The canvas tag is not well used but is nothing less than a surface you can draw on using Javascript. It supports all the normal primitives (lines, arcs, fills, etc) and allows (indirect) access to the pixel data. While some people (eg: Project Bespin) are using the canvas tag in to offer extended functionality, I am busy fooling around.

Check out the fruit of my labour – Sketch This Page!.

It’s a Javascript bookmarklet that replaces each <img> element in a page with a same sized <canvas>. It works by copying the image to a temporary canvas, extracting the pixel data for some hacky post-processing, and then blatting the pixel-data onto the final canvas. The Javascript could certainly be better, but it works well enough and I am impressed with the speed.

The biggest flaw is that browsers will not allow Javascript to access the pixel data of images that are loaded from a different domain than the main page. This is a great idea from a security standpoint, but it does limit the usefulness of the bookmarklet. It would be great if Sketch This Page! worked on sites like Flickr, but sadly it is not to be.

For those interested, here is the function that actually dithers the image. I was going for a hatched look with the diagonal lines.

function generateBWDitherImage( src, dst )
{
   var srcContext = src.getContext(“2d”);
   var dstContext = dst.getContext(“2d”);

   var srcImageData = srcContext.getImageData(0, 0, src.width, src.height);
   var dstImageData = dstContext.getImageData(0, 0, dst.width, dst.height);
   
   for (var y = 0; y < dstImageData.height; ++y)
   {
      for (var x = 0; x < dstImageData.width; ++x)
      {
         var index = (dstImageData.width * 4) * y + (x * 4);
         var g = (0.30 * srcImageData.data[index]) +
             (0.59 * srcImageData.data[index+1]) +
             (0.11 * srcImageData.data[index+2]);
         if (g > 200)
         {
            g = 255;
         }
         else if (g > 150)
         {
            if (((y % 6) – x % 6) == 0)
               g = 0;
            else
               g = 255;
         }
         else if (g > 75)
         {
            if (((y % 4) – x % 4) == 0)
               g = 0;
            else
               g = 255;
         }
         else
            g = 0;
         dstImageData.data[index] = g;
         dstImageData.data[index+1] = g;
         dstImageData.data[index+2] = g;
         dstImageData.data[index+3] = 255;
      }
   }

   dstContext.putImageData( dstImageData, 0, 0 );
}

Mar 192009
 

I have quite a lot of books. I am not a book hoarder, I quite often do purges of books I don’t intend to read again, but my bookcases are always overflowing. I have tried various methods of keeping track of what I have read, but nothing really seemed that useful.

A friend at work just hipped me to LibraryThing, a website that seems tailor made for people like me. It is a little like a book-oriented facebook – you join and set up a profile (here is mine) and then start adding books. Books you have added can be given ratings and keywords, you can even write reviews if you are really keen. Once you have registered a few books, LibraryThing starts recommending other books you might like.

The website works pretty well for something claiming to be a beta. It is very text-heavy, but I don’t think that will be a problem for its target audience. The one thing that could be smoother is the interface for actually adding books – at the moment it is a bit of a pain to add multiple books by the same author, even if they appear together in the search.

In true Web2.0 fashion, LibraryThing offers all sorts of RSS feeds and blog widgets to publish data to other sites. As an experiment, I have added the LibraryThing widget to my blog theme. You should be able to see a random selection of books I have read to the right. I removed this, unfortunately it doesn’t work very well with my theme.

Mar 152009
 

The standard C++ iostreams library is very good (well, some would say sort-of good) at reading and writing a file’s contents, but it does so in such a way as to completely ignore file names. I am sure there was a good reason for this omission, but whatever it was is long out of date. There isn’t even a standard way to iterate through a directory, for God’s sake! You end up either falling back to the C standard library (ick) or using operating specific APIs just to find out how big a file is.
Continue reading »

Mar 132009
 

Apple has a new iPod out and that means a new version of iTunes. Along with support for the new device, there are a couple of interesting new features.

The first is autofill, a feature that I have been waiting for since I a got my first iPod. Up until now there has been no way to tell iTunes to simply fill up an iPod with music; you had to much around creating smart playlists and manually juggle how much space each one took up. Now you can just let iTunes fill the iPod from a playlist. It still isn’t as flexible as I would like (if I want to fill my iPod with 30% Scandinavian Death Metal, 40% Classical and the rest with 80s cartoon theme songs I see no reason why iTunes can’t accommodate me), but we now have the option.

iTune DJ Options Dialog

The second feature, iTunes DJ is an overhaul of the old Party Mix feature and is potentially awesome. Like Party Mix, it is basically shuffle on steroids, you select a playlist for your party and iTunes plays the songs. The interesting part is that it integrates in with the Remote iPhone/iPod Touch app. The allows you to mess about with the playlist from your portable device while your laptop is sitting on top of the stereo pumping out your cool tunes.

Even better, your guests can suggest upcoming songs and vote on what they want to hear next from their mobile devices. Luckily your guests can’t change the currently playing song, but everyone gets to have their say.

This will make iPhone/iPod Touch owners even more insufferable at parties, but frankly none of us care what you think. Count yourself lucky that we let you hang out with us in the first place.

Feb 232009
 

Nixon meets Robocop

I mentioned this picture once before, but I thought it deserved another outing. The reasons are clear:

  • It contains Robocop
  • It contain Richard Nixon
  • It contains Richard Nixon meeting Robocop
  • Richard Nixon looks amazingly happy
  • Robocop looks a little perturbed
  • The logo behind them is for The Boy Scouts of AmericaBoys Clubs of America

While you are enjoying the image, I hope you realize that somebody back in 1988 ruined their health smoking the amount of crack required to dream up and organize a meeting between disgraced former president and the star of an R rated film at a children’s event.

Feb 152009
 

A former colleage of mine (Hi Nigel!) frequently wore the greatest geek tee-shirt I have ever seen to work. Ineptly reproduced here, it summarizes the realities of software development – when deciding what to implement technical considerations are often overruled by more prosaic influences.
9-layer-osi

Take this comment by another old colleage. It is a example of how a lot of companies fail to exploit the huge amount of well-tested code available for reuse. There are lots of reasons why a company might ban boost, in my opinion none of them are that compelling.

The main reason cited is the fear of legal retribution (before continuing, I should point out that I am not a lawyer and the following is not legal advice.)

More than one company has been stung by employees including code they do not own into a commercial product, even accidental violations can attract huge penalties with big companies being particularly at risk. This has resulted in a climate where a company will pass every decision on third-party libraries through their lawyers. Lawyers by nature are cautious, they live in a world of contracts, indemnities and assigned liabilities. The default answer is almost always going to be “no” unless there is a contract to sign and someone to blame if it goes pear-shaped.
Continue reading »

Feb 092009
 

Living on a spherical planet can sometimes be a real pain in the neck. It makes what should be a simple concept, Time, inordinately complex. Timezones, daylight savings, leap years (and worse: leap seconds) all conspire to destroy any simple abstraction. So boost provides a complex one.

First up is the gregorian::date class, which specifies a day in the gregorian calendar (sorry fans of the French Revolutionary Calendar, boost::date_time is not for you). Along with normal days, gregorian::date supports positive/negative infinite dates as well as a special not_a_date_time value that make certain algorithms very easy.

A closely related type is gregorian::days, which represents duration. Durations can be freely added or taken away from dates to create new dates. Special classes for longer units also exist: gregorian::weeks, gregorian::months, and gregorian::years come in very handy. gregorian::months and gregorian::years even have special handling to ensure that dates “snap” to the end of the month during calculations.

gregorian::date leapYearMonth( 2008, Feb, 29 );
gregorian::months oneMonth(1);
gregorian::date endOfMarch = leapYearMonth + oneMonth;
// endOfMarch == 31/3/2008, not 29/3/2008

gregorian::date_period represents a fixed period between two dates, and has the methods you would expect for determining if a date exists within a period or two periods overlap. Because the date class can represent abstract concepts like dates infinity days into the future or past, date_periods can represent segments of time without fixed ends.

gregorian::date_period untilFurtherNotice( gregorian::day_clock::local_day(),
                                           gregorian::pos_infin );

Date Iterators and Generators are both very cool concepts. Iterators produce a series of dates that are all some duration (ie: 1 month) apart. Generators provide even more complex factories for producing non-uniform dates such a “the last monday in January” for a given year.

Times are just dates with an offset into the specified day. In boost::date_time this is handled by the posix_time::ptime class. Like date, ptime can represent positive and negitive infinity as well as not_a_date_time giving great flexibility. Also like gregorian::date there are time_duration, time_period, and time_iterator classes which serve the same purpose.

I haven’t even mentioned the most useful part of boost::date_time yet – a full set of streaming operators and conversions to and from standard string formats. If for some reason the standard input/output formats aren’t enough it is possible to imbue a stream with a custom date/time facet for that fancy touch of class.

Aside from strings, dates and times are probably the most common data-types that must be represented in programs dealing with human affairs. It is a pleasure to finally have a library that is up to the task.

Feb 082009
 

A while ago I created a font of my handwriting using a for-pay font-making website. For various reasons I was never terribly happy with the results, although I thought the small amount of money I was changed was a fair price. I kept using the font, waiting for something better.

That something better is YourFonts, a new font-making website that is free. An added bonus is that it does a much better job of creating a font than the other service did, with a much fuller range of characters and proper spline-based outlines.

If you are using a browser that supports @font-face (Safari or Firefox betas) then you are looking at the result – I think it is an improvement, if not a great leap forward for typography.

If you are planning to use YourFonts, or a similar service I have some hints.
Continue reading »

Jan 192009
 

One of the many, many legitimate criticisms that could be leveled at C++ is that string handling is abysmal. Sure std::string can hold some chars for you, but there is a distinct lack of utility functions to actually do anything with those characters. Enter the Boost String Algorithm library, or string_algo to its many friends.

String_algo contains all those fiddly little functions that you write yourself to process text, as well as some clever extensions. The simple stuff is very simple:

string mixedCase = “Hello there”;
to_upper(mixedCase);

string allLower = to_lower_copy(mixedCase);
// mixedCase == “HELLO THERE”
// allLower == “hello there”

string weirdFormat = ” .;text;;;;.. “;
trim(weirdFormat);

// remove punctuation with a predicate
trim_if(weirdFormat, is_punct());
// weirdFormat == “text”

The is_punct() function returns a predicate – string_algo defines a bunch of useful predicates so you will rarely have to roll your own. Not shown in the above is the ability to pass a std::locale to handle strings in other languages.

There is the full compliment of find, replace, and erase substring options:

string statement = “I like cheese, cheese, and cheese”;
replace_nth( statement, “cheese”, -2, “bacon” );
replace_last( statement, “cheese”, “eggs” );
erase_first( statement, “cheese” );
erase_all( statement, “,” );

(the -2 parameter for replace_nth means “replace the 2nd from last occurance” – very useful)

And check this out:

vector words;
string anthem = “God of nations! at Thy feet\n”
                ”In the bonds of love we meet,”;
split( words, anthem, is_any_of(” \n!,”) );

I haven’t even mentioned the ability to do fancy things with regular expression and the concept of find iterators that advance over the substrings that match. Also, the library is generic enough to work with any container that looks vaguely like a sequence of characters, not just std::string.

String_algo is replacing vast numbers of little hacked-together functions in my code. If nothing else it will reduce the temptation to use the God-forsaken CString classes.