The short version of how Ars rolled out short URLs on such short notice: Django!

I keep meaning to do this, but I really do plan on writing up a short post on Ars Vigiles about how I implemented and deployed the Ars Technica URL shortening service in about 3 hours using Django.

For quickies it’s just a vanilla Django project utilizing a hacked version of Josh VanderLinden’s django-ittybittyJannis Leidel is busy making it less hacky. By default, the “shortening” in ittybitty uses a very weird sort of bit masking, replacing each matched “place” with a character between 0-9 or a-z, which really isn’t the same as a straight Base36/62 representation of an integer. Specifically, the strings it produces are reletively long at low integer values, unlike a Base36/62 representation which remain at 2 characters from 0 to (36**2)-1.

In my project I added a (very) small app (urls.py+views.py) with about 10 lines of code that added an API endpoint that lets me pass in an Ars URL and get back a new arst.ch URL.

arspat = re.compile(r'^http://arstechnica.com')

def shorten(request):
  url = request.GET.get('url', None)
  m = arspat.match(url)
  if m and url:
    iburl, created = IttyBittyURL.objects.get_or_create(url = url, defaults = {
      'url': url,
    })
    return HttpResponse('%s' % (iburl.get_shortcut(),))
  else:
    return HttpResponseBadRequest('URL Fail.')

I also extended my Ping.FM Smasher Django project to allow anyone to use any arbitrary URL shortener they want (and append any special tracking codes they want—we use Google Analytics campaign stuff). This was required so I could integrate the ars.tch short URLs into our Twitter Accounts.

Finally I just wrote a little ShortenedURL Movable Type plugin in Perl that requests a new short URL from the API and stores it in Entry metadata right before it’s published to disk (and subsequently pushed out to our front ends).

Look for a slightly longer and in-depth version on Vigiles sometime next week.