Skip to content

Instantly share code, notes, and snippets.

View rolandcrosby's full-sized avatar

Roland Crosby rolandcrosby

View GitHub Profile
@rolandcrosby
rolandcrosby / csvfix.py
Last active December 12, 2018 21:05
csv preprocessor
import sys
# CSV cleaner-upper to change CRLF terminations to LF, and to avoid quoting empty strings
# inspired by https://github.com/mhus/mhus-lib/blob/master/mhu-lib-core/src/main/java/de/mhus/lib/core/io/CSVReader.java
# usage: python csvfix.py < in.csv > out.csv
def parse_field(char, state="start", acc=""): # returns (new_state, new_acc)
if state == "start":
if char == ",":
return ("eof_u", acc)
@rolandcrosby
rolandcrosby / twitter-archive-search.sh
Created January 26, 2019 18:22
search your twitter archives
#!/usr/bin/env bash
# expects you to have your twitter archive folders in $dir
# with folder names like "acct1 2019-01-26" so they sort nicely
set -euo pipefail
dir='path/to/archives'
accts='acct1 acct2'
query="$*"
@rolandcrosby
rolandcrosby / muji-a5-letter-paper.svg
Created February 3, 2019 22:35
position of lines on Muji A5 letter paper
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rolandcrosby
rolandcrosby / muji.sh
Created May 26, 2019 18:23
fetch all the room photos from the muji hotel website
#!/usr/bin/env bash
set -x
for city in ginza shenzhen beijing; do
for room in {a..z} ; do
pic=0
while true; do
((pic++))
fn="${room}_${pic}.jpg"
curl --fail "https://hotel.muji.com/${city}/wp-content/themes/mujihotel${city}/img/rooms_type_$fn" -o "${city}_${fn}"
@rolandcrosby
rolandcrosby / basis_door.rb
Created June 2, 2019 14:20
SketchUp script to generate cabinet door/drawer fronts in the style of Reform's Basis design
def basis_door(width, height, cx=2.0, cy=2.0)
# Measurements from https://www.reformcph.com/us/design/basis/
lin_depth = 5.0/64
oak_depth = 3.0/4
hole_depth = 5.0/8
radius = (1 + 5.0/8) / 2
model = Sketchup.active_model
door = model.active_entities.add_group
@rolandcrosby
rolandcrosby / gtfs.sql
Last active August 19, 2019 03:27
CockroachDB 19.2 IMPORT INTO with GTFS data
-- IMPORT INTO for GTFS data (e.g. http://transitfeeds.com/p/mta/87)
create table agencies (
agency_id int primary key,
agency_name string,
agency_url string,
agency_timezone string,
agency_phone string,
agency_lang string
);
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 16 columns, instead of 7. in line 8.
PID,Designation,State,County,Latitude,Longitude,USGS Quad,First City,Second City,Beacon #,Airport?,Arrow?,Airway,Status,Report,
TT6703,LADD FIELD AIRWAY BEACON,AK, ,64.8393467,-147.6422778,FAIRBANKS D-2, , , ,N,N, ,Undetermined NGS beacon/arrow,,
UV1481,MENDENHALL PENPOLE OBS LT,AK, ,58.36027612,-134.6373542,JUNEAU B-2, , , , , , ,Undetermined NGS beacon/arrow,,
UV1482,MENDENHALL PEN TWR OBS LT,AK, ,58.36558586,-134.6345829,JUNEAU B-2, , , , , , ,Undetermined NGS beacon/arrow,,
UV1489,MENDENHALL PENINSULA AWY BCN,AK, ,58.35891469,-134.6378411,JUNEAU B-2, , , ,N,N, ,Undetermined NGS beacon/arrow,,
UV8118,BETHEL CAA AIRFIELD AIRWAY BCN,AK, ,60.77455235,-161.7225519,BETHEL D-8, , , ,Y,N, ,Undetermined NGS beacon/arrow,,
UV8494,ANIAK AIRWAY BEACON,AK, ,61.5781849,-159.5386466,RUSSIAN MISSION C-2, , , ,N,N, ,Undetermined NGS beacon/arrow,,
UW5259,AIR BCN,AK, ,71.32724161,-156.6789262,BARROW B-4, , , ,N,N, ,Undetermined NGS beacon/arrow,,
BG4136,ATLANTA MOBILE AWY BCN 15,AL,BALDWIN,30.96132667,-87.70389309,DYAS (19
const childProcess = require("child_process");
function gitCmd(args) {
const cmd = childProcess.spawnSync("/usr/local/bin/git", args);
return cmd.stdout.toString().split("\n");
}
function commitsForPath(path) {
return gitCmd(["rev-list", "--format=oneline", "--all", path])
.map(x => [x.substr(0, 40), x.substr(41)])
city population area_sqmi
San Francisco 884363 46.873
Brooklyn 2622000 96.92
Queens 2322000 178.2
Manhattan 1636000 33.59
Staten Island 474248 102
Bronx 1438000 57.48
Chicago 2716000 227.6
Paris 2206000 40.5
@rolandcrosby
rolandcrosby / countypres_2000-2016.tab
Created December 8, 2019 03:42
MIT Election Data and Science Lab, 2018, "County Presidential Election Returns 2000-2016", https://doi.org/10.7910/DVN/VOQCHQ, Harvard Dataverse, V6, UNF:6:ZZe1xuZ5H2l4NUiSRcRf8Q== [fileUNF]
This file has been truncated, but you can view the full file.
year state state_po county FIPS office candidate party candidatevotes totalvotes version
2000 "Alabama" "AL" "Autauga" 1001 "President" "Al Gore" "democrat" 4942 17208 20191203
2000 "Alabama" "AL" "Autauga" 1001 "President" "George W. Bush" "republican" 11993 17208 20191203
2000 "Alabama" "AL" "Autauga" 1001 "President" "Ralph Nader" "green" 160 17208 20191203
2000 "Alabama" "AL" "Autauga" 1001 "President" "Other" "NA" 113 17208 20191203
2000 "Alabama" "AL" "Baldwin" 1003 "President" "Al Gore" "democrat" 13997 56480 20191203
2000 "Alabama" "AL" "Baldwin" 1003 "President" "George W. Bush" "republican" 40872 56480 20191203
2000 "Alabama" "AL" "Baldwin" 1003 "President" "Ralph Nader" "green" 1033 56480 20191203
2000 "Alabama" "AL" "Baldwin" 1003 "President" "Other" "NA" 578 56480 20191203
2000 "Alabama" "AL" "Barbour" 1005 "President" "Al Gore" "democrat" 5188 10395 20191203