Author Archives: Andrew

Go: How to Get the Directory of the Current File

In Python I often use the __file__ constant to get the directory of the current file (e.g., os.path.dirname(os.path.realpath(__file__))). While writing a Go app recently, I found that there wasn’t an immediately obvious (or searchable, even with “golang”) equivalent. But in the annals of the golong-nuts mailing list I eventually found out about runtime.Caller(). This returns

Run Django Unit Tests in a Sublime Text 2 Build System

With the dev builds of Sublime Text 2, you can easily set up a build system that runs Django unit tests. You do this by adding a build system to your Sublime Text 2 project file for the Django project. I’ll include an example project file in this post that runs manage.py test –noinput as

Python: How to tell what class a decorated method is in at runtime

When profiling a Python app, it’s helpful to have a decorator that wraps functions and reports details about their performance. Assuming you are doing this to report some metric about the function, you’ll want the decorator to work with both bound and unbound functions (IE, regular functions and methods of a class), and if the

Make Sublime Text 2 More like Vim: Wrap Code, Go To Last Edit, Jump Back, and More

I’ve been trying out Sublime Text 2 as a replacement for Vim. While I enjoy using it and I experienced the “Wow, this does 90% of what Vim does” moment, I kept a running list of all the features in the remaining 10% that I relied on every day. These included: Better code wrapping (gq)

Sharp Edges: Protecting Ourselves from Digital Publishing

Nicholas Carr wrote in a recent article that he considered the ability of publishers to change text after they had released it “insidious” and a “bane” of digital publishing — specifically, if such changes are made in response to market research. I agree that there is a challenge inherent in the new ease with which

iA Writer and Notational Velocity

The OS X apps iA Writer and Notational Velocity are great for writing and taking notes, respectively. I wanted to try using them together, by setting iA Writer as the external editor for Notational Velocity, but after doing so I noticed that iA Writer would not open with the keyboard shortcut (Command-Shift-E), and it was

How to Fix Slow Scrolling in Vim and MacVim on OS X

I finally discovered the cause of my #1 OS X problem: slow scrolling in Vim, both in Terminal.app and in MacVim. There was always a marked difference between Vim on my Mac and Vim on Linux. Scrolling with the movement keys (j/k in particular) was blindingly fast on Linux, but plodded along on my Mac so

Instant Django Dev Environments with Tmux, Tmuxinator, and Virtualenvwrapper

This post describes how to use a few common tools to instantly set up and tear down Django development environments. I’ve found that such automation is most useful when switching between branches in source control. Without automation, you have to manually kill and reconstruct any Django shell and development server instances for each branch (and

Self-Reliant Veganism

“Trust thyself: every heart vibrates to that iron string.” When I first read “Self-Reliance,” these words sunk into me, but I must have skimmed the rest of the essay. Emerson’s style and vocabulary put me off, an experience which I attributed to 150 years of drift in the English language. The problem only got worse

No More Supermarket Blues

A few weeks ago, Kim and I were riding home from our weekly trip to Fred Meyer, and I had an epiphany: I never wanted to go back. Kim wasn’t fond of Fred Meyer, either, so we hatched a plan to limit how much time we spent at the supermarket, and how much we bought,