TimeSpan.js Version 1.2 released

I've just pushed a new Version of my TimeSpan Library to GitHub. Version 1.2 contains a new "static" constructor TimeSpan.FromDates which takes two dates and returns the difference between them as a TimeSpan. If the second date is earlier than the first date, the TimeSpan will be negative. Pass true as third parameter to force it to be positive.

Usage example:

var date1 = new Date(2010, 3, 1, 10, 10, 5, 0);
var date2 = new Date(2010, 3, 1, 10, 10, 10, 0);
var ts = TimeSpan.FromDates(date2, date1);
var ts2 = TimeSpan.FromDates(date2, date1, true);
alert(ts.totalSeconds()); // -5, because we put the later date first
alert(ts2.totalSeconds()); // 5, because we passed true as third parameter

Running three Monitors off a Radeon 5870 card

Okay, as said last time, I bought a Radeon 5870 card with the desire to drive three monitors. Now, ATI proudly claims that they have three independent display controllers, which is true. And the card has 2x DVI, 1x HDMI and 1x Display Port, so you would expect a setup of 2x DVI and 1x HDMI to work, right?

Wrong. You see, DVI/HDMI and DisplayPort have different Signal Types. DVI and HDMI use TDMS, while Display Port uses a completely different protocol. And guess what? The card only supports up to two TDMS Signals, which means 1x DVI and 1x HDMI or 2x DVI, but not 2x DVI and 1x HDMI as that would require three TDMS outputs.

Now, the solution seems easy, just get one of those cheap $10 DisplayPort > HDMI or DVI adapters, right? Wrong again. Those adapters do not convert the signal, they seem only able to mechanically convert and then require the host to generate a TDMS Signal. You need an "active" Adapter, that is an adapter that actually converts the signal. Those require extra power, usually provided through an USB Port. And they are expensive.

I bought one from Dell (R478G), which set me back a hundred bucks. Other adapters are sold by Sapphire or Accell and possibly others, but they are all around that price range. Sadly, I already had three Monitors at that point, otherwise I would recommend paying the extra money for a DisplayPort Monitor as the Adapter can cause problems (check the reviews) or even considering a second graphics card, which kinda defeats the purpose of getting a Radeon 5xxx in the first place.

Oh well, at least I now finally have three monitors for a 6016 Pixel wide screen...

My Monitors are now armed…

When I bought my PC, I wanted a no-compromise Developer and Gaming workstation. In the past, I worked with 2 Monitors (best optimization ever!), but I found even two monitors too limiting at times, especially if I need Visual Studio, my application, a Web Browser, e-Mail and Twitter clients, some command windows, explorer windows and notepad instances running, not to mention some non-development related apps like iTunes.

So this time, I wanted three monitors. As I wanted to avoid two graphics cards (always gets crowded inside the PC, also as my graphics card needs to be good enough for high-end-gaming I didn't want to run 2 different cards, but also not buy 2 $400+ cards...), I ended up buying a ATI Radeon 5870 which has 2 DVI, 1 HDMI and 1 DisplayPort connector and can drive 3 screens at a time. Well, in theory. I'm going to make another posting, but basically one of the three monitors has to be DisplayPort, 2x DVI and 1xHDMI will not work, and neither will the cheap Adapters - I'm currently waiting for my $100 DP->DVI Adapter to be delivered as I already have 3 Monitors.

But anyway, the problem with 3 big monitors is that they take up an insane amount of space on the desk. I bought a big desk, but still it's too much. I remembered a posting from Jeff Atwood about monitor arms and thought I'd give them a try. I bought an Ergotron LX Dual Side-by-Side Arm (45-218-194) which holds two monitors, as long as they are max. 20 lbs/9.1 kg each (basically everything up to and including 24" - if you weigh, remember to remove the foot before). The two monitors I've connected currently are Acer B233HUbmidhz - 23", 16:9, 2048x1152.

The Ergotron arms are solid metal and certainly make a very sturdy impression. The users manual on the other side is IKEA-quality, that is barely understandable pictures instead of good explanations. Definitely take some time when you install them, it took me a bit more than an hour. The nice thing about the Ergotron arms is that you can either drill through your table or mount it using a clamp - no drilling! But make sure you have some space under your desk - I thought I had enough, but I underestimated the size of the clamp...

Luckily it still fit well enough to hold the screens, phew! It takes a little time adjusting them properly, because of the two parts of the arm (one can be removed) - prepare to move the clamp. As said, take your time. Oh, and another hint: There are two plastic caps that you put on the holder after installation to make it look nice. These caps are hard to remove, so installing them should be the very last thing you do, after mounting the monitors and adjusting them completely. Also, another important hint: You can (and need) adjust the strength of the spring that holds the monitor. Do not wonder if you just mounted your monitor and it's weight drags the arm down - do not write an angry review on Amazon that makes you look bad, but look at the (as said, horrible) manual again (Step 7a) and tighten the screw. Last hint: Make sure your cables are long enough.

I'm definitely happy with it, removing the feet of the monitors makes the desk much more tidy in my opinion. For my third Monitor, I'm looking at the normal LX Arm.

Lawyer von Gravenreuth commits suicide…

Just got the news that Günter Freiherr von Gravenreuth commited suicide last night. Non-German readers may not know him, so allow me to quickly give a breakdown why he was an important figure in the German computer "scene".

During the 1980s, he put up advertisements in newspapers, posing as 15 year old Tanja Nolte-Berndel and asking to "share" software, only to sue responders for breach of copyright laws. In later years, he was active in some controversial lawsuits regarding brand copyrights for brands like "Explorer" (suing Microsoft and some newspapers for using the brand, even though to this day it's not entirely clear if the claim was ever valid, the German patent office even deleted the entry for Explorer). Recently, he was found guilty of Fraud and sentenced to 14 months jail, which were supposed to start this month.

Needless to say, he was not a very popular figure, and that is as nice as I can say it.

But still, he made a name for himself and to this day, "Tanja" and "Gravenreuth" remain an insider under C-64 (and other 80's computer) users. It is part of computer history in Germany now, so when I heard the news, my first thought was "Whoa". It's weird seeing something or someone who just seemed to be always there go away. Maybe it's just a sign that I'm getting old (even though I'm only 26), maybe it's just a sign that the 1980s and my childhood are really over.

While I can't say that I'm crying, I'm also not cheering. I can't say much good about him, except that he was part of the culture I grew up in and as such made an impact, and so there is a certain emptiness now. That and suicide is always a horrible way to make things end.

Goodbye, 1980's.

Why is it so hard to list proper technical specifications?

I never read user manuals, because they are usually a waste of time. The main reasons for me to read user manuals is because I need to check something that is not listed in the technical specifications.

A few weeks back I ranted about TV manufacturers unable to properly list their Inputs/Outputs in the specs and how I have to read the user manual to find out if I really am able to use it. Weirdly, some companies are unable to provide a shot from the back and a user manual.

My current reason to rant is the Acer B233HU monitor. I bought it more or less blindly because it has a resolution of 2048x1152 and because it has an HDMI input that supports that resolution (my graphics card can drive 3 monitors, but only has 2 DVI Ports, so I needed a HDMI or Display Port Monitor). Now I'm realizing how much space my monitors take up on my desk, so I remembered Jeff Atwood posting about Monitor Arms some time ago.

Now, to buy a Monitor Arm, I need to know the proper measurements for VESA Mounts. There is 75x75mm, 100x100mm and some other sizes. For my Philips 240BW that's no problem: Go to Philips website, look at specs, see that it's 100x100mm. But my Acer Monitor? No information. I can guess or measure myself that it's also 100x100mm (it is), but really, that belongs in the specs or the manual!

I think it's astounding that they list stuff like what the pins of the DVI Port do (As it's important for me to know that Pin 24 is DDC TMDS Clock-) but not what measurements their VESA Mount it.

Seriously, why is it so hard for companies to determine which specs are important and list them? Yes, I know that I belong to the minority of people who look at the specs and buy stuff that fits a need rather than just buying stuff because of bling-bling and advertising, but do you really need to constantly remind me of that fact? Can't you just - at least sometimes - pretend that us engineers are still valued customers?

An Extension method to replace multiple Chars in a string

I needed a Sanitizer function for a project, which will replace chars in a string with other chars. To my dismay, I found that there is only a function to replace a single char or string. Of course, I could chain multiple string.Replace calls, but that creates a new string every time which can add quite a bit of overhead. So I've created a function that takes two Lists of chars and then replaces each occurrence of one char with another one. This also allowed me to implement a second function I was missing from string.Replace, the ability to remove chars (it's possible if you use the string overloads, but not the char ones). The second List is of nullable char type, so just pass in null to remove a char.

public static string ReplaceMultiple(this string input,
                                     IDictionary<char,char?> replacements)
{
    var sb = new StringBuilder(input.Length);
    foreach (char c in input)
    {
        if (!replacements.ContainsKey(c))
        {
            sb.Append(c);
        }
        else
        {
            char? replacement = replacements[c];
            if (replacement.HasValue)
            {
                sb.Append(replacement.Value);
            }
        }
    }
    return sb.ToString();
}

Usage example:

public string SanitizeTitle(string title)
{
    // Replace space with _ and remove ? and :
    var replacements = new Dictionary<char, char?>
                           {
                               {' ', '_'},
                               {'?', null},
                               {':', null}
                           };
    return title.ReplaceMultiple(replacements);
}

Update: The previous version had two lists. When working with that, I found it rather stupid to keep two lists in sync (they need to have the same count, and the order needs to be correct). So this updated version uses a Dictionary instead, which also allowed me to remove the Exception.

Important caveat: Each character is only processed once, so if you replace a char and happen to have a replacement for the replacement, it will not be processed. Example:

public string ImportantCaveat()
{
    string input = "ABC!DE_FG";
    // Replace ! with _ and  _ with %
    var replacements = new Dictionary<char, char?>
                           {
                               {'!', '_'},
                               {'_', '%'}
                           };
    string output = input.ReplaceMultiple(replacements);
    // Output will be ABC_DE%FG and not ABC%DE%FG
}

JavaScript TimeSpan library updated to 1.1

I have polished the TimeSpan library a bit more. I ran it through JSLint to get the formatting right, and I changed it's function names to follow the common practice in the JavaScript world. Also, there is now a Documentation with some examples.

Note that due to the naming changes, this is a breaking change.

Download it from GitHub.

JavaScript TimeSpan Library

Working with Time is always weird. Some functions want milliseconds, others want seconds. And if you want to express "3 hours" in milliseconds, usually the result looks like var targetTime = 3 * 60 * 60 * 1000; which is a bit ugly in my opinion. Also, I always have to remember what to actually add together :)

As a .net Developer, I'm used to the useful System.TimeSpan and System.DateTime structs which have such useful features like AddHours or TotalMilliseconds to have a more natural way to work with Time.

I wrote a JavaScript library that mixes useful functionality from these two structs into "class". Here is a quick example:

var ts = new TimeSpan();
ts.AddHours(3);
alert(ts.TotalMilliseconds()); // Outputs 10800000

// There are also "static constructors":
var ts = TimeSpan.FromHours(3);
alert(ts.TotalMilliseconds()); // Outputs 10800000

There are also functions to Add/Subtract another TimeSpan and an Equals function to compare two TimeSpans. Note that there are two types of getters. There are the TotalSeconds/Hours/etc. functions that return a floating point number. And then there are the Seconds/Hours/etc. functions that return an Integer, but that only return a fraction of the TimeSpan that can be used to create a clock. This mirrors the behavior of the .net TimeSpan.

Example:

// TimeSpan for 3 Days, 2 Hours, 10 Minutes and 4 Seconds
var ts1 = new TimeSpan(0, 4, 10, 2, 3);
alert(ts1.TotalDays()); // 3.0903240740740743
alert(ts1.TotalHours()); // 74.16777777777777
alert(ts1.Hours()); // 2, not 74.
alert(ts1.Days()); // 3

I haven't written Documentation or VSDoc comments yet, and there is no minified version either, but in the next days I'll add them. In the meantime, Download it from GitHub. It is licensed under MIT license.

Why I think Internet Explorer is the best browser for JavaScript development…

I've started learning JavaScript in November 2009, so about 2 months ago. I am a WebForms developer in my Job, thanks to SharePoint, and I was fed up one day with static/postback-only user interfaces. I wanted to make them snappy, cool, Web 2.0™.

One of the things that kept me away from JavaScript in the past was the browser support hell. Every browser has little differences in it's implementation, and even trivial operation often require an if-statement with 3+ branches to get the differences straightened out. Luckily, libraries like jQuery are available to abstract the whole mess away and give us a clean interface to interact with the browser. I am a big fan of abstractions as long as I know what I'm abstracting away, and jQuery is pure gold that allows me to focus on the actual application/user interface I'm building. After lerning about JavaScripts scoping rules (variables are available to the entire function - { and } do not create a new scope) I was finally able to understand, troubleshoot, and (hopefully) fix a bug in a third party library that I'm using - finally being in control feels great!

But, I have one issue, which is the JavaScript support in Chrome and Firefox. This is a controversial statement for sure, as pretty much everyone agrees that Firefox and Firebug is the de-facto standard for JavaScript development, which I would normally agree with - as good as the Web Developer Toolbar became in Internet Explorer 8, Firebug is still the nicer tool. But my problem with Firefox and Chrome is that they are too lenient about bad JavaScript.

I'm guessing that this is because most JavaScript on the web is simply broken, and throwing an error every time an error is occurs would seriously degrade browsing experience. So I'm guessing that just as with broken HTML, "modern" browsers try to fuzz and fix the JavaScript. One of the reasons XHTML failed was because it was too strict, and because browsers didn't complain loud enough.

I had 3 hard to track down JavaScript errors. Well, hard to track down for me. In all three cases, the error was mine. An extra comma before a closing bracket, forgetting to close a bracket etc. Firefox worked flawlessly. Chrome had a subtle bug. The only browser that constantly does the right thing is Internet Explorer 8: It refuses to execute the JavaScript and throws an error instead.

Internet Explorer showing an Error

When developing, this is what I want. I want any errors to be reported. I want the application to crash hard. I want the browser equivalent of -Wall and -Werror. Granted, the Internet Explorer error messages are not that helpful as they only roughly outline what the problem is, but still they are useful enough to work with.

As a developer, I still care about my code. I try to write valid HTML, valid CSS and valid JavaScript whenever possible and at least know when I'm breaking the rules in the cases where valid code is not feasible. So any functionality that sweetens the experience for the end user by hiding errors is making the experience for the developer worse. I know that there are many advocates of loose standards and "just somehow automatically fix it", but ultimately I think that standards exist for a reason and I'd like to at least know that I'm doing something wrong.

But then again, this is the Internet and I realize that design and content are much, much more important than code quality, and I agree that providing value to the customer is ultimately more important than having a solid code base. But still, please leave me my illusion that good code and web application are not mutually exclusive :)

Beginning Debugging in VS2010 Episode 2: Advanced Breakpoints

This episode focuses on some advanced concepts with breakpoints, like conditions or exporting/importing them. We also look at the breakpoint window. After this episode, you should be able to use breakpoints more efficiently than just as on/off switches.

Okay, this took a little longer because of a broken Power Supply in my PC. Also, due to software problems, there are no titles, but I didn't want to wait much longer. If you happen to know a proper Video Editing solution for Windows, please answer this SuperUser question :-)

Beginning Debugging in VS2010 Episode 2: Advanced Breakpoints from Michael Stum on Vimeo.

The source code for the demo application is available here.

Overview of all Episodes