Source Code That Allegedly Broke the Microsoft Zune

Thanks to Lawrence, Ryan, JSTN.

while (days > 365) {
    if (IsLeapYear(year)) {
        if (days > 366) {
            days -= 366;
            year += 1;
        }
    } else {
        days -= 365;
        year += 1;
    }
}

For non-programmers out there, this is what we like to call in technical terms “an infinite loop”. This code block will never finish running because on Day 366, the loop keeps checking to see if the day is greater than 365 (it is), and then checks to see if it’s a Leap Year (it is), and then checks to see if it is greater than 366 (it isn’t). So it does nothing, and then starts all over.

Perfect way to lock up your Zune every four years on the last day of the leap year.

Not sure if this is the actual code snippet or not, but a fun exercise. I could actually see this being on an introduction to programming test at some point.

My favorite quote about this fiasco (from the San Jose Mercury News):

“I’ve never heard of a consumer electronic device fail en masse like this,” said Matt Rosoff, an analyst with Directions on Microsoft, a Seattle-based research firm that focuses on the software giant.

Does anyone doubt that “Microsoft Zune” has become the “Ford Pinto” of consumer electronics?

New Dutch Architecture Five (5) Euro Coin, Programmed in Python

Yes, I said Python.

First, special hat tip to Mario Sundar for finding this lead.  Mario is not a coin collector, but he reads my blog often enough to know that I have a special interest in coins.  This one is a beauty, since it combines creative visualization with a unique engineering tale.

Here is the coin design:

dutch_coin_design

Here is a brief description, from the Dutch Mint website, on the coin design:

A new 5 euro commemorative coin pays tribute to the history of Dutch architecture. Both our historical architecture as well as our innovative conceptual architecture and modern design are popular across the globe.

The Architecture five-euro coin was designed by artist Stani Michiels (b. 1973). The design on the obverse of the coin pays tribute to the history of Dutch architecture, with the portrait of Queen Beatrix being distinctively constructed using the names of important architects from Dutch history. The artist used the internet as a popularity-meter to determine the names’ order of appearance.

The reverse of the Architecture five-euro coin draws attention to the striking fact that many Dutch architects have also included publishing books on architecture in their professional activities. To illustrate this phenomenon, recent books on architecture rise up from the sides of the coin like buildings. Through their careful placement they combine to outline the Netherlands, while birds’ silhouettes suggest the capitals of all the provinces.

This blog post, however, from the designer, is where the real beauty lies.  It’s too long to reproduce here, but it goes into significant depth about the design inspiration, concepts, and visualization at work.  If you have a background in design, you will appreciate it.

Here is the summary from the post, and I think you’ll see why this contest winner gets substantial geek cred, as he goes into detail about the technology used in the coin design:

The whole design was done for 100% with free software. The biggest part consists of custom software in Python, of course within the SPE editor. For the visual power I used PIL and pyCairo. From time to time also Gimp, Inkscape and Phatch helped quite a bit. All the developing and processing was done on GNU/Linux machines which were running Ubuntu/Debian. In the end I had to collaborate closely on location together with the technicians of the Royal Dutch Mint (coin factory). So all the last bits were done on my Asus Eee PC. (I am still wondering why Asus doesn’t offer Ubuntu on its netbooks.) The Eee laptop took a bit longer (30 seconds instead of 3 seconds to generate a whole coin), but did the job just fine. For looking up the number of hits on the internet, I rediscovered Yahoo, which provides a much better api for automatic querying than its competitors. Of course the jury judged only the design and not the software used as others used Maya, Illustrator, …

And the winner is…
I am proud to announce that I won the competition! So soon 350.000 Dutch people will use the fruits of free software. I would have loved to release the coin under the GPL, which could maybe solve the financial crisis. However for obvious reasons I was not allowed to do that. There will be also special editions for collectors which can be bought world wide: a massive silver edition for € 30,95 and a massive gold edition for € 194,95. They will be probably sold out quickly as these are real collectors items. The coin is released in all Dutch post offices to the public the same day as the Intrepid Ibex: 30th October 2008.

You can purchase the coin here at the Royal Dutch Mint.  They seem to still have the gold version available, but no sign of the silver version.  Maybe it sold out?  If you find it, please comment here with a link.

Ding Dong, The Apple iPhone NDA is Dead

They’ve been celebrating in the streets all day.  Apple iPhone NDA.  Gone. History. Finito.  Buh-Bye.

Great news and timing for the CS 193P class at Stanford, as this means that forums are likely to emerge quickly for students to engage with, learn from, and help each other.

Here is some text from the Apple Announcement:

We have decided to drop the non-disclosure agreement (NDA) for released iPhone software.

We put the NDA in place because the iPhone OS includes many Apple inventions and innovations that we would like to protect, so that others don’t steal our work. It has happened before. While we have filed for hundreds of patents on iPhone technology, the NDA added yet another level of protection. We put it in place as one more way to help protect the iPhone from being ripped off by others.

However, the NDA has created too much of a burden on developers, authors and others interested in helping further the iPhone’s success, so we are dropping it for released software. Developers will receive a new agreement without an NDA covering released software within a week or so. Please note that unreleased software and features will remain under NDA until they are released.

It’s interesting to note the phrase I bolded above… given Apple’s history with the Mac & Quicktime, it always seemed possible that the iPhone NDA was a reaction to those bitter lessons.

The San Jose Mercury has a funny write up here.  Ars Technica has a more verbose post up as well.

I think we’ll see a measurable increase in the number of applications and the relative quality and pace of innovation from this change.  It was shocking how much this simple legal protection was stifling the growth and development of developers new to the platform.

Stanford CS193P: iPhone Application Programming Launches Tomorrow

A little too busy tonight for a long blog post, but thought I’d share how excited I am to be helping assist the launch of a new course at Stanford this Fall:

CS 193P: iPhone Application Programming

The class website is still a work in progress, but it will come along.  The course is open to Stanford undergrad and graduate students, as well as through the Stanford Center for Professional Development (SCPD) on video.  Enrollment is limited, and my guess is that it will be oversubscribed.

A wonderful opportunity for me to dust off the old Objective-C skills, and help give back to the Stanford community.  Launching new courses is always exciting, and I feel very lucky to be involved with this one in particular.

It might sound crazy to take this on in addition to the full load at both work and at home, but I’m excited to get back involved with teaching, and that’s worth the potential sleep deprivation for the quarter.

SimCity Is Now Open Source as Micropolis

Very cool to see that the original SimCity code has been updated and released under the name Micropolis.

There is coverage on Boing Boing:

 SimCity has just been released as free software under the GPL version 3 license (though the name has been changed to Micropolis for trademark reasons; it was the original working title). This was precipitated by the inclusion of SimCity on the One Laptop Per Child XO machines, but no reason the kids should have all the fun. Can’t wait to see the SimCity hacks that emerge now:


The “MicropolisCore” project includes the latest Micropolis (SimCity) source code, cleaned up and recast into C++ classes, integrated into Python, using the wonderful SWIG interface generator tool. It also includes a Cairo based TileEngine, and a cellular automata machine CellEngine, which are independent but can be plugged together, so the tile engine can display cellular automata cells as well as SimCity tiles, or any other application’s tiles.

There is more detailed coverage about the open source release on this blog.

Back in college, I spent a good chunk of my junior year coding up a fast sprite library for the Mac called “Pixie” which had hand-tuned blitters, layering, and other goodies that seem shockingly dated now in a world of graphics cards, modern rendering pipelines, and modern gaming engines.  Back then, getting 30 frame-per-second animation for about fifty 32×32 animated sprites was considered real bragging rights for a 68K-based Mac.  I can’t tell you how excited back then I would have been to download and play with this.

Check it out, if you are so inclined.

My Mail.app Plugin, v0.1

Major milestone tonight.

Spent two hours after the boys went to bed.  Managed to get swizzling working.  I have now completed a Mail plug-in that when installed…

… drumroll, please …

logs out to console the name & email address of the sender of every email you view in Mail.app.

… let it sink in …

OK, it may not sound significant, but that was 1 of the 7 things I have to get working to have a demo of my new Mail plug-in up and running.  I now have a renewed burst of confidence that this plug-in will indeed get done.
Many thanks to Adam Tow, who responded to my previous blog post, sharing not only tips & sample code, but also a pointer to a regular, weekly coffee night for Cocoa developers in Campbell.  I had forgotten how supportive the Mac development community was… this event looks pretty neat.  Maybe when I get to the really tough stuff, I’ll go.

Mac OS X: Method Swizzling in Cocoa

It took me about 45 minutes, but I finally think I have this figured out:

Method Swizzling in Cocoa

Basically, it’s the missing piece you need to effectively “hijack” an existing function in an existing piece of Mac OS X software.

To do this, you follow a few key steps:

  1. You identify a method of an existing class in an existing piece of software that you want to hijack, let’s call it “foo”
  2. You then write your own implementation of that method in that class, let’s call it “myFoo”
  3. You do what ever you want in myFoo, but then you include a call to myFoo. It looks like infinite recursion, but it’s not.
  4. You do the MethodSwizzle trick, which basically tells the Objective-C runtime to replace all calls to “foo” with “myFoo”, and vice-versa.

End result, every existing call to “foo” now calls “myFoo”, and “myFoo” is no longer infinitely recursive because it’s call to “myFoo” now calls “foo”.

It turns out this type of trickery is essential if you want to write a plug-in for an existing application, like Apple Mail, where there is no pre-defined API, and you want to take over pre-existing actions and add some functionality to them.

My work on an Apple Mail plug-in is painfully slow, but I’m at least a little further along now.