Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View johan's full-sized avatar

Johan Sundström johan

View GitHub Profile
@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 (omar@shammaslabs.com)
and Stripe (alex@stripe.com)
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:
@johan
johan / index.md
Created January 2, 2017 12:18
opower PG&E csv file cleanup

Usage

sh opower-csv-to-csv < pge_*.csv

Purpose

Take your PG&E csv data export (pge_electric_interval_data_NNNNNNNNNN_YY-MM-DD_to_YYYY-MM-DD.csv) for the date range you want,

@johan
johan / events.es5.js
Last active February 4, 2017 08:36
HAI 2017 events, as of 2016-12-22
'use strict';var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"])_i["return"]();}finally{if(_d)throw _e;}}return _arr;}return function(arr,i){if(Array.isArray(arr)){return arr;}else if(Symbol.iterator in Object(arr)){return sliceIterator(arr,i);}else{throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}();var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj;}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i];}return arr2;}else{return Array.from(arr);}}var deQuery=function deQuery(){var q=argu