Saturday, February 9, 2008

I ate a skunk for lunch

Faithful xkcd readers will know about the sudden change in Google results caused by the Dangers comic. The number of hits for "died in a blogging accident" has since risen from 2 to over 32,000.

The results were acquired simply by entering the corresponding Google query. This has one disadvantage: you have to know in advance which type of accident you're looking for.

I wrote a little Perl script to overcome this. It Googles for "died in a" "accident" and parses the first 1000 results (unfortunately, Google refuses to give more than that). The number of occurrences of “died in a _ accident”, with exactly one word in place of the _, is counted, and the results are charted using the Google Chart API.

So now we can see which accidents are really most common:

It appears that blogging is far more dangerous than I always thought!

The number of words we want in the results can be modified (e.g. “give me all results consisting of one, two or three words”), and they do not have to be sandwiched between two known phrases, but can also come before or after a certain phrase, as in “_ is an idiot” (which obviously requires that we specify a fixed number of words to take). There is also an ignore list to get rid of meaningless matches like “he” and “bush”.

The script can also tell us what people eat:

Fair enough. But:

A rat? A skunk? A hippopotamus?!

Unfortunately the script does not work as well as I hoped. The results often do contain both parts of the query, but on different parts of the page. These hits get in the way of the useful results, and because we're limited to 1000 results we cannot dig any deeper to find them.

The script is full of known and unknown bugs, not in the least because it's my first nontrivial Perl script, but I put it online for your enjoyment anyway. It is called accident.pl and requires Perl (obviously), WWW::Mechanize and URI. Run it without arguments to get a brief help text. Let me know what results you come up with!

Friday, February 8, 2008

Add three inches in a week!

For over a year, I've been the happy owner of a Dell 2407WFP 24" widescreen monitor:

Dell 2407WFP

But as of late, there has been a little problem with it:

It's as if there is a strip loose between the backlight and the LCD. Not a big problem, but slightly annoying.

So last Monday I mailed Dell customer support. I got a prompt response, recommending me to try resetting the monitor by holding down the power button for 20 seconds. Tried that; didn't help; mailed back. Tuesday, I got the reply: they were sending a replacement through UPS, to be arriving the next day. Wednesday morning: phone call from UPS. From Lithuania, of all places. Telling me in fairly decent English that the replacement was not in stock, and that I should contact Dell for an alternative, so I mailed them again. On Thursday I got a call from Germany. Broken English, not entirely clear on the purpose of the call, but apparently verifying my address. Oh well.

Now this Friday morning, I woke up to the sound of the doorbell. A man from UPS with a replacement monitor. I was surprised, since I hadn't heard anything from Dell in the meantime. Being careful, I wanted to see the replacement in action before the UPS guy left with my old one. Unpacked the monitor.

Dell 2707WFP

First thing I noticed: brushed metal, not black like my old one. Checked the model number on the back: 2707WFP. — Wait… 27?! And indeed, holding my old panel up against it, the new one was three inches larger. It worked right out of the box and had no dead pixels or other artifacts, so I let the UPS guy take my old screen away (sniff). He didn't even want the booklets or cables or cd-rom, which was lucky for me since I'd have a hell of a time finding all that stuff again.

Thinking that this replacement was too good to be true, I e-mailed Dell once more to verify that it was indeed correct and intended to be permanent. Got a confirmation within the hour.

Now that is what I call Customer Care.

Sunday, December 30, 2007

Visual C++/Studio: Application configuration incorrect?

If you have just written a program in Microsoft Visual C++ or Visual Studio (2005 and above, I believe), try to run it on another machine, and get the error message “This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.” then you want to read on. If you just want to see me rant at Microsoft, read on as well.

The problem is really simple. If you write a C++ program, it links dynamically to the C Runtime Library, or CRT for short. This library contains your printf, your malloc, your strtok, etcetera. The library is contained in the file called MSVCR80.DLL. This file is not by default installed on a Windows system, hence the application cannot run.

The solution? Either install the DLL on the target machine through VCREDIST.EXE (the Visual C++ Redistributable Package), or link to the CRT statically (plug the actual code for the used functions straight into your EXE).

Distributing and installing VCREDIST along with a simple application is a pain in the arse, so I went for the second option: static linking. It's really easy: go to your project's properties, unfold C/C++, click Code Generation, and set the Runtime Library to one of the non-DLL options. That's all there is to it.

Now comes the rant part: how much effort it took me to figure all this out. You have been warned.

  1. “This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.” What kind of error message is that? It's like saying “sorry, your car does not work, because the engine won't start; please buy a new car.”
    In the very least, you could tell me that I'm missing a DLL. Preferably also tell me which particular DLL.
  2. Reinstalling the application, like the error message suggested, did of course not fix my problem. But the message also does not give a hint where to go looking for the error. It took some web searching to figure that out: the Event Log. Itself hidden quite well inside Windows, it told me which particular DLL was missing on the system. The Dependency Walker, that also comes with Visual Studio, told me that MSVCR80.DLL was indeed the culprit.
    The error message should at least point toward the more useful information: “See the Event Log for details.”
  3. I searched around on the web for MSVCR80.DLL and found its purpose. It turned out to be possibly the most basic library any C programmer could wish for. So why the heck is it not installed on any Windows system? It turns out that some older versions of the CRT are installed with Windows, but these are really ancient and buggy, and I honestly wouldn't know how to make Visual Studio link against them.
    So why, in these days of automatically updating systems and always-on internet connections, is this small (612 kB) but very essential DLL not included in service packs, or in Windows Update?
  4. Now, to fix the problem, I had to install the DLL on the target system. Simply dropping it alongside my application didn't work, because nowadays DLLs actually need to be installed. This is because modern DLLs are what Microsoft calls Side-by-side (SxS) Assemblies, which have been introduced in a brave attempt to diminish DLL hell. I don't know the gory details; it's something to do with manifests, and probably lots of candles, pentagrams and holy water as well.
    Anyway, you cannot download the VCREDIST installer straight from the Microsoft website, because there's only an old version there. Or is there? A newer page does give you what you want, and there's a 2008 version too.
  5. Thinking that it must be possible to link statically to the C Runtime Library, I looked into the project options in Visual Studio. I could not find the option there. Not very surprising, considering its name: “Runtime Library.” What runtime library? The Grand Unified DLL of Making Coffee? Or is this just a general option relating to runtime libraries in general? The default value (“Multi-threaded DLL”) seems to suggest this. I dared not touch this option for fear of breaking my application. It's a common problem with Microsoft: they often use a very generic-sounding name for something very specific.
    Had the thing been called “C Runtime Library linkage” instead, I would immediately have grasped its meaning.

On a not completely unrelated note, I'm pleased to announce that this bug in Taekwindow has finally been resolved.

Sunday, December 16, 2007

My ideal filesystem

I have a file server. It has multiple disks of various sizes. Some are old and likely to fail soon, others are brand new and will hopefully fail less soon. The file server contains nearly half a terabyte of data. Some data are big, others are small. Some are important, others I could do without.

The problem: it takes a lot of manual labour to manage all this. I need to decide which data goes where, keep an eye on the free space of each drive, make sure backups are made regularly, shuffle around data when I add a new disk, etcetera. Highly inconvenient.

The solution: My Ideal Filesystem, MIFS for short. Unlike other filesystems, MIFS is not stored on a single disk (or partition, if you like): it is spread out over multiple partitions. Unlike filesystems on a RAID or LVM array, MIFS actually has knowledge of the underlying structure of its disks (or partitions) and uses this knowledge to its advantage.

MIFS presents itself to the operating system simply as one filesystem. You can therefore mount it at a single mount point. There is only one small extension to the interface that normal filesystems expose to the OS: you can tag a file with a number that indicates the ‘importance’ of the file. This number indicates how bad it is if the file gets lost. So I can tag, for example, a thesis that I'm working on as very important, whereas a television series that I downloaded can easily be downloaded again and is therefore less important. There is also a number which specifies a ‘minimum redundancy’ for the file. If no number is specified, it is inherited from the parent directory.

Additionally, the disks comprising the filesystem each have a tag with their relative reliability, so you can indicate which disks are likely to fail soon. This number might be extracted from the SMART data that the disk itself presents, combined with a database of reliabilities of different disk models, if it is possible to build a database like that.

Now when I write a file to this filesystem, MIFS will decide what to do with it, depending on its importance. When the array is mostly empty, MIFS can afford to write files to each and every of the disks, achieving maximum redundancy and complete recovery even if all disks but one fail. When the array fills up, the files that are less important will be erased from some of the disks to make room for more important files. The ‘minimum redundancy’ tag ensures that my important thesis will always be on at least three of the disks. The filesystem is only full when all files are at their minimum redundancy level.

One could even go a step further, and put some of the disks in a machine across a network or even the internet. That would essentially give you automatic, real-time backups in case one of the machines gets fried along with all of its disks.

MIFS has only one huge drawback: it does not exist. Of course there are many technical difficulties to be overcome when implementing MIFS; I am not blind to that. But I think it should be possbile. Anyone who writes this filesystem will earn my eternal gratitude.

Friday, December 14, 2007

Using MS Word – the right way

It's been quite some time since I last used Microsoft Word for any serious document. Nowadays I mostly use LaTeX. Which of the two is “better” is not a discussion I want to get into: each has its own pros and cons and is suitable for a different purpose.

For those who are for some reason stuck with Word, I've been wanting to write an article on “proper Word usage” which takes much of the pain of the program away. However, I just discovered that this article already exists (and how couldn't it?): Living with Microsoft Word: Tips for survival.

No Word user, frequent or occasional, should be without the knowledge in this article. Spread the word! — Erm… sorry.

Thursday, December 6, 2007

A case against student presentations

For my master's in computing science, I am currently following two courses which largely consist of presentations given by the students themselves. The idea is that students research one topic in-depth, and learn about the other topics from others.

I've attended four such presentations today. One was quite good, one was mediocre and two were downright embarrassing. In view of my past experiences with such presentations, I found this a decent score.

Why doesn't this system work?

Firstly, students often don't know the material well enough. The presentation can then go one of two ways. Either the material that is not understood is skimmed over, or it is left out. If the hard stuff is only skimmed, we see slides with many complicated formulas, algorithms, graphs and numbers, but the presenter hardly touches upon them. Upon asking a question to dig up more information, only stutters come out. Equally bad, if the hard stuff is completely left out, we end up with a presentation so shallow that it is nearly without content. When we ask more detail, it turns out that the presenter knows no more than he told.

Secondly, most people cannot teach. Understandable, because teaching and explaining is hard. Why else would teachers have to go through years of training before they are allowed in front of a full classroom? And even then, most teachers are mediocre. University professors, despite knowing their subject very well, have received hardly any training at all, and are usually worse. Therefore students cannot be expected to be able to explain something properly. Those who can are the exception, not the rule.

It is already hard enough to get complicated material into your own mind. To get it into someone else's is much, much harder. Forcing people to attempt both at the same time is a recipe for failure.

Friday, November 30, 2007

50,000: Better late than never!

Official NaNoWriMo 2007 Winner There. I've done it. I just wrote a 50,000 word novel in one month, as I set out to do. I just typed out the 50,078th word, and made it to the finish line in the nick of time.

I wrote last month that the novel was going to suck. Now, I really don't know anymore. It is so hard to judge a work that you've been working on for hours on nearly every day: you become blind to its flaws. But the story may even not suck as badly as I thought it would.

Although the story is finished, the novel is not done yet. The scenes are written out of order and do not connect logically to each other. There is exactly one scene per chapter, and the chapter heading gives a perfect spoiler of what happens in that scene. Inconsistencies crept in while I changed my mind about how things should work. Things that should have been said only once are said twice, thrice, while things that need to be mentioned remain unwritten. As I wrote in English, which is not my native language, the vocabulary I used is probably limited. And I may even have made an occasional typo. Much work remains.

I hope to get this all fixed up during December. Then, if and only if I'm satisfied, I will print out copies for some friends. Whatever I do with the story afterwards much depends on their reaction. If it's total rubbish I might put it online for free; if it's brilliant I might try to get it published. The truth is probably in between, so neither might happen. We'll see.

NaNo taught me a lot of lessons. I might write more about all that later. I might also write up the “making of” story for posterity and future WriMos. But all that will have to wait. Right now, my arms are starting to complain of RSI again, and I have a much neglected social life to attend to.

But I did it!