Skip to content

Instantly share code, notes, and snippets.

@migurski
migurski / check-internal-links.py
Created January 30, 2014 06:48
Scripts used in the creation of the new Code for America website.
@migurski
migurski / well-known-status.py
Last active August 29, 2015 13:56
Engine Light status endpoint script for www.codeforamerica.org
#!/usr/bin/env python
from json import dumps
from time import time
try:
lib_state = open('/var/run/library-state.txt').read().strip()
if lib_state != 'OK':
app_state = 'Library: ' + lib_state
else:
@migurski
migurski / conform.py
Last active August 29, 2015 14:07
Python wrapper for openaddresses-conform
''' Python wrapper for openaddresses-conform.
Looks in /var/opt/openaddresses-conform for an index.js to run. Generates
all data in a temporary working directory, and does not use cached files.
'''
from subprocess import Popen
from tempfile import mkdtemp
from os.path import realpath, join
from shutil import move, rmtree
.../~: Sleeper% cd /tmp
...//tmp: Sleeper% mkdir vn
...//tmp: Sleeper% rmdir vn
...//tmp: Sleeper% mkdir van
...//tmp: Sleeper% virtualenv van
New python executable in van/bin/python
Installing setuptools, pip...done.
...//tmp: Sleeper% source van/bin/activate.csh
[van] ...//tmp: Sleeper% pip install https://github.com/openvenues/address_normalizer
You are using pip version 6.0.3, however version 6.0.6 is available.
@migurski
migurski / data.acgov.org.txt
Created January 13, 2015 01:53
Socrata HTTP Gripes
% curl -sIL 'https://data.acgov.org/api/geospatial/8e4s-7f4v?method=export&format=Original'
HTTP/1.1 405 Method Not Allowed
Server: nginx
Date: Tue, 13 Jan 2015 01:52:36 GMT
Connection: keep-alive
Access-Control-Allow-Origin: *
X-Error-Code: method_not_allowed
X-Error-Message: HEAD not allowed
X-Socrata-Region: production
@migurski
migurski / guess.py
Created January 28, 2015 18:32
guess reason for OpenAddresses failure
def guess_reason(log):
'''
'''
if 'JobTimeoutException' in log:
return 'took too long'
elif 'DownloadError: 404 response' in log:
return 'missing source'
elif 'Source says to skip' in log:
return 'skipped'
elif 'Invalid number of points in LinearRing' in log:
@migurski
migurski / squares-map.js
Created March 3, 2015 04:50
Compiled TypeScript sample
var Map = (function () {
function Map(parent, template, proj, loc, zoom) {
this.selection = d3.select(parent);
this.loaded_tiles = {
};
this.template = template;
this.parent = parent;
var size = Mouse.element_size(this.parent), coord = proj.locationCoordinate(loc).zoomTo(zoom);
this.grid = new Grid.Grid(size.x, size.y, coord, 3);
this.projection = proj;
@migurski
migurski / index.html
Last active August 29, 2015 14:17
Grabbing census tracts around Oakland, messing with Turf
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Untitled</title>
<script src="https://code.jquery.com/jquery-1.11.2.min.js" charset="utf-8"></script>
<script src="modestmaps.min.js" charset="utf-8"></script>
<script src="turf.min.js" charset="utf-8"></script>
</head>
<body>
@migurski
migurski / stats2runs.py
Created July 23, 2015 05:54
Converting from OpenAddresses stats table to runs and sets table
from __future__ import print_function
from os import environ
from psycopg2 import connect
from psycopg2.extras import DictCursor, Json
from itertools import count, groupby
from datetime import timedelta, datetime
from operator import itemgetter
from uritemplate import expand
from dateutil.parser import parse
> make PKG_CONFIG_PATH=/home/migurski/src/simple-tiles/out/lib/pkgconfig test
cd src && make all
make[1]: Entering directory `/home/migurski/src/simple-tiles/src'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/migurski/src/simple-tiles/src'
cd test && make test
make[1]: Entering directory `/home/migurski/src/simple-tiles/test'
cd ../data && make && cd ../test
make[2]: Entering directory `/home/migurski/src/simple-tiles/data'