Skip to content

Instantly share code, notes, and snippets.

import re
import cairo
import bezier
import numpy
import itertools
# https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#path
paths = [
'''M500.04,309.630308 C817.696558,309.630308 931.823304,522.666719 936.58,532.180112 L936.58,549.295931 C931.824662,557.855539 817.696558,770.894667 500.04,770.894667 C182.383442,770.894667 68.2566964,557.858256 63.5,548.344863 L63.5,531.229044 C68.2553377,522.669436 182.383442,309.630308 500.04,309.630308 Z M520.015815,422.809043 L520.015815,422.806648 C524.766058,399.02996 514.304315,374.305261 494.342086,360.983862 L494.342086,360.035189 C475.315641,360.991352 456.295139,367.645088 440.12784,378.107171 C424.909061,388.570612 412.543655,402.840022 403.985575,419.955841 C407.793242,444.686993 425.863525,464.656354 450.589583,469.413051 C482.924181,476.067127 513.355115,455.143641 520.015815,422.809043 Z M357.379869,438.976342 L357.373076,438.975833 C364.033945,404.737401 383.053598,375.254308 409.690282,354.330822 C375.451851,359.086159 344.064924,367.644748 3
@migurski
migurski / OSMF-2021-Survey.qgz
Last active February 27, 2021 00:03
OSMF 2021 Survey Regions
@migurski
migurski / generate-boards.py
Created May 17, 2020 18:33
Generate Codenames board in Google Sheets
#!/usr/bin/env python3
import json
import random
import copy
import argparse
import oauth2client.service_account
import apiclient.discovery
parser = argparse.ArgumentParser()
parser.add_argument('players')
@migurski
migurski / Mercator.ipynb
Last active January 8, 2019 17:57
Mercator Projection with GDAL
Loading
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
Loading
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
Loading
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
Loading
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',