Skip to content

Instantly share code, notes, and snippets.

@fitnr
fitnr / 2014-primary-gov.csv
Last active September 14, 2018 16:58
NYS democratic primary results for nyc
electdist county cuomo teachout credico
65001 New York 2 3 0
65002 New York 16 23 0
65003 New York 5 6 0
65004 New York 2 4 0
65005 New York 30 8 3
65006 New York 43 41 5
65007 New York 44 32 2
65008 New York 53 47 5
65009 New York 6 6 0
@fitnr
fitnr / mtfcc.csv
Created August 3, 2018 14:46
CSV copy of US Census MTFCC code list https://www.census.gov/geo/reference/mtfcc.html
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 7.
MTFCC,Feature Class,Superclass,Point,Linear,Areal,Description
C3022,Mountain Peak or Summit,Miscellaneous Topographic Features,Y,N,N,A prominent elevation rising above the surrounding level of the Earth's surface.
C3023,Island,Miscellaneous Topographic Features,Y,Y,Y,"An area of dry or relatively dry land surrounded by water or low wetland. [including archipelago, atoll, cay, hammock, hummock, isla, isle, key, moku and rock]"
C3024,Levee,Miscellaneous Topographic Features,N,Y,Y,An embankment flanking a stream or other flowing water feature to prevent overflow.
C3026,"Quarry (not water-filled), Open Pit Mine or Mine",Miscellaneous Topographic Features,Y,N,Y,An area from which commercial minerals are or were removed from the Earth; not including an oilfield or gas field.
C3027,Dam,Miscellaneous Topographic Features,Y,Y,Y,A barrier built across the course of a stream to impound water and/or control water flow.
C3061,Cul-de-sac,Miscellaneous Topographic Features,Y,N,N,"An expanded paved area at the end of a stree
SHELL = bash
raster = elevation/ned/ned.vrt
vector = water/WBD/WBD.gdb
layer = 10
# ids = $(shell ogrinfo build basins -q -fields=YES -geom=NO | grep HUC$(layer) | cut -d = -f 2 | xargs)
ids = 0202000503 0202000504 0202000505 0202000506 0202000507 0202000601 0202000602 0202000603 0202000604 0202000605 0202000607 0202000608 0202000609 0202000611 0202000703 0202000704 0202000705 0202000706 0202000801 0202000802 0202000803 0202000804 0202000805 0203010101 0203010202 0203020101 0203020102 0203020103 0203020104 0203010405 0203020202 0203020203 0203020204 0203020205 0203020206 0203020207 0203020208 0203020209 0204010101 0204010102 0204010105 0204010201 0204010202 0204010203 0204010204 0204010205 0204010401 0204010402 0205010101 0205010102 0205010103 0205010104 0205010105 0205010106 0205010107 0205010108 0205010109 0205010110 0205010111 0205010112 0205010201 0205010202 0205010203 0205010204 0205010205 0205010206 0205010207 0205010208 0205010301 0205010303 0205010304 0205010305 0205010306 0205010401 0205010402 0205
@fitnr
fitnr / brew.info.json
Last active March 12, 2018 19:37
patch for Homebrew postgis formula to rely on gdal2
[
{
"name": "gdal2",
"full_name": "osgeo/osgeo4mac/gdal2",
"desc": "GDAL: Geospatial Data Abstraction Library",
"homepage": "http://www.gdal.org/",
"oldname": null,
"aliases": [
"gdal-20"
],
@fitnr
fitnr / insert.sql
Last active November 10, 2019 16:02
Example of inserting missing service_id into a GTFS
INSERT INTO gtfs.calendar (feed_index, service_id, monday, tuesday, wednesday, thursday, friday, saturday, sunday, start_date, end_date)
SELECT a.feed_index, a.service_id, monday, tuesday, wednesday, thursday, friday, saturday, sunday, start_date, end_date
FROM (
SELECT feed_index, service_id
FROM gtfs.trips a
LEFT JOIN gtfs.calendar b using (feed_index, service_id)
WHERE COALESCE(b.monday, b.friday) IS NULL
GROUP BY feed_index, service_id
) a
INNER JOIN gtfs.calendar b ON a.feed_index = b.feed_index AND (
@fitnr
fitnr / query.sql
Created June 28, 2017 19:54
simple SQL clipping for four sections of US: Alaska, contiguous states, Hawaii, and Puerto Rico & the USVI.
SELECT * FROM table WHERE (
(
lat > 51 AND lat < 71.5
AND ((
lon > -180 AND lon < -129
) OR (
lon > 172 AND lon < 180
))
) OR (
lat > 24 AND lat < 49.5
#!/usr/bin/env python3.5
import os
import sys
from urllib.parse import urlsplit
from requests import Session
from transitfeeds import TransitFeeds
listing = sys.argv[1]
feed_ids = sys.argv[2:]
urls = []
@fitnr
fitnr / add_diacretics.py
Last active May 19, 2017 16:12
Make your text wide and imposing using Python 3. A̮̍d̦ͭd̳̓ cͮͅr̊͡ä̫́zͬ̈́y͉͓ dͤ̕iͦ̃a̧̬c̢̙r͊̄e͞ͅt̳̔i̦̓c̩͜s͚̲ t̴͙o̢̬ y̞͟o͕͟u̬̖r̴̬ t͓̭é͟x̗͊t̥͉
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import string
from random import sample
# Add random diacretics to a text
diacretics = [chr(x) for x in range(0x300, 0x36F)]
# don't add marks to whitespace or punctuation
reserved = ' ' + string.whitespace + string.punctuation
@fitnr
fitnr / Makefile
Last active May 12, 2017 01:31
Results for the 2017 South Korean presidential election. Scraped from [Naver.com](http://news.naver.com/main/election/president2017/result/index.nhn), processed with
#
# Requirements: ogr2ogr (GDAL) and jq, as well as basic bash tools (echo, curl, cat)
#
provinces = 42 43 44 11 26 27 28 29 31 51 41 45 46 47 48 49 30
SELECT = SELECT key, name, \
SUM(CASE WHEN candidate = '김민찬' THEN vote ELSE 0 END) AS kimminchan, \
SUM(CASE WHEN candidate = '김선동' THEN vote ELSE 0 END) AS kimsundong, \
SUM(CASE WHEN candidate = '문재인' THEN vote ELSE 0 END) AS moon, \
SUM(CASE WHEN candidate = '심상정' THEN vote ELSE 0 END) AS sang, \
@fitnr
fitnr / presidential_17.csv
Created April 26, 2017 19:44
Résultats de le 1er tour de la présidentielle 2017, a niveau de commune / Commune-level results of the first round of the 2017 French presidential election
We can't make this file beautiful and searchable because it's too large.
commune,votes,le_pen,macron,fillon,melenchon,dupont_aig,hamon,asselineau,arthaud,poutou,cheminade,lassalle
01001,495,126,119,110,59,34,29,6,4,4,2,2
01002,176,48,37,34,33,6,13,1,2,2,0,0
01004,6452,1667,1332,1084,1412,346,344,71,40,91,5,60
01005,933,306,191,197,126,45,37,10,5,10,0,6
01006,77,18,15,14,19,4,3,0,1,2,0,1
01007,1548,458,348,233,296,80,82,11,9,17,1,13
01008,473,135,95,84,89,28,23,2,3,8,3,3
01009,209,40,55,44,39,6,8,6,0,3,0,8
01010,589,207,110,83,103,33,20,10,3,5,1,14