> /dev/null

Interesting hacks, snippets, and shortcuts.

Mar 31

The Monty Hall problem

The Monty Hall problem is a somewhat counterintuitive probability problem loosely modeled after the game show "Let's make a deal". Here's the setup:

You're presented with 3 doors. Behind one of the doors is a bran...

Apr 14

Weird screenshot issue on OS X

While working on my previous post, I ran into an annoying issue.

In OS X, you can take a screenshot of an individual window pressing Cmd-Shift-4 followed by the the spacebar. Screenshots taken this way look quite good; they even include the drop shadow.

Individual window screenshot

Unfortunately, it turns out that the shadow changes size depending on whether the window is in focus.

Here is a window that has focus:

In focus

And here is one that doesn't:

Out of focus

The red border is drawn around the actual edge of the image. Those windows are...

Apr 14

Keeping your AWS credentials safe on the command line

Sometimes you need run tasks locally that connect to AWS. If this is touching a real system, you don't want to leave the credentials sitting in clear text. Fortunately, Apple's keychain has a command line interface that lets you access securely stored passwords.

Here are some simple steps to put your AWS credentials in the environment only for commands that need them.

1. Create a Keychain entry for your secret key

Go into Keychain Access (/Applications/Utilities/Keychain Access.app) and add a ...

Jan 2

Managing $PYTHONPATH on Heroku

I have a Flask application that I wanted to host on Heroku. This is normally very simple, but I put my code in a src/ subdirectory which means I need $PWD/src on my PYTHONPATH.

Googling reveals some people adding a Heroku config variable like so:

heroku config:add PYTHONPATH=...

I don't like this solution for 2 reasons. First, I have to already know the existing $PYTHONPATH and well as the path to...

Nov 7

Quickly activate a virtualenv

Here is a small bash function that serches for a virtualenv on your current path and activates it for you. To use it, simply type ve. If your virtualenv is named something besides 've', pass its name as the first argument: ve my_env.

ve() {
    local curdir ve
    [ -z "$1" ] && ve="ve" || ve="$1"
    while ! ls -d "$ve" >/dev/null 2>&1; do
        if [ "$PWD" == "/" ]; then
            echo "Cannot find a '$ve' directory on the current path" >&2
            cd $curdir
Oct 27

Repairing an LCD TV

After almost 6 years of service, my TV (a Samsung LNT4065F in case you are googling this problem) stopped working. It died slowly. Over the course of many months, it would take longer to come on each time. Eventually, I could expect to wait five minutes from pressing the power button to being able to use the TV. Then it started to not come on at all. Sometimes, instead of the image, I would just get vertical bands of color:

My TV on its deathbed

As a rule of thumb, when I see electronics behaving like this, I suspect bad capacitors. I opened up...

Oct 24

Using arguments from the previous command

One of my favorite bash tricks is the ability to grab the last argument of the previous command with <ESC>.

$ vim program.sh
$ chmod +x <ESC>.
$ ./<ESC>.

But what if you need other arguments than just the last one? You can specify an argument number. For example <ESC>1<ESC>. gets you the first argument for your command.

$ mv foo bar
$ mv <ESC>. <ESC>1<ESC>. # rename bar back to foo

As a bonus, <ESC>0<ESC>. gets the previous command itself.

The Meta Key

If your terminal is configured for it, you can save time...

Apr 14

A git alias to PEP-8 the files you have changed

Add the following section to your .git/config and you will get the new command git pep8, which will run the files you have changed through pep8.

As a bonus, I also included the alias to do the same with pyflakes.

Thanks to Robert Morris for the idea to make these functions into aliases.

Jun 30

Estimate your 2012 taxes

This ruby function takes it your expected gross income and estimates your taxes (not including deductions and credits).

May 12

Run 32 Bit Python Libraries

Today I learned it is trivial to get python running in 32 bit mode. All you have to do is:


and then run your program normally.

Page 1 of 2