Bad Luck

Bad Timing & The Mysterious AWS XML Exception

Bad Luck
Bad Luck
Server Time Mis-configured, Amazon Web Services S3 .NET SDK has a bug in it, Vague XMLExceptions that don’t make sense.

Sometimes karma is just going to get you. There’s no point fighting it. A series of events & issues just come together in cosmic bliss guaranteed to completely wreck your weekend.

We rolled out some new code for a new client last week. One of the “big stories” for both us and the client was a migration away from in-house content storage to a cloud based solution. We had opted to use Amazon S3 for the file storage part and after ~6 weeks of project development, rigourous QA & Regression testing, and a bit of a stressful production release we were good to go. Our Biz/Mkt team had seen it and they were happy. Last minute checks of the production service were done, all looked good, and home we went.

Read More “Bad Timing & The Mysterious AWS XML Exception”

Converting to Base62 & URL Shortening

Generic Marketeer: “Why do we need to shorten the URLs, people just click on them. It’s not like they have to memorize them; call them out to their friends”

Me: “Eh… no you’re right, but I do need to jam them into a SMS WAPPush along with some descriptive text, so I don’t have much room to play with”

Generic Marketeer: “Fine, as long as it doesn’t impact the project deadline”

Cue, my good self scurying away to find a way to bang out a private URL Shortening service in as short a time as possible. The URL Storage itself was a piece of pie. But I did stumble across some nice code while I was at it. I started out with a int-to-base64 implemenation. but the `+` & `/` characters are fugly to deal with in URLs. I tried a Hex version as well but it just didn’t look bit-ly-y enough. Enter the baseAnything encoder. Just point it at any character set and it will encode/decode to that number of chars.

The following extension methods convert longs to strings, and vice-versa

public static string ToBase(this long input, string baseChars)
    string r = string.Empty;
    int targetBase = baseChars.Length;
        r = string.Format("{0}{1}",
            baseChars[(int)(input % targetBase)],
        input /= targetBase;
    } while (input > 0);

    return r;

public static long FromBase(this string input, string baseChars)
    int srcBase = baseChars.Length;
    long id = 0;
    string r = input.Reverse();

    for (int i = 0; i < r.Length; i++)
        int charIndex = baseChars.IndexOf(r[i]);
        id += charIndex * (long)Math.Pow(srcBase, i);

    return id;

I’ve been using it against the first character set below, but you could easily tweak it to remove any “confusing” characters, or any set for that matter.

private static string ALPHANUMERIC =
    "0123456789" +

//Remove 0oO1iIl - Base52
private static string ALPHANUMERIC_ALT =
    "23456789" +

Now all I have to do is go write a Math Engine for it 😉