Setting environment variables in a Python virtualenv from a .env file

Lately, I’ve gotten into the practice of storing configuration in environment variables and keeping those in a .env file in the root of my project directory.

This file contains simple environment variable assignment and is used by Heroku and Docker.

However making sure these environment variables get set for any command being run in the development environment.

I often work in Python virtual environments, so putting the shell commands in the postactivate and postdeactivate scripts makes sense to me.

To set environment variables in postactivate:

# This hook is sourced after this virtualenv is activated.
cd ~/workspace/scrape-represent-statements
set -a
source .env
set +a

To unset environment variables in postdeactivate:

# This hook is sourced after this virtualenv is deactivated.
while read var; do unset $var; done < <(cat .env | grep -v '^\s*#' | sed  's/\s*\([^=]*\)=.*/\1/')

Music for early March


While in Mexico City, I went to “El Chopo”, a punk street market and got an Eskorbuto patch. It made me excited to listen to this band.

Smino – S!CK S!CK S!CK EP

Smino is a Chicago (via St. Louis) rapper performing March 2 as part of “The Come Up” series.

Watercolor Paintings – Red Scarf

My friend Mooj, who’s all over a bunch of cool radio/podcast projects made this music video.

Watercolor Paintings – Red Scarf from Zadie on Vimeo.

Muncie Girls – From Captain to Belsize

I read an article about this band that a friend shared on Facebook and they sounded really interesting.

Upgrading Homebrew-installed Postgres 9.3 to 9.5

I didn’t read the instructions when I let PostgreSQL get upgraded from 9.3 to 9.5 with brew upgrade. This is what I had to do to migrate my data after I had already upgraded:

# Switch back to the previous version of postgres, postgis
brew switch postgres 9.3.5_1
brew switch postgis 2.1.4_1
# Start the server (run this in a separate shell)
postgres -D /usr/local/var/postgres
# Dump all my databases
pg_dumpall > pg_dump
# Stop the server
pg_ctl -D /usr/local/var/postgres stop
# Switch back to the up-to-date version of postgres, postgis
brew switch postgresql 9.5.0
brew switch postgis 2.2.1
# Move the old data directory out of the way
mv /usr/local/var/postgres/ /usr/local/var/postgres9.3
# Initialize the data directory for Postgres 9.5
initdb /usr/local/var/postgres
# Start the server
postgres -D /usr/local/var/postgres
# Import the database dump
psql -d postgres -f pg_dump
# Delete the dump file
rm pg_dump
# Stop the server
pg_ctl -D /usr/local/var/postgres stop
# Start the server with launchctl
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist


I played three different shows, with three different bands in 48 hours. So different playing for a handful of folks below the Loyola Red Line, in a crowded basement and on a giant stage. It was a hectic weekend, but ultimately, after the dust settled, I feel lucky to get to do all this.

Defiance, Ohio playing at the Fest, 2015.  Photo by @jimmyvague (

Defiance, Ohio playing at the Fest, 2015. Photo by @jimmyvague (

“Rabbit Bucket” playing next to the Loyola Red Line. Photo by Roberta.

Defiance, Ohio playing at the Fest, 2015.  Photo by @waxwingsmusic (

Defiance, Ohio playing at the Fest, 2015. Photo by @waxwingsmusic (

Property tax increases and renters

There’s been a lot of coverage of the mayor’s property tax increase, and some provisions to reduce the burden on low-to-moderate income homeowners. My first thought went to renters, though:


In-real-life data visualization of Chicago Budget


Originally from:

Sincere. Fucking. Curiosity. Above all things.

New Music for Early August

Janelle Monáe + Wondaland Records – Hell You Talmbout

This references a bonus track off of Monae’s 2013 release, I think.

Mick Jenkins – Wave[s]

Mother Cyborg – Tough Femme Mix

Aye Nako – White Noise

Here’s a Pitchfork review of the track. From the review:

Dixon elaborated on the song, saying it’s about how “whiteness is centered in everything, how it taught me to hate myself for being black, how when I was a kid I used to pray to God that I could be white… how it scares me that white supremacy doesn’t even need white people to perpetuate it.”

Tunde Olaniran – Transgressor


Gold Paint Boy – little engine

Programmatically reshaping data

Yesterday at work, my coworker needed to reshape a data table, from CSV. The data was a time series, with one row per date. He wanted to reshape the data so there was one row per day of the year with a column for the desired variable for each year. He observed that there were 93 distinct days of the year for each year and used some clever Excel functions and auto-fills to do this in about 5 minutes. I spend considerably more time figuring out how to do this in PostgreSQL, Python and R.

CPS School Budgets


On Monday, July 13, 2015, Chicago Public Schools (CPS) released preliminary spending plans for the 2015-2016 school year. Many schools face significant budget cups. We made a simple [news app to let users explore how different school budgets changed](

Additional coverage:

* [CPS Budget: Deep Cuts For Neighborhood Schools, Cash Infusion For Charters]( (DNAinfo Chicago)
* [Chicago Public Schools’ budgets spend $500 million district doesn’t have](