Geek

Django template tag to display latest git commit, date and tag in template

I found a few references to bits and pieces of this in various places, but this snippet ties all three bits of information together in a single string, and accounts for calling the path to the git repo from anywhere (which tends to work “magically” on localhost but breaks on servers).

If you don’t use git tags, season to taste.

@register.simple_tag
def git_ver():
    '''
    Retrieve and return the latest git commit hash ID and tag as a dict.
    '''

    git_dir = os.path.dirname(settings.BASE_DIR)

    try:
        # Date and hash ID
        head = subprocess.Popen(
            "git -C {dir} log -1 --pretty=format:\"%h on %cd\" --date=short".format(dir=git_dir),
            shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        version = head.stdout.readline().strip().decode('utf-8')

        # Latest tag
        head = subprocess.Popen(
            "git -C {dir} describe --tags $(git -C {dir} rev-list --tags --max-count=1)".format(dir=git_dir),
            shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        latest_tag = head.stdout.readline().strip().decode('utf-8')

        git_string = "{v}, {t}".format(v=version, t=latest_tag)
    except:
        git_string = u'unknown'

    return git_string

Then, in your template, you can simply:

{% if user.is_superuser %}{% git_ver %}{% endif %}
Arts and Culture, Geek

GoPro Time Lapse: Stinson Beach

Last weekend at Stinson Beach I attached a GoPro to a tree and had it shoot one image every 5 seconds for a couple of hours. Later compiled the image into a 29fps half-speed video in GoPro Studio. Not sure why I enjoy making these so much; something oddly satisfying about the process.

Geek

View 403, 404, 500 with media in Django DEBUG mode

When working with Django in DEBUG mode, it can be tough to see your 403, 404, and 500 views, since they raise visible stack traces instead of the UX the end user will see. But if you turn DEBUG off, runserver’s local media serving is disabled because it’s designed to work only with DEBUG = True. The solution is scattered throughout the Django docs, and I couldn’t find it compiled into one compact code block anywhere – just reference the handling functions directly from the end of your urls.py:

if settings.DEBUG:
    from django.views.defaults import server_error, page_not_found, permission_denied
    urlpatterns += [
        url(r'^500/$', server_error),
        url(r'^403/$', permission_denied, kwargs={'exception': Exception("Permission Denied")}),
        url(r'^404/$', page_not_found, kwargs={'exception': Exception("Page not Found")}),
    ]

And voila, your 403.html, 404.html, and 500.html templates will be displayed in full glory for developers.

Out there

New Collage for Amy’s 50th

Back in my late teens and well into twenties, before the interwebs, I spent countless evenings creating paper collages (sometimes with friends) – for framing, for calendars, for cards, for laughs. But it had literally been decades since I last pulled out an exacto blade and glue stick until this afternoon, when I decided to make one for my wife’s upcoming birthday. Kind of had trouble getting things to “click” aesthetically, and this one feels a bit clunky, but it felt great to re-connect.

Collage Amy 50th birthday

Hosting

Birdhouse Hosting – End of an Era

Well, that’s a wrap! After 12+ years in the web hosting business, I’ve just moved the very last customers off of the server, migrated my personal domain over to Dreamhost, and updated the final DNS records. And with that, Birdhouse Hosting is no more. It’s been an amazing dozen years – both fulfilling and frustrating. I made some money, lost a whole lot of sleep, and had way too many vacations and weekends interrupted with sudden needs.

It’s amazing to see how drastically the hosting landscape has changed in the past decade. The emergence of tools like GMail made custom mail hosting all-but-irrelevant – there’s absolutely no way a small web host can provide the level of spam control, or storage, or excellent interfaces that they do. And the emergence of serve-yourself site builders like the ones offered by Squarespace just can’t be touched by open-source software.

Except in special cases, pretty much all of the need (and the reward) has been drained out of the boutique hosting business. It was time to let it go. I’m honored to have been able to host so many fantastic sites, and to have worked with so many fantastic customers over the years.

Once the dust settles on the new year, I look forward to getting back to a bit of freelance web dev work, though next time around I plan to focus on higher-end web application needs rather than WordPress.

See you in the new year!

Environment

Mountain Biking the Coastal Trail, Marin Headlands

Decided to take a mountain bike out to one of my favorite hiking trails in the Marin Headlands yesterday – the Coastal Trail from Alexander Drive down to the Headlands Center for the Arts. Recorded the trip with a helmet-mount GoPro and edited it down to 9 minutes (probably still too long, but I didn’t have time to make it shorter. Hopefully catches a bit of the feeling of being out there on a perfect November afternoon.