Tales from the Evil Empire

Bertrand Le Roy's blog


Bertrand Le Roy

BoudinFatal's Gamercard

Tales from the Evil Empire - Blogged

Blogs I read

My other stuff


March 2013 - Posts

This is how we should read hexadecimal…

Today my five-year-old told me that when she was four, she thought that what came after ninety-nine was… tenty. You know, because seventy, eighty, ninety, tenty.

At first I thought it was just funny and charming, but then I realized it was actually a really good idea. Tenty is only nonsensical if you’re counting in base ten (or lower), but it makes total sense for higher bases.

How do people usually read 0xA0? “A-zero”? How unimaginative! Let’s read that “tenty” from now on!

Here are some more examples of how to read hexadecimal in a non-boring way:

  • 0xB3 is eleventy-three
  • 0xCA is twelvety-ten
  • 0xD9 is thirteenty-nine
  • 0xEC is fourteenty-twelve
  • 0xFF is fifteenty-fifteen
  • 0xF04A is fifteen hexathousand forty-ten
  • 0x4B2AC0AA is forty-eleven hexamillion, two hexahundred tenty-twelve hexathousand tenty-ten
  • and of course, seven-eleven will have to change their logo to 0x7B.

Repeat after me... One, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, onety, onety-one, and so on.

Is this the greatest thing or what?

Taking an Orchard site offline while you update it

(c) Bertrand Le Roy 2012If your hosted environment does not give you a staging site and the means to swap it easily with the production environment like Azure Cloud Services do, or if you don’t have a staging database, or if you just need to take your site offline for the public while you perform data updates in the admin, you may be wondering what solutions you have, if any.

IIS has an app_offline.htm feature that you can use, that will serve a static page for all requests but that’s rather brutal as it does not just take the site offline for your users, it also does so for you. While that file exists, you can do absolutely nothing with your site. You cannot access the admin, you cannot preview your changes, nothing. So when you flip the switch back, it’s anyone’s guess whether the changes you blindly made actually work, even if they did on your machine…

We need a better solution. Well, I happen to have one...

All you have to do is create a new theme named “Offline” with just one /Views/Layout.cshtml file containing a message along the lines of “We are updating the site. We apologize for the inconvenience. Please come back in a few minutes.” You can add stylesheets to make it pretty if you want to. It’s a full theme, you can go crazy.

The important thing is that this theme has one layout, and that this layout does nothing but display its message. It has no zones, so no dynamic content is going to be served to the public from the site no matter what URL is hit.

Once you have made this theme current, all your visitors are seeing it, but you can still access the admin of the site and do whatever you want.

Better, you can use the “Theme Preview” feature of Orchard to check what your changes look like while your users continue to see the “offline” page. Just go to Themes, and click Preview on your regular theme…

Once you are satisfied with your changes and judge the site to be ready to be taken back online, just restore your theme as the current. The “Offline” theme can sit there and do nothing until the next time you need it.

I’ve used this technique successfully last time I updated an Orchard site. It worked great. I hope it helps others…

Dead simple stubbing for JavaScript

I’m writing a lot of JavaScript these days, and for testing I mostly use QUnit. When I need to quickly stub a piece of the code that I’m testing, I like to use the following micro-library. What it does is enable you to replace a bunch of methods on an object with stub versions, in a easily reversible way.

I use RequireJS, but if you don’t, just remove the define and outer function.

define(function() {
    var stub = function(obj, stubs) {
        obj._stubbed = obj._stubbed || {};
        for (var name in stubs) {
            obj._stubbed[name] = obj[name];
            obj[name] = stubs[name];
    stub.restore = function(obj) {
        if (!obj || !obj._stubbed) return;
        for (var name in obj._stubbed) {
            obj[name] = obj._stubbed[name];
        delete obj._stubbed;
    return stub;

Here is how you would replace two methods bar and baz on an object foo:

stub(foo, {
    bar: function() {
        return "stubbed bar";
    baz: function(glop) {
        return "stubbed baz " + glop;

And here is how you can put everything back in place once you’re done:


I hope this helps...

More Posts