Skip to content

Instantly share code, notes, and snippets.

@migurski
migurski / Mercator.ipynb
Last active January 8, 2019 17:57
Mercator Projection with GDAL
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@migurski
migurski / VA.geojson
Created November 1, 2018 17:22
Sample Virginia PlanScore model tiles
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@migurski
migurski / 13-2333-3172.geojson
Created November 1, 2018 17:16
Sample Virginia PlanScore model tile 13/2333/3172
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@migurski
migurski / 10-285-394.geojson
Created November 1, 2018 17:15
Sample Virginia PlanScore model tile 10/285/394
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@migurski
migurski / brooklynt.sql
Last active July 26, 2018 04:55
Use Brooklyn Integers directly in Postgres
--
-- Table of available integers with a boolean column for when they're used up.
--
DROP TABLE IF EXISTS brooklyn_integers;
CREATE TABLE brooklyn_integers (used BOOLEAN DEFAULT false NOT NULL, value BIGINT NOT NULL);
CREATE INDEX brooklyn_integers_used ON brooklyn_integers (used);
CREATE UNIQUE INDEX brooklyn_integers_value ON brooklyn_integers (value);
--
-- Request a single unused integer and mark it used.
@migurski
migurski / openelections-table.py
Created December 7, 2017 16:50
Convert WI ward-level result CSVs from OpenElections to tabular format
''' Convert ward-level result CSVs from OpenElections to tabular format.
'''
import gzip, csv, collections, sys, itertools
def key1(row):
''' Outer key is the county and ward.
'''
return row['county'], row['ward']
def key2(row):
@migurski
migurski / intersect-areas.py
Created October 29, 2017 17:45
Intersect North Carolina voting precincts with Census tracts to get selected area-weighted race, income, and education statistics
import psycopg2, csv, math
with psycopg2.connect('postgres:///redistrict_nc') as conn:
with conn.cursor() as db:
for year in ['2016', '2014', '2012']:
with open(f'{year}-4.txt') as in_file, open(f'{year}-5.txt', 'w') as out_file:
in_rows = csv.DictReader(in_file, dialect='excel-tab')
out_fields = in_rows.fieldnames + ['Non-Hispanic White',
'Non-Hispanic White, Error', 'College', 'College, Error',
@migurski
migurski / openelections-table.py
Last active December 7, 2017 16:50
Convert NC precinct-level result CSVs from OpenElections to tabular format
''' Convert precinct-level result CSVs from OpenElections to tabular format.
'''
import gzip, csv, collections, sys, itertools
def key1(row):
''' Outer key is the county and precinct.
'''
return row['parent_jurisdiction'], row['jurisdiction']
def key2(row):
@migurski
migurski / make-gpwv4-us.py
Created April 28, 2017 21:52
Script to bake gridded U.S. population based on ACS 5-year data
from osgeo import ogr
import requests, zipfile, io, tempfile, shutil, os, sys, csv, math, collections
state_codes = {
'01': 'AL', '31': 'NE', '02': 'AK', '32': 'NV', '04': 'AZ', '33': 'NH',
'05': 'AR', '34': 'NJ', '06': 'CA', '35': 'NM', '08': 'CO', '36': 'NY',
'09': 'CT', '37': 'NC', '10': 'DE', '38': 'ND', '11': 'DC', '39': 'OH',
'12': 'FL', '40': 'OK', '13': 'GA', '41': 'OR', '15': 'HI', '42': 'PA',
'16': 'ID', '72': 'PR', '17': 'IL', '44': 'RI', '18': 'IN', '45': 'SC',
'19': 'IA', '46': 'SD', '20': 'KS', '47': 'TN', '21': 'KY', '48': 'TX',

Keybase proof

I hereby claim:

  • I am migurski on github.
  • I am migurski (https://keybase.io/migurski) on keybase.
  • I have a public key whose fingerprint is 2D09 CC12 CFAF 908F 40D2 A4BC 6658 C0CD 757E 9D53

To claim this, I am signing this object: