The Stochastic Game

Ramblings of General Geekery

Working with Disqus

Since I’ve migrated this blog to PieCrust and all its comments to Disqus I’ve run into a few problems that took me some time to figure out (although I got help from the nice Disqus guys). Those problems come down to the following information which was not quite clear to me even after reading their documentation several times:

  • The disqus_identifier value gives a unique name to a thread.
  • The disqus_location value indicates the URL(s) at which a given thread can be found.
  • A thread can be used by several URLs, but no URL can be used by more than one thread.

The first 2 points are pretty straightforward, but that last one was the tricky one. Basically (at the time of this writing, obviously) if you have 2 threads with 2 correctly unique identifiers that were created both with the same URL, your page at that URL will show all kinds of weird behaviours, from never loading any comments (you get the “Disqus loading” icon animation) to loading one of the thread regardless of what disqus_identifier you specified on that page. You would think that identifier would, well, identify exactly what thread you wanted to display, but no, the URL from which it is loaded apparently also plays an important role.

This means, for example, that you can’t display more than one thread on a single page, although the Disqus guys told me this limitation will be removed in a few months.

Another little thing to look for is the subtle distinction between http://example.com/some/url and http://example.com/some/url/ (note the trailing slash character at the end of the second URL). Those URLs are effectively different, as far as Disqus is concerned. This is especially important for statically generated websites since the actual URL of a page or post is http://example.com/some/url/index.html, so there could be at least 3 correct ways to access the same page. Hopefully, as long as you don’t have some weird address collision, you won’t run into the problem mentioned above (which I ran into because I was messing around with the very handy Disqus Python bindings to batch rename and re-identify my threads).

Hopefully this will save somebody some head-scratching.


Announcing PieCrust

You may have noticed that this blog has changed its look, and has migrated its comments to Disqus. You may also see at the bottom of the page something about some pie crust baking… here’s what’s happening.

I have a few websites around and most of them don’t have much in them (e.g. I use the domain name for other things). There’s clearly not enough content to use a proper CMS, but there’s a bit too much repetition for my tastes if I write HTML files by hand. Also, I wanted to take advantage of libraries like Markdown or SmartyPants to make my text look nice with no effort. Basically, I needed some micro-CMS that would handle some basic layout and formatting.

Then there was the issue of this blog. It was running with WordPress, which I’m very happy with usually, but it wasn’t geeky enough. Also, syntax highlighting for code snippets felt dirty and over-complicated. I stumbled upon the whole “static site generation” underground scene and figured I could find something in between: a micro-CMS (for my small sites) that could also bake its own contents into static HTML files (for this blog).

Enter PieCrust.

There was already a shitload of static website generators, but none that could also work as a “dynamic” micro-CMS. Also, I’m a programmer geek, so it’s kind of my duty to not be happy with existing solutions and write one myself (“this one uses curly braces, but I want to use brackets instead! Surely now I have to write my own!). Anyway, isn’t the whole point of home projects to write stuff for yourself, to learn something new or just have fun with a new subject, regardless of whether it’s productive? I was bored, too.

I ended up writing PieCrust in PHP not because I like PHP (it mostly sucks), but because it’s still the most widely used web application language out there. And also because I’ve already got other home projects aimed at having fun with Python and Ruby.

So there you have it, go check out PieCrust. The code is on BitBucket, and mirrored on GitHub.


Poor man’s search engines sync for Google Chrome (version 2)

After receiving some feedback, I’ve updated my scripts for syncing the search engine settings in Google Chrome. You can grab the new ZIP file here.

Here are the changes:

  • I’ve written some native CMD.EXE scripts for Windows, which are easier to run than the Powershell ones for non dev people (or devs that never used Powershell).
  • The scripts have been renamed to “export” and “import” since most people don’t get the “push” and “pull”.
  • The “import” script creates a backup of the settings files (a file called “Web Data.backup” in the same directory) so you can revert to the previous version if something goes wrong.

Enjoy!


My new shiny toy: the Archos 70

Tablets, and especially Android tablets, are going to be all the rage this year, with more new tablets announced every week than Lindsay Lohan had rehabs. Because I’m a geek with money to waste on unneeded electronics, I’ve decided to be part of the early adopters with my new shiny toy, the Archos 70.

IMG_2022.jpg

I would have usually waited on more mature tablets, along with a more mature version of Android (hopefully Honeycomb), but there are a few reasons I jumped on this one:

  • I’ve been a relatively faithful user of Archos’ previous portable media players (I’ve owned 2 other devices of theirs in the past, the AV500 and the 1st gen Archos 5).
  • The Futureshop warranty on my Archos 5 was about to expire, so I returned it and cashed in its retail value as a gift card in order to upgrade to the latest model “for free”.
  • I need a portable video player first, and a tablet second, so I don’t care much if the tablet experience is not so good.
  • I’m not playing games on my phone, and I don’t intend to play games on my tablet either.

Reading through Engadget’s review of the Archos 70 and his big brother the Archos 101, all I can say is that it’s a pretty fair review. If you don’t want to read the whole thing, the conclusion is that although those devices are clearly not as good as the Galaxy Tab or the iPad, for less than half the price there’s really nothing you can complain about. I’d go as far as saying that the price/quality ratio is actually higher on the Archos 70. This is especially true when compared to the Galaxy Tab, because this one is bound to be obsolete very soon (if it’s not already by the time I finish writing this) – at least the iPad features an OS and apps that are very well designed for the tablet format and are already quite mature.

Now there’s a few things I’d like to add to Engadget’s review, because I think they didn’t highlight some of the things the Archos 70/101 are doing better than the competition.

Body Design

Archos has been until now mostly a portable media player manufacturer, and it shows in the Archos 70. First, the device has a widescreen aspect ratio, unlike the big shots out there. This means that when watching movies and recent TV series, you will have smaller black bars around the screen, if any at all. For example, this is it playing Dirty Harry… See? No bars, no cropping. Just full-screen bad-assery.

IMG_2037.jpg

Speaking of the screen, it’s bright enough that you can watch videos outside to some degree, but it’s not as good as the iPad or Galaxy Tab screens, obviously. The view angles are particularly pretty horrible, but I don’t think it’s a big deal because it’s not like you can cram several people in front of a 7 inches screen anyway. For personal use, it’s “good enough”.

Second, the device has a built in stand you can unfold in the back. It’s very useful if you’re watching something while doing something else, like eating or cleaning your camera lenses or whatever. Way better porn watching experience, too 🙂

IMG_2028.jpg

The stand itself is cheap plastic and feels a bit fragile, so I wouldn’t be surprised if some people broke it at some point (which would suck).

By the way, I was expecting something bad in terms of device body after reading Engadget’s review, but it turned out okay in my opinion. It sure doesn’t feel as nice and solid as an iPad, but it doesn’t feel like a Playskool toy either. And I dropped it a couple times already and it’s completely fine (unlike an iPhone 4…). True to Archos’ tradition, however, the power and volume buttons on the side are a bit wobbly, and I expect them to be the first thing that breaks down. I wish they would learn to make sturdier buttons…

Another thing Engadget mentioned already, but it’s good to mention it again, is how thin that tablet is. It’s almost 50% thinner than the iPad. See how it’s even thinner than my iPhone 3G:

IMG_2027.jpg

It’s also super light. Archos says it’s 300 grams, which is less than half the iPad’s weight (although that’s not fair since the iPad is way bigger, with a 10 inches screen). My point is that it’s just a bit heavier than a Kindle 3 (at 250 grams), so it feels pretty natural to hold the Archos 70 in one hand while riding the bus or the subway. This is perfect for me since that’s where I watch most of my videos with it.

Media Playback

Another thing Archos is famous for is releasing devices that can read all the major (and even some minor) audio and video codecs. These tablets are no different, and so far anything I’ve thrown at it has been playing fine without the need for transcoding. Also, and that’s a big feature for me, the device appears as an external USB drive when you connect it to your computer – no need to go through some painful piece of software like iTunes. And you don’t even have to connect it at all since you can put stuff on an external mini-SD card (not included). Like any other Android device, it will scan the SD card when you mount it back and all the media that’s on it will be available. Hell, you can even just push stuff on it wirelessly with FTP or any other Wi-Fi syncing app. You’re free! Yay!

Speaking of Wi-Fi, the Archos 70 does a good job of integrating with your home network. The custom Video Player app can not only read local media, but also media from your SMB shares or your UPnP servers.

IMG_2030.jpg

If I want to finish watching some TV series episode in bed before going to sleep, I can stream it from my NAS or my XBMC box downstairs. The only thing that wouldn’t play was uncompressed rips of Blu-Ray movies (we’re talking 25 to 30 Gb HD video files, here!). I would get this error message:

IMG_2031.jpg

The rest would play smoothly across Wi-Fi. Here’s Serenity streaming from my NAS. I can even switch/toggle the audio or subtitle tracks and all that jazz.

IMG_2035.jpg

Applications

The main thing that kinda sucks about applications on the Archos 70 is how Archos decided to not install the Google Market, or any of the Google applications. That was probably to avoid having to get the device certified by Google or something, but still, it’s pretty lame. Instead, they want the user to go through some other market, AppsLib, which is decent (it has quite a lot of applications) but, well, is only a subset of the main Google Market.

Thankfully, and because we’re talking about Android here, people hacked the device pretty quickly. Archosfans was, I think, the first to offer an APK of the official market app, and that’s what the Engadget guys point you to, but now I recommend using the one from XDA. In both cases, it’s super simple: you just download a file and launch it with the built-in file browser. Once that’s done, you can get GMail and Google Reader and whatever you feel like downloading. You can even run AppBrain and copy all the apps you already have on your phone, if you have an Android phone. You’re free! Yay!

Performance

I don’t care much about performance, since I’m not using the tablet for anything heavy like gaming or whatever, but in case you’re curious, here it is. I ran the Quadrant Benchmark on it and got a score of 1271 without tweaking anything on the device (e.g. it still had applications running in the background and all that).

IMG_2074.jpg

People around the web can get scores around 1500 and more (above the Nexus One running 2.2) by killing all running apps and setting the “Power Management” to “Overdrive” in the system settings. Now, benchmarks like these don’t mean much, I know. For example the OS version alone seems to play a big part in it (see the difference between the Nexus One running 2.1 and 2.2 on the previous screenshot?). But at least it gives a rough idea of where the Archos 70 falls in terms of performance.

Just for laughs I installed a few well known games like Angry Birds or X Construction Lite and they ran very smoothly. Some people reported, at first, that a few games were unplayable, but it looks like it got fixed when Archos released the 2.0.71 firmware. And if you’re looking for serious speed and power, the XDA guys have already released a few custom kernels for the Archos tablets, some of which feature CPU overclocking.

Conclusion

So far I’m quite happy with my new toy, and the only thing I’m worried about at this point is how long it’s going to last – Archos usually cuts costs with cheap builds that tends to break or malfunction after a couple years (but then again, my Apple devices haven’t lasted much longer in my experience, although it’s usually for different reasons). I originally expected to only use it as a portable video player, ignoring most of the other features like I did with the Archos 5 (it had a web browser and all that, but the horrible resistive touch screen and crappy performance made it unusable for anything else than media playback). But it turns out the Archos 70 is a very nice tablet, and I find myself browsing the web, checking my email and social networks, and all that stuff more and more. For example it’s a pretty nice way to catch up on saved Google Reader or Instapaper articles before going to sleep. It’s also a very decent eBook reader.

It’s the best gadget I’ve bought since my first iPhone, although it’s mostly awesome because it’s so cheap. But still, it’s awesome.


Poor man’s search engines sync for Google Chrome

Update: since Lifehacker featured this post on their home page, I released some simpler updated version of the scripts here.

The wonderful thing about open-source software is that whenever something’s missing, anybody can go ahead and fix it… that is, unless nobody cares enough about it. And that’s precisely what’s happening with the “search engines sync” feature in Google Chrome, which has been in Chromium’s bug database for more than a year and a half. Looks like Google is not so much in a hurry to let you use other search engines as soon as you install a fresh copy of their browser.

Oh, don’t look at me. I seriously don’t have the time to dive into such a big codebase to add the feature myself… but what I do have the time for is a little scripted hack to get around the problem quickly!

Google Chrome, like a lot of programs these days, is using SQLite to store its data. Your search engines are stored in a database called “Web Data”, in a table called “keywords”. It’s quite easy to use the SQLite command line shell to export and import that table across your computers… so that’s what I did. There are 2 scripts: one to export, and one to import, although I called them “push” and “pull” to sound cool like the Git/Mercurial guys.

Windows

On Windows, my scripts are written in Powershell, which ships by default with Windows 7. On previous versions of Windows, Powershell ships with some service packs, so if you’re up to date you should have it. Otherwise, go get it from Microsoft’s website.

Update: if you’ve never run any Powershell script before, you’ll have to change the security settings because I didn’t sign my scripts. Run Powershell as an administrator and type “Set-ExecutionPolicy RemoteSigned”.

You’ll need to also download the SQLite command line shell (no install required, it’s just one .exe file in a zip). Just keep it next to the script files.

Here’s the export script:

param (
    [String] $Destination = "keywords.sql"
)

$CurrentDir = Split-Path -Parent $MyInvocation.MyCommand.Path
if (![IO.Path]::IsPathRooted($Destination)) { $Destination = [IO.Path]::Combine($CurrentDir, $Destination) }
$Destination = $Destination.Replace('', '/')
$TempSqlScript = "$env:TEMPsync_chrome_sql_script"

Push-Location
Write-Output "Exporting Chrome keywords to $Destination..."
cd "$HOMEAppDataLocalGoogleChromeUser DataDefault"
Write-Output ".output `"$Destination`"" | Out-File $TempSqlScript -Encoding ASCII
Write-Output ".dump keywords" | Out-File $TempSqlScript -Encoding ASCII -Append
& "$CurrentDirsqlite3.exe" -init $TempSqlScript "Web Data" .exit
Remove-Item $TempSqlScript
Pop-Location

And here’s the import script:

param (
    [String] $Source = "keywords.sql"
)

if ((Get-Process -Name chrome -ErrorAction SilentlyContinue | Measure-Object).Count -gt 0)
{
    throw "Close Chrome and try again..."
}

$Reply = Read-Host -Prompt "This will overwrite your Google Chrome search engines! Are you sure?  "
if (!($Reply -match "^(Y|y|YES|Yes|yes)$"))
{
    Write-Output "Cancelling operation."
    exit
}

$CurrentDir = Split-Path -Parent $MyInvocation.MyCommand.Path
if (![IO.Path]::IsPathRooted($Source)) { $Source = [IO.Path]::Combine($CurrentDir, $Source) }
$Source = $Source.Replace('', '/')
$TempSqlScript = "$env:TEMPsync_chrome_sql_script"

Push-Location
Write-Output "Importing Chrome keywords from $Source..."
cd "$HOMEAppDataLocalGoogleChromeUser DataDefault"
Write-Output "DROP TABLE IF EXISTS keywords;" | Out-File $TempSqlScript -Encoding ASCII
Write-Output ".read `"$Source`"" | Out-File $TempSqlScript -Encoding ASCII -Append
& "$CurrentDirsqlite3.exe" -init $TempSqlScript "Web Data" .exit
Remove-Item $TempSqlScript
Pop-Location

MacOS X

On MacOS X I’m using bash so all you need is to make sure you’ve got the SQLite command line shell. You can either download it directly, or use one of the package managers like MacPorts or Homebrew (I’m using the latter myself).

Here’s the export script:

#!/bin/sh

DESTINATION=${1:-./keywords.sql}
TEMP_SQL_SCRIPT=/tmp/sync_chrome_sql_script
echo "Exporting Chrome keywords to $DESTINATION..."
cd ~/Library/Application Support/Google/Chrome/Default
echo .output $DESTINATION > $TEMP_SQL_SCRIPT
echo .dump keywords >> $TEMP_SQL_SCRIPT
sqlite3 -init $TEMP_SQL_SCRIPT Web Data .exit
rm $TEMP_SQL_SCRIPT

And here’s the import script:

#!/bin/sh
if ps -x | grep -v grep | grep Google Chrome > /dev/null; then
    echo "Close Chrome and try again..."
    exit 1
fi

read -p "This will overwrite your Google Chrome search engines! Are you sure?  " -n 1
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    echo "Cancelling operation."
    exit 1
fi

SOURCE=${1:-./keywords.sql}
TEMP_SQL_SCRIPT=/tmp/sync_chrome_sql_script
echo
echo "Importing Chrome keywords from $SOURCE..."
cd ~/Library/Application Support/Google/Chrome/Default
echo DROP TABLE IF EXISTS keywords; > $TEMP_SQL_SCRIPT
echo .read $SOURCE >> $TEMP_SQL_SCRIPT
sqlite3 -init $TEMP_SQL_SCRIPT Web Data .exit
rm $TEMP_SQL_SCRIPT

Bringing it all together with Dropbox

Those scripts handle importing and exporting our search engines, but we’re missing the “sync” part so far. That’s where popular syncing service Dropbox comes into play (but you can do this with any other syncing service). Just put all this stuff (the SQLite command line shell, the scripts, and the database dump) in a Dropbox folder. All you have to do is run the “export/push” script after you’ve changed your search engines, and run the “import/pull” script next time you get on another computer. Dropbox will have synced the dumped database file (“keywords.sql” by default) in the meantime (unless you’re moving really super fast, in which case you’ll have to wait a second or two).

I’ve made a handy ZIP file with those scripts, a couple of bootstrap (double-clickeable) files for Windows, and the SQLite win32 command line shell. So download it and start syncing in a very hacky and lame way!


Using Twitter as a feed reader

Robert Scoble famously posted about ditching Google Reader for Twitter a bit more than a year ago, and ever since I’ve been baffled at people moving to Twitter or Facebook to read their news. Business Insider even said a few months ago that Twitter has killed RSS readers. I’ve always been wondering how Twitter would be any better than RSS… that is, until I’ve actually tried it.

Now I’m just thinking those people are crazy out of their minds.

First, let’s put Scoble aside. This guy is clearly not your average user, he’s really out there. I mean, his performance concerns with Google Reader are completely legitimate, but he must be the only guy on earth that actually follows more than 20,000 people… and still uses the term “friends” to define them, by the way. And I’m not even talking about the feasibility of keeping up with that much information — after all, if he’s clever, he’s using tools to consume it all and make the trending subjects bubble up to the surface, or maybe he does it the other way around by searching for topics he’s interesting in right now instead of reading the timeline in a linear fashion. But average people (or, well, at least me) are following real friends (either their blogs, or the links/videos/pictures they share), a few websites pertaining to their interests that may not be related to web technology (knitting? cat breeding?), and other things that can’t be processed by some “trending” tool.

Anyway, I used Twitter instead of Google Reader for a couple months, and here’s what I found.

User Experience

The first thing that bugs me about Twitter, and all of its client applications, is that it effectively has a worse user experience than even the crappiest of RSS feed reader.

Remember why RSS feeds were supposed to improve our productivity, making it easier to get to the information that mattered? They were supposed to do this by bringing the information to us instead of forcing us to go to the information. RSS feeds would deliver the content, and only the content, right there in front of us, and they pretty much delivered on that promise. Sure, some websites only publish an abstract of the article, and you need to go to that website to read the rest, but that’s the worst case scenario. The best case scenario is that you read the whole thing in a distraction free environment.

Now what about Twitter? The best case scenario is the title of the article, with a link to the website. Yep. As far as I’m concerned, this is a step backwards in terms of productivity: I read some entry on Twitter, click a shortened URL, wait for some HTTP redirections, and then end up on the full website with animated ads and other distractions. Compare that to reading the article right now with only the content in front of me. And I’m not even talking about the worst case scenario, which is a shortened title of the article with a link, or some obscure smart-ass comment with a link.

Then there’s the problem of knowing what you’ve already read. All RSS clients track the items you’ve read. Most even synchronize that data over the cloud. Compare that to Twitter which doesn’t remember anything and for which I always have to look out for that point in the timeline where I’ve caught up with all the new stuff. And that’s for a naive, linear approach. Most of the time, I’m going to read stuff in a non-linear way, either by using lists or filtering by user (on Twitter) or filtering by tag or website (on Google Reader), so the stuff I’ve already read could end up mixed up with the stuff I haven’t read yet.

Q&A

There’s one thing I keep reading about Twitter being awesome, and that’s its ability to give you answers super quickly. Supposedly, you can tweet a question and get replies within a few minutes, if not seconds.

Well, that’s the biggest load of crap I’ve ever heard.

First, this obviously works only if you’ve got a sizeable following. A year and a half ago, the average Twitter user had 127 followers. It’s hard to tell how that number was calculated, but let’s assume it did take into account statistical distortions from the few internet celebrities having insane numbers of followers on one end, and all the inactive users (supposedly making up 3/4 of the whole user base) on the other end. Either way, that number is just big enough for a user to get a few answers a day. To really get to the point where you get better answers faster than your search engine of choice, I’m guessing you need to hit the 500 followers mark, maybe even 1000. I wouldn’t know, I’m far from being that popular… And even then, what? Twitter gets better for you as you get more people to follow you? Ok… what else sounds like this? Yeah: pyramid schemes. And that’s known to be non sustainable. There will be a lots of users down there with 20 followers trying to get some attention.

Second, what happened to all that concern about privacy? People start complaining the second Google introduces their Web Search History, but on the other hand it’s OK to search for information by posting stuff publicly on Twitter, which is then indexed a hundred times more?

Technical Stuff

Then there’s the problem of infrastructure. This part has a lot more to do with personal opinions about stuff you may not care about, but I always prefer a more open, distributed design over a more closed, constrained one. For example, if I can sign into a website using either my Facebook or Google account or OpenID, I’ll take OpenID because it’s obviously more open and doesn’t rely on the existence of a single company. Sure, unless you’re running your own OpenID identity server, you’re relying on some third party provider, but you can abstract that from OpenID consumers, and then switch the underlying implementation anytime you want. To pick a more mainstream example, between using a Hotmail or Gmail address and a custom domain address, I’ll choose the custom domain address for similar reasons.

Ok, so this is on the same level as people using open-source software vs .people who don’t care, or people eating organic food vs. people who also don’t care. And in this case, you probably don’t care, and that’s fine, but I personally dislike how Twitter and other similar services create this “siloization” effect on information and data on the web.

On Using Twitter

All of this makes Twitter a pretty horrible experience as a feed reader, at least for me. Does that mean it sucks? Well, kinda, but not necessarily. First, some of the new features indicate how the design team is trying to reduce my first productivity problem: if a link in a tweet points to a picture or a video from a known media service, said picture or video will be displayed in the sidebar right away. When you couple this with the new keyboard shortcuts and the lists, you have an experience that’s somewhat close to that of Google Reader, at least for some of the tweets. I can easily imagine that it’s going to get closer and closer in the near future… but right now it’s still lagging far behind IMHO.

For now I’m back to using Twitter the way it’s effective for me: following actual people’s status updates and link shares. Twitter is wonderful in the way it lets you get closer to what experts and other key people in society have to say on an everyday basis (you wouldn’t believe how “I had pasta today” inspires you when it’s been tweeted by a Nobel prize winner…). Arguably, that’s actually what Twitter is all about: information through people. RSS on the other hand is only for delivering content (although Google is trying to add social layers on top of it). The two may feel similar, but not quite.

Twitter is also a useful alternative search engine in some situations, but more and more search engines actually include tweets as search results (in Google, you need to click on the “Realtime” result type on the left).

But all things being equal, if I get the choice between following the same thing on Twitter or via RSS, I’ll choose RSS for sure.


Making WPF controls double-clickable

A common UI pattern features the ability to double-click on a control to go in “edit” mode. So for example, you have a TextBlock that shows you the name of an object, and you can double-click it to change it into a TextBox where you can edit that name. At this point, it’s easy to hook up the MouseDoubleClick event, or some other mouse event, but that’s not very MVVM-like, is it?

Thankfully, WPF gives us the awesome attached dependency property API, which we already used for adding auto-complete to TextBoxes. The goal is to be able to write something like this:

<TextBlock Text="{Binding Name}" mi:ExtendedCommands.DoubleClickCommand="{Binding EditNameCommand}" mi:ExtendedCommands.DoubleClickCommandParameter="42" />

When the TextBlock would get double-clicked, the “EditNameCommandcommand object on the DataContext would get called with “42” as the parameter. This is super easy to do:

public static class ExtendedCommands
{
    public static readonly DependencyProperty DoubleClickCommandProperty;
    public static readonly DependencyProperty DoubleClickCommandParameterProperty;

    static ExtendedCommands()
    {
        DoubleClickCommandProperty = DependencyProperty.RegisterAttached("DoubleClickCommand", typeof(ICommand), typeof(ExtendedCommands), new UIPropertyMetadata(null, OnDoubleClickCommandPropertyChanged));
        DoubleClickCommandParameterProperty = DependencyProperty.RegisterAttached("DoubleClickCommandParameter", typeof(object), typeof(ExtendedCommands), new UIPropertyMetadata(null));
    }

    public static ICommand GetDoubleClickCommand(DependencyObject obj)
    {
        return (ICommand)obj.GetValue(DoubleClickCommandProperty);
    }

    public static void SetDoubleClickCommand(DependencyObject obj, ICommand value)
    {
        obj.SetValue(DoubleClickCommandProperty, value);
    }

    public static object GetDoubleClickCommandParameter(DependencyObject obj)
    {
        return (object)obj.GetValue(DoubleClickCommandParameterProperty);
    }

    public static void SetDoubleClickCommandParameter(DependencyObject obj, object value)
    {
        obj.SetValue(DoubleClickCommandParameterProperty, value);
    }

    private static void OnDoubleClickCommandPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var element = d as UIElement;
        if (element != null)
        {
            if (e.OldValue == null && e.NewValue != null)
            {
                element.MouseDown += new MouseButtonEventHandler(Control_MouseDown);
            }
            else if (e.OldValue != null && e.NewValue == null)
            {
                element.MouseDown -= new MouseButtonEventHandler(Control_MouseDown);
            }
        }
    }

    private static void Control_MouseDown(object sender, MouseButtonEventArgs e)
    {
        if (e.ClickCount == 2)
        {
            var element = sender as UIElement;
            if (element != null)
            {
                var command = GetDoubleClickCommand(element);
                var parameter = GetDoubleClickCommandParameter(element);
                if (command != null && command.CanExecute(parameter))
                {
                    e.Handled = true;
                    command.Execute(parameter);
                }
            }
        }
    }
}

This code is pretty naive, but it gets the job done and illustrates quickly how to do it: just register 2 attached dependency properties in a new custom class, and whenever someone uses it on a UI element, start listening to the “MouseDown” event on that element and check against the “ClickCount” property to figure out if it’s a double-click. If it is indeed a double-click, just run the command that was specified for this control!

Obviously, you’ll need to handle error cases a bit better (like for instance if these properties are used on a non-UIElement), make it a bit better (for example register the MouseDoubleClick event instead of the MouseDown event if the target object is a Control), and other stuff like that. But, well, by now, you should know not to copy/paste code found on blogs without using your brain anyway.


The harpsichord and the clavichord!

Google recently released Google Scribe, an experiment on auto-completing words for the user in advance, instead of spell and grammar checking what he’s already written. Go try it for yourself.

I myself had some fun letting Google write stuff for me. Just start with an arbitrary word, and keep accepting whatever the first suggestion is. The UI slows down quite a lot after a dozen or so auto-completions, so sometimes you need to delete the last space and type it again to get some performance back.

For example, here’s what I got after seeding their algorithm with “I’m”:

I’m not sure if it is not a valid stream resource in C minor for Piano and Orchestra No. 1 in the world of the living room and dining room with a view to share videos with friends and family to enjoy a good meal and a drink for the first time in the future and the future of the world and the world of the living room and dining room with a view to share videos with friends and family to enjoy a good meal and a drink for the first time in the future and the future of the world and the world of the living room and dining room.

Obviously, the algorithm quickly loops like crazy, and the sentence doesn’t quite make sense, but it’s pretty funny (at least to me!). Now, here’s what I got when starting with “You”:

You can turn Autoshare off at any time and without notice to you and your family to enjoy a good meal and a drink for the first time in the future and the future of the world and the world of the living room and dining room with a view to share videos with friends and family to enjoy a good meal and a drink for the first time in the future and the future of the world and the world of the living room and dining room.

That’s pretty interesting, as the looping is very similar to the first one!

Now, here’s what I got when starting with “let’s”:

Let’s see if we can not guarantee each coupon ‘s authentication and authorization data between security domains and do not want to be related to the search result can be bookmarked to maintain the filter for future use at Recent Searches for neutral Higgs bosons in e minor for clavichord and the harpsichord and the clavichord and the harpsichord and the clavichord and the harpsichord and the clavichord and the harpsichord.

This time, the loop is short and kinda catchy. The harpsichord and the clavichord! The harpsichord and the clavichord! The harpsichord and the clavichord! Maybe that’s gonna be the next internet meme?