Quickly change directory to the root of a git project

Change directory upwards to the first directory containing a .git directory. Helpful in quickly getting to the root of a git project.

Quick and Dirty Google Analytics Debugging

It can be difficult to tell what’s being tracked by Google Analytics with the delay between triggering actions in the browser and seeing those records in the Google Analytics dashboard. This is a quick and dirty way to track Google Analytics actions locally to make sure events are being triggered correctly before going to production.

Using Python’s requests Module to Fake APIs

In this case, it’s used to read the status of an Alarm.com account and set the status of a Dropcam accordingly (disable Dropcam when alarm is disabled).

An Open Letter to My Congressional Representatives Regarding PIPA and SOPA

Dear [Congressman Guinta/Senator Ayotte/Senator Shaheen]:

I am writing regarding the [Stop Online Piracy Act (SOPA)/PROTECT IP Act (PIPA)] bill currently under consideration in the [House/Senate].

I am a ███-year-old software developer living and working in ██████ and a lifelong New Hampshire resident. I grew up as a citizen of the global Internet community along with millions of others just like me. We invested untold hours to create and nurture a still-flourishing place for freedoms of speech and commerce both. The [SOPA/PIPA] legislation currently in the [House/Senate] represents a major shot across the bow of a free and open Internet, one which provides me a good living and the ability to contribute back to online and offline societies alike. Continue reading An Open Letter to My Congressional Representatives Regarding PIPA and SOPA

Debugging sorl-thumbnail in Production

By default, Django makes every attempt to hide template errors from the user. This makes sense in a production environment where you don’t want a simple empty variable to cause your site to blow up. It can, however, cause trouble because you won’t see those swallowed errors in any admin email notifications. It’s especially tough when you’re using a thumbnail library like sorl-thumbnail, which will have no output when it encounters errors rendering thumbnails. There’s a nice way to use Django’s built-in shell to troubleshoot sorl-thumbnail errors in your production environment. Here’s some sample code, using a generic Image model:

class Image(models.Model):
  image = models.ImageField(upload_to='images')

Enter the Django shell:

python ./manage.py shell
>>> from django.conf import settings
>>> from django.template import Context, Template
>>> from models import Image
>>> settings.THUMBNAIL_DEBUG = True
>>> image = Image.objects.get(id=1)
>>> c = Context({'image': image})
>>> t = Template('{% load thumbnail %}{% thumbnail image.image "100" as img %}{{ img.url }}{% endthumbnail %}')
>>> t.render(c)

The key is setting THUMBNAIL_DEBUG to True, which you wouldn’t want to do when the code is being rendered to your site visitors, but in this instance it will allow any sorl-thumbnail errors to be displayed in the console. The most common issues I’ve stumbled across are permission-related, with the Python instance not having write permissions to the sorl-thumbnail cache directory.

LWA Webcam Revamp

We set up the first webcam for the Lake Wentworth Association (LWA) web site at least seven or eight years ago. It started with one of those old, beige eyeball webcams, which soon gave way to our old tape-based video camera hooked up through a TV tuner card. It didn’t take long for the stress of running constantly to turn the image output into a giant pink blob. After that, we did some looking and found that Canon digital cameras offered a remote capture functionality, turning cheap, readily-available still cameras into great webcams. We picked up a used Canon A20 and a power adapter up on eBay for something under $150. That camera did its duty for a couple of years before giving up the ghost. We went back to eBay and found a Canon A520, which is a great 4.0 megapixel camera with 4x optical zoom. Several years later, that same camera is still clicking away, taking a new picture every 15 minutes.

While the hardware has changed a bit, the software behind the scenes hasn’t. Our first couple of cameras just uploaded over the same set of four images; we didn’t keep an archive like we do now. Eventually, we realized what a great resource the camera could be for documenting the state of the lake for visitors near and far. The original archive pages I wrote to store daily photos were very crude PHP and they haven’t changed much since then. The archive sits nested inside of an outdated Mambo installation, which is in dire need of replacement. On the camera side, I wrote a BASH script that combines Capture, ImageMagick, and several other command line utilities to capture an image from the camera, test for the amount of daylight, resize to the appropriate dimensions, create a timestamp/temperature image, and upload the group of images to the LWA web site. The script has evolved over the years and it’s still quite functional, but the time has come for an upgrade. That’s where WordPress comes in.

I’ve been involved in a lot of WordPress development over the past couple of years at work and in my own time, and I’ve grown to love the platform. Plugins and widgets make it easy to build a system to do just about anything content-related. It’s that flexibility that recently got me thinking about developing a webcam plugin for WordPress. The code I developed years ago is simply too messy and customized for general consumption. The WordPress plugin I’m working on now will let anyone with a webcam and a bit of technical knowledge set up an archive of photos without much effort. WordPress’ XML-RPC API provides a simple base for uploading photos programmatically. I’ll also be creating a simple Python client that will handle the blog interaction on the camera side. Both projects are going to take some time, but I’m aiming for March to have working versions running. This timeline is intended to coincide with a re-launch of the LWA site in WordPress. For now, progress of the webcam projects can be tracked on GitHub: WordPress plugin and XML-RPC client.

SeacoastOnline.com’s Broken Pay Wall

Dear SeacoastOnline.com,

If you want to make money with your new payment model, consider hiring a web developer who could create a real login system to protect your content. All it takes is a few lines of JavaScript (four to be exact) in a bookmarklet to disable the current content “protections” and read an article. The system uses jQuery to hide content and show the pay wall, but the problem is that the full article content is delivered to the browser even for anonymous visitors. A complete login solution would do a server-side check to make sure the visitor is logged in before returning complete content. It can’t be that hard to do it the right way.

Update: The great Readability bookmarklet also makes the full article content visible with the bonus of removing ads.

Buy This Beer

BuyThisBeer.com is a little project I started to keep track of what beers I’ve tried, what beers I liked and didn’t, and what beers I’m seeking out. Right now there’s not much to it, but it gives me an opportunity to play with new technologies and techniques (there’s no fun in repetition, but there is in self-improvement).


I have a few goals I want to accomplish with this project:

  • Work with larger data sets and the programming challenges that brings, including finding efficient ways to traverse the data on the UI side as well as search it.
  • Make a usable mobile interface, with a light footprint and easy-to-navigate page elements.
  • Get to know Git for version control and Capistrano for easy deployment of changes (already set up).
  • Create a social sharing aspect of the site to let people network, share recommendations with friends, and receive recommendations based on their own ratings.
  • As time allows, experiment with opening a basic API to make the data accessible beyond the site. My main pet peeve with existing beer rating sites is their closed nature. I’ve been forced to write a page scraper for BeerAdvocate for the time being.
A long way to go on design...

Dave Masse, Software Engineer