My entry for the JS1k contest is a JavaScript Syntax Highlighter implemented in 1023 bytes of JavaScript – just one byte short of the contest limit. I also submitted an uncompressed and somewhat more readable version of the source.
The highlighter recognizes keywords, strings, comments (single and multi line), numbers, regexp and punctuations. And as far as I can tell, it works perfectly. It handles escaped characters as well as /* "strings" in comments */ and "comments // in strings" correctly.
I really doubt that I'm going to win anything with this though, as there are already many other unbelievably awesome demos.
Update: Stripped a few more bytes (1005 now) and formatted the source so it's actually readable. I also made the script a Quine – a program that prints its own source. You can find the new version here.
How do you display a list with a huge number of items? Easy: just paginate – split your list into several pages and let the user click through them one by one. Google does it with their search results, every forum software in existence splits a thread after N posts, my Blog only shows 8 entries at most. It's a solved problem.
Some years ago Microsoft had a different idea with MSN Search (now Bing): Infinite Scroll. If you do an image search on Bing and scroll down far enough, more results will be loaded on the fly and appended to the current page. There's no need to click a Next Page link. I don't know if they were the first to do it, but they certainly were the first I remember.
Today, many sites are using Infinite Scroll or the slightly less ambitious Load More button. And it constantly annoys me. It's not so much that most implementations are done very carelessly, but that the idea is inherently broken and really can't be done right.
Take Twitter for example. Say I'm writing a Blog post about how John Gruber was all the rage about X a few days ago. Naturally, I want to have a link to his tweets from said day in my post, so I visit twitter.com/gruber, click the more button two or three times, till I see those tweets and… now what? How do I link to this page? Do I have to link directly to twitter.com/gruber and tell my readers to click more a couple of times? How often? Well, it of course depends on how chatty he's been since I posted my story.
You might say that this issue could be easily fixed by utilizing the Fragment Part of the URL. So after I click more the URL would change to twitter.com/gruber#20, twitter.com/gruber#40, twitter.com/gruber#60 and so on (or better yet, counting from the first tweet). Now, what if I'd want to link to Grubers first 20 tweets? The URL would be twitter.com/gruber#8900 and the page would load nearly 9000 tweets? I don't think that's a good idea.
The non-link-ability is not the only problem of this technique: How do I jump to the end of the list? Or generally, how do I jump to a specific item (e.g. the first unread post in a forum thread)? What if the page becomes so long that my browser struggles to keep up?
It ultimately boils down to what we gain by using a Load More button instead of Next Page. And the only answer I can think of, is a few milliseconds of time I'd otherwise would've spent waiting for a whole new page to load. I also believe that appending items to a page is even more confusing for the user than going to a new page. After you've clicked more a few times, the list becomes so long that you easily get lost in it.
Pagination might not be as cool as all the AJAX stuff, but for navigating a list of “infinite” size I really can't think of a better approach. It doesn't have to be the old school pagination with a Next Page link though – you could build something that utilizes AJAX, caches the next page in advance, makes use of your mouse' scroll wheel etc. Ultimately it just has to be something that says “you are viewing items 340–380 of 920”: Providing a fixed sized, moving window into a set of items, instead of the fixed position, growing window that is Load More.
Songfever, at it's heart, is a tangible front-end for iTunes. Album covers are projected onto four physical objects standing on a shelf. With a scroll wheel, attached to the shelf, you can scroll through your music library in a Cover Flow like fashion. The goal was to reintroduce the aesthetic quality of a physical music collection (CDs, LPs), while maintaining the comfort of a digital one.

Each of the four covers are tracked by a webcam mounted above the shelf. Their positions are translated in software in the same way the projector located relative to the webcam in the real world. When rendered in a 3D OpenGL view and projected back onto the shelf, the album covers line up with the physical objects again. Approximately, that is.
Songfever was our main project in the 4th semester for “Digital Media” at the Hochschule Darmstadt. I was responsible for the programming; the UVC Camera Control I posted some month ago, was a small part of it.
Visit the Songfever Website for some more photos and videos.
For the last ten years or so, I used to turn on my PC when I came home from school or work and shut it down again right before I went to bed. So most of the time when my PC is running, I'm awake. I've also been idling in IRC for as long as I had Internet – when my PC is running, so is my IRC client.
I still have all my IRC logs since 2001 lying on my HDD. The log format of mIRC changed slightly over the years, but it's all easily parsable with some basic Regexp. I quickly wrote a PHP script that extracts the Session Start and Sessions Close markers and timestamps from these logs and transfers them into an image.
Open image in a new window
As you can see, I tend to stay up late. I also tend to go into a free-running sleep mode when I don't have to get up early every morning. At May 2004, after my A-Level exams and before my apprenticeship started, I “rotated” my sleep cycle three times. This has been even more extreme for the last two years, where we only had few lectures in university but instead worked on a lot of projects. I should really get one of these daylight lamps.
There's so much more interesting information hidden in these IRC logs. Maybe I can bring myself to parse and import all of them into a database, so I can run some simple queries on them. Maybe I can even find my pre-2001 IRC logs on some backup CDs.
More than two years ago, I created a Flash Animation for my university class. Today, I converted the whole thing to plain Javascript and HTML5, using the new <canvas> tag to draw and the <audio> tag for music playback. It now runs smoother than it ever did in Flash.
Without further ado: Venetianization / HTML5 Animation
Some technical notes: For the original Flash Animation I used ActionScript 3 and created my own classes. Javascript doesn't have classes per se, but you can build something that looks and feels exactly like it. MooTools did an awesome job at that. Converting my ActionScript classes to MooTools classes was a no-brainer.
I was able to reuse most of the code with some basic search and replace throughout the source. One thing however, that is (to date) completely missing in Javascript, is the ability to analyze the current sound spectrum of an audio file. I ended up extracting the raw values of the spectrum with a sampling rate of 15Hz (which is enough for an animation that initially ran at 30Hz) and put them in a large array in one of the source files.
The thing that annoyed me the most however, is that I now have the music in two different formats: OGG Vorbis for Opera, Firefox and Chrome, and MP3 for Safari. I totally understand that Firefox, being open source and all, can't include MP3 support. What I don't get, is that Apple doesn't support OGG Vorbis – an audio format that is clearly superior to MP3 – instead, they choose to sit on their high horse and twiddle their thumbs. This is exactly the behavior that made Internet Explorer a laughable side note.
Side note: Of course none of this works in any version of Internet Explorer.
Google introduced Chrome Frame today, which is essentially a plugin for Internet Explorer to use Chrome/Webkit as it's rendering engine. This at first may seem like one of Google's Aprils Fool's jokes or an attempt to make Microsoft even more embarrassed of IE. However, when looked at closely, the Idea to bring Chrome to IE is very clever and might actually work!
The problem is clear: While Microsoft certainly fixed many issues of the now infamous IE 6 in their newer versions, IE 8 still has many many problems and is far behind in terms of standard compatibility, features and speed. This has hindered many sites from using new technologies and ideas and oftentimes forces developers to backpedal in order to still support IE. So how do we get people to switch to a different browser?
Imagine you're visiting a website and are greeted with a message like “Your browser is not supported by this website. Please download one of the following browsers...”. Would you do it?
For the average user, the answer is of course no. There are way to many hurdles to overcome. Many people don't even know what a browser is. For them, IE is the Internet. They won't understand why they need to install a new software and they won't know what to do if they wanted to switch. Even if a user exactly knows what a browser is and how to install software, he'd still have to trust the browser vendor that this new software won't do any harm to his PC and he'd also have to invest some time to get familiar with it. It's just not worth the effort.
Now imagine you're visiting this website and you get the message “You need the plugin XYZ to view this site”. Imagine this plugin was created by Google – a company you know and can be sure of that they won't harm your PC. Installation of this plugin is just one click away. You don't have to download or install anything manually and your browser will look and behave exactly the way it used to.
Google Chrome Frame is just that. It's only a plugin, but for web developers it has the same benefits as if the user switched to another browser. If you're working on a high-end website that you can't possibly get working in IE (like Google itself does with Wave), or that just would work better with a standard compliant rendering engine, then Chrome Frame seems like a very good answer.
Richard Dawkins once urged us to not just be atheist, but militant atheists. I don't want to talk about religion here – after all, everyone already knows that religion is stupid. No, what I want to talk about is the Colemak keyboard layout. Today, I'm a militant Colemak user.
Two years ago I asked myself if there isn't any better keyboard layout for programming than the German keyboard layout. Many keys that are essential for programmers, like curly braces and square brackets, are only reachable through extensive use of the ALT key on the German QWERTZ. This is hardly ideal and makes QWERTZ much less usable for programming than the English QWERTY.
I did consider switching to QWERTY for some time. Sure, I'd miss the German Umlauts (ä, ü, ö) but that was a sacrifice I was willing to make. I asked a German programming board how they are dealing with the cumbersome QWERTZ layout – many of them are using the English QWERTY layout as their default and are happy with it. They also mentioned Dvorak, which I largely ignored, as it seemed incredibly hard to learn and had no apparent benefit.
However, I stumbled over a new, totally different, keyboard layout that sounded promising. It's name: Colemak. Colemak is designed to be efficient and ergonomic. You can type whole sentences with it, without your hands ever leaving the home row. Yet, it is fairly easy to learn. The keys for the widely used shortcuts for undo cut, copy and paste all stay at the same place and the layout of all special characters is identical to the English QWERTY. Furthermore, I can type all the German language specific characters with Colemak and it also adds many special characters like the ellipses, en- and em dashes, typographic quotation marks and many, many more. These would otherwise only be reachable with complicated ALT combinations on Windows (e.g. ALT+0151 for the em dash).
I've been using Colemak for almost two years now, and I can't imagine switching back to QWERTZ. Typing with Colemak feels so much more fluent than it ever did with QWERTZ, especially when programming. I can now keep my 10 fingers on the keyboard at all times, as all the special characters are easy to reach. I don't mind the somewhat more complicated to type Umlauts since I don't write that much German anyway.
Another nice side effect of having Colemak installed on my Windows Desktop PC and my Macbook Air is that it flattens out the differences between their QWERTZ layouts – that's right, Windows and Mac OS have a slightly different Keyboard layout for the German language. Especially annoying is the different positioning of the curly braces, square brackets, the pipe and the at sign – characters you'll need frequently when programming. With Colemak the layout is exactly the same on all systems.
Of course, while the layout itself is close to perfect, switching to Colemak also has it's downsides. For one, if someone wants to use your PC/Mac she'd first have to switch back to QWERTZ or QWERTY. This is not a problem at all on Mac OS, where you can switch the layout with two clicks. On windows however, you can only switch the layout on a per application level, meaning that you'd have to switch the layout for each application that you want to use. Whoever had this idea at Microsoft needs to be slapped with a large trout.
I can still type on QWERTZ/QWERTY, albeit a bit slower than I used to. The one thing I'm incredibly lost at, is when I want to type program code on a friends MacBook since I never learned the Mac OS specific QWERTZ layout. However, this is a problem I'd also have if I'd still use the Windows specific QWERTZ.
If you're already using the English QWERTY layout, there's probably not that much benefit in switching to Colemak. QWERTY is already nice enough for programming and the layout is identical on Mac and PC. For everyone else who is programing a lot on the German, French, Czech or Swedish layout, Colemak sure is a very nice alternative.
For a recent computer vision project I needed to pull images out of a Logitech QuickCam 9000 and track some markers with the help of the ARToolKitPlus library. I connected the camera to my Mac and was quite surprised to see that it just works. There was no need to install any drivers. As I learned later, that's because the QuickCam 9000 is a UVC webcam for which Mac OS X 10.4.9 already provides a driver. I was able to get to the raw camera images through the QTKit Framework in no time.
However, the QuickCam 9000 has its auto exposure enabled by default, which is absolutely deadly for stable tracking results. I thought I could just turn the auto exposure off and set it to a fixed value through some QTKit API – but no, there's no way to change the exposure of a UVC camera with QTKit. In fact, there's no way to change any parameters of your camera. No exposure values, no white balance, no gain, nothing. Apple just implemented the bare minimum in its UVC driver and the QTkit Framework.
Well, maybe I could get to these parameters through the older Sequence Grabber Framework then? After all, there's a VDIIDCSetFeatures function and a vdIIDCFeatureExposure key! But nope, as the name implies, this stuff only works for IIDC cameras. What's an IIDC camera? Wil Shipley asked the same questions almost 3 years ago - even back then, IIDC cameras were pretty much deprecated. Still, these cameras are the only devices that Apple provides an API for, if you want to change some esoteric parameters no one would ever need to change, like oh, the exposure time or white balance temperature for instance.
Apple is aware of the problem but hasn't done anything to solve it. And Logitech apparently doesn't see the need to provide a Mac driver for their cameras, since Mac OS X already ships with one. Great.
But wait, UVC is a standard, right? USB.org provides a documentation for all device classes, and the Video Class is no exception. So, I poked around in the documentation for a while, read some Linux UVC driver sourcecode and used Apple's USB Prober to see what's going on. After some more hours of playing around with the Kernel Framework's USB API, I was finally able to control some of the QuickCam's settings!
Read complete post »