Skip to content

Instantly share code, notes, and snippets.

View palewire's full-sized avatar

Ben Welsh palewire

View GitHub Profile
@palewire
palewire / roundint2precision.py
Created November 15, 2011 20:31
Rounding an integer to precision of "significant digits"
def roundint2precision(value, count):
"""
Accepts an integer and rounds it to the nearest number
at the specified precision, measured in "significant digits."
Example usage:
>> roundint2precision(1211111, 2)
1200000
>> roundint2precision(1211111, 3)
@palewire
palewire / stripdict.py
Created December 13, 2011 05:12
Strip leading and trailing whitespaces in dictionary keys and values
def strip_dict(d):
"""
Strip all leading and trailing whitespace in dictionary keys and values.
"""
return dict((k.strip(), v.strip()) for k, v in d.items())
import csv
from googlegeocoder import GoogleGeocoder
geocoder = GoogleGeocoder()
data = list(csv.DictReader(open('/home/ben/Downloads/latest.csv', 'r')))
outfile = open("out.csv", "w")
s = "%s, %s"
for row in data:
a = s % (row['Address'], row['Zip'])
@palewire
palewire / golive.py
Created January 4, 2012 18:36
A quick Python script for rolling through the DcoumentCloud error attachment and setting everything live.
"""
Before you can use this, install the @LATdatadesk DocumentCloud wrapper for Python. Like so:
$ sudo pip install python-documentcloud
"""
import csv
from documentcloud import DocumentCloud
path = '/home/ben/Desktop/docs.csv'
data = csv.DictReader(open(path, 'r'))
@palewire
palewire / fabfile.py
Created January 17, 2012 03:30
fab bootstrap
from fabric.api import *
from openstack.compute import Compute
def bootstrap():
install_chef()
update_chef()
def install_chef():
"""
Install Chef on your server
@palewire
palewire / pgfail.log
Created January 24, 2012 10:06
Weird postgres errors
In my Django error messages...
File "/apps/projects/lib/django/db/models/sql/query.py", line 2347, in execute_sql
cursor.execute(sql, params)
OperationalError: could not write block 341 of temporary file: No space left on device
HINT: Perhaps out of disk space?
...
@palewire
palewire / LOCATING_THE_STORY.textile
Created January 30, 2012 23:59
Locating the story: The latest in mapping.

Locating the story: The latest in mapping

A collection of links for a NICAR 2012 presentation. It will suggest broad themes for the past year, and try to support them with examples from work in the field. This is a work in progress. Feel free to crap on it, or add your own ideas.

Escape from Google Maps

  • Google changed the rules of the game. There are now usage limits. Read about them here
  • TileMill, custom tiles, need examples
  • Links to ranty blog posts from Nestoria guy and others
  • One replacement is simple line maps drawn using HTML5 technologies like SVG, Canvas and VML. You saw this example a lot in election maps during the GOP primaries, like NYT, WaPo, HuffPo, LAT
@palewire
palewire / settings.py
Created February 4, 2012 21:50
My current default Django LOGGING configuration
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
},
'null': {
'level':'DEBUG',
@palewire
palewire / vacuumdb.sh
Created February 10, 2012 20:50
vacuumdb.sh
/bin/su postgres -c "/usr/bin/vacuumdb --analyze --dbname <dbname>"
@palewire
palewire / WTF.py
Created February 20, 2012 19:24
WTF.py
File "/home/ben/Code/.../lib/python2.7/codecs.py", line 984, in getreader
return lookup(encoding).streamreader
LookupError: unknown encoding: r