Stuff from my Old Hard Drive

I don’t usually keep a lot of files around. When I get a new computer I don’t tend to copy all my documents across – anything I haven’t looked at for a couple of months is probably not worth the fraction of a millimetre it takes up on the platter. On the other hand, some things I can never bring myself to delete. Here is something I rediscovered the other day:

This is one of the first MODs I wrote back on the Amiga. I never had a sampler or a very large collection of instruments, but I loved mucking around with MED trying to get a pleasant sound out of the 4 channel 8-bit sound. It is often said that there is a lot of crossover between programming and music, and the soundtracker clones of the 90s made that explicit which is possibly why I enjoyed it so much. Now days I can fire up GarageBand any time I want with any number of sampled instruments. I could say that I regret not having the time to produce music as an adult but the truth is that the inspiration isn’t there any more – my interests have moved in other directions.

Although none of my MODs ever sounded anything like as good as the music from the games and demos of the time, I am still pretty pleased with this one. It must date from form 6 (I was 16) which makes it vintage 1991. Listen to the sound of 20 years ago…

Jungle Drums MP3
Jungle Drums OGG

A Better Boost Book

Boost is a excellent resource for C++ programming, but suffers from inconsistent documentation and a daunting array of sub-projects. Trying to make sense of it all is a fairly serious undertaking. I tried to get my head around it by writing my occasional series of boost blog posts, but now I see that somebody has done a much better job.

The Boost C++ Libraries is a free book that clearly explains some of the more generally useful boost libraries, with lots of useful examples. It even covers advanced libraries like ASIO in an approachable way. I highly recommended bookmarking it if you do any C++ programming.

UIButton.titleLabel is not as useful as it looks

I have been doing some iPhone development lately. Nothing too amazing, just some test apps to get a feel for the system. Now, some people will tell you that Cocoa Touch is an API sent from God and frankly it is pretty good (especially given what passes for UI on other embedded devices), but that doesn’t mean it doesn’t have some annoyances.

Here is something that tripped me up for a while. The UIButton class has a property called titleLabel which (obviously) returns the UILabel that is used to display the text of the button. You can use this property to modify the parameters of the label, like so:

1
2
3
m_addButton.titleLabel.font = [UIFont systemFontOfSize: 7];
m_addButton.titleLabel.textColor = [UIColor blackColor];		 
m_addButton.titleLabel.textAlignment = UITextAlignmentRight;

What you can’t do is this:

1
m_addButton.titleLabel.text = @"Add Stuff";

Although nothing I have found in the documentation says so, the text of the button cannot be set from the titleLabel property. What you have to do is this:

1
[m_addButton setTitle:@"Add Stuff" forState: UIControlStateNormal];

Setting the title this way works, and has the advantage that you can specify different text for different states:

1
2
[m_addButton setTitle:@"Add Stuff" forState: UIControlStateNormal];
[m_addButton setTitle:@"Add Stuff (not now)" forState: UIControlStateDisabled];

This is perhaps not that interesting for text titles, but is an excellent way to control the image the button shows based on whether the button is enabled, highlighted, and/or selected.

How to change the dictionary in MacOSX

I love MacOSX, and one of the best features is the almost ubiquitous built-in dictionary. So it is surprising that I after 3 years I have only just now discovered how to switch the dictionary from the default American English to British spellings. For some reason this is not part of the normal System Preferences pane, nor does setting your region or system language have any effect on spelling. I knew there had to be a way, but could never find the trick until today.

In case anyone else is having the same problem, here is what you have to do:

  1. Open an application that supports the in-built dictionary (pretty much anything except for Firefox). If in doubt use TextEdit.
  2. Right click on a text input area and select Spelling and Grammar -> Show Spelling and Grammar from the menu. Alternatively, the same menu option is available from the Edit menu.
  3. Select the dictionary you want from panel that pops up. Although the panel looks like part of the application you are using changes to the settings here apply across the entire OS.
  4. Enjoy the sensation of spelling words with lots of silent letters just like Queen Elizabeth II and God.

spelling

A game rated arrrr! Monkey Island Returns (updated)

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.

Longest Word You Can Type (QWERTY Edition)

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.

The C++ Boost Libraries Part 5 – boost::filesystem

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

The Boost C++ Libraries Intermission – Getting Boost Used

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

The Boost C++ Libraries Part 4 – boost::date_time

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.

The C++ Boost Libraries (Part 1 – Introduction)

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

Replacing a MacBook Hard Drive

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.

Chrome

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.