Skip to content

Instantly share code, notes, and snippets.

View johan's full-sized avatar

Johan Sundström johan

View GitHub Profile
@johan
johan / index.html
Last active October 5, 2017 13:45
People in congress sponsored by the NRA in the 2016 cycle
<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<base href="https://ballotpedia.org/">
<title>NRA Sponsored US Members of Congress</title>
</head><body>
<h1>NRA Sponsored US Members of Congress</h1>
Sources: these tables were compiled on October 4, 2017 from the
#! /bin/sh
# path to your unzipped Facebook html/friends.htm file
friends="$1"
year=$(
egrep -o '<div class="footer">Downloaded by .* on \w+, \d+ \w+ (\d+)' "$friends" \
| awk '{print $NF}'
)
@johan
johan / .gitconfig
Last active July 12, 2017 17:42
git swap - swaps top two commits; git drop [revision] - nukes that revision (or HEAD); git hoist <revision> - rebases that revision to be the most recent commit, so you can tweak it
[alias]
swap = "!GIT_SEQUENCE_EDITOR=\"sed -i '' -n 'h;1n;2p;g;p'\" git rebase -i HEAD~2"
drop = "!f() { GIT_SEQUENCE_EDITOR=\"sed -i '' '/^pick '$(git log -n 1 --pretty='%h' ${1:-HEAD})/d\" git rebase -i ${1:-HEAD}^^; }; f"
hoist = "!f() { GIT_SEQUENCE_EDITOR=\"git log -n 1 --pretty='pick %h' $1|~/bin/hoist-lines.pike\" git rebase -i $1^; }; f"
_git_commit ()
{
case "$prev" in
(-c | -C) __gitcomp_nl "$(__git_refs)" "" "${cur}"
return ;;
(-m) __gitcomp "feat: fix: docs: style: refactor: test: chore:
" "" "${cur}"
return
;;
esac
#! /bin/sh
# git-fold (a k a "git fold") fetches the main branch upstream,
# and if your current branch has already been landed upstreams,
# then check out the master branch, delete the landed branch,
# and catch up master with origin
# optional reference branch to check folding against and move to - or master
master="${1:-master}"
@johan
johan / index.html
Created April 13, 2017 18:27
HTML5 drag/drop
<html>
<head>
<title>HTML5 drag/drop files to console.log them</title>
</head>
<body>
<script>
// this should probably be a more interesting function in your case
function show(...files) {
console.log(...files);
@johan
johan / mac-specs.sh
Created March 3, 2017 01:13
mac-specs
#! /bin/sh
# runs on any mac, gives its apple specs
curl -is https://support.apple.com/en-us/HT201300 \
| grep -B 1 $( system_profiler SPHardwareDataType -detailLevel mini \
| awk '/Model Identifier/ { print $3 }' \
) \
| egrep -o '<a href=.*</a>'

EUREKA

1: Prehistoric Man

S, T!, N, E, T, E, U, T!, S!, T, M AXE (from flint and bone),
SW, T!, W!, W!, SE!, J! (the tyrannosaurus falls into the hole),
SW, W, T, E, E, J (over the hole),
S, SE, CUT TREE, M RAFT (from trees and creeper),
E, E, L (you see a stairway),
@johan
johan / Makefile
Created January 24, 2017 06:15
Makefile of the steps in Mike Bostock's command-line cartography tutorial, parts 1-4 https://medium.com/@mbostock/command-line-cartography-part-1-897aa8f8ca2c
# request one at http://api.census.gov/data/key_signup.html and paste it below
CENSUS_API_KEY=YOUR_CODE_HERE
# a factor 1609.34 squared
SQ_M_TO_SQ_MI=2589975.2356
#prereqs:
# npm install -g shapefile # 0.6.1
# npm install -g d3-geo-projection # 1.2.1
# npm install -g ndjson-cli # 0.3.0
@johan
johan / LICENSE
Created January 23, 2017 22:25
A small ES6 credit card number validation and formatting library based on https://github.com/omarshammas/jquery.formance/blob/master/src/zfields/credit_card_number.coffee
Copyright (c) 2013 Omar Shammas ([email protected])
and Stripe ([email protected])
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions: