Skip to content

Instantly share code, notes, and snippets.

Avatar

Johan Sundström johan

View GitHub Profile
View mac-specs.sh
#! /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>'
View eureka.md

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 Jan 24, 2017
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
View Makefile
# 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
View LICENSE
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 Jan 2, 2017
opower PG&E csv file cleanup
View index.md

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 Feb 4, 2017
HAI 2017 events, as of 2016-12-22
View events.es5.js
'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
@johan
johan / srt.js
Created Dec 21, 2016
A little subtitle file tweaking class
View srt.js
class SRT {
constructor(s) { this.setSubs(typeof s === 'string' ? SRT.decode(s) : s); }
toString() { return SRT.encode(this.subs); }
timeShift(dt) {
return new SRT(this.subs.map(s => Object.assign({}, s, {t: s.t + dt})));
}
getSubs() { return this.subs.map(o => Object.assign({}, o)); }
setSubs(subs) { this.subs = subs; return this; }
@johan
johan / controlfreak.js
Last active Dec 16, 2016
Convenience lib for the chrome extension "Control Freak", a light-weight Greasemonkey.
View controlfreak.js
const scrape = (scraper) => {
let spec = 'dom' in scraper ? scraper : { dom: scraper };
on(spec).then((scraped) => {
console.info('on.dom scraped:', {scraper, scraped});
exportToPage({scraper, scraped, on});
evalInPage('on');
});
};
const exportToPage = (obj) => {
@johan
johan / cancelAll.js
Created Dec 11, 2016
A browser functionality fill-in I ended up writing and sharing on http://stackoverflow.com/questions/3141064/how-to-stop-all-timeouts-and-intervals-using-javascript to batch cancel javascript's basic deferred execution functions.
View cancelAll.js
(function(deferFunctions) {
for (var setter in deferFunctions) (function(setter, clearer) {
var ids = [];
var startFn = window[setter];
var clearFn = window[clearer];
function clear(id) {
var index = ids.indexOf(id);
if (index !== -1) ids.splice(index, 1);
return clearFn.apply(window, arguments);
@johan
johan / alert.js
Created Nov 22, 2016
Somewhat improved version of Fake News Alert extension 0.1.2 from https://chrome.google.com/webstore/detail/fake-news-alert/aickfmgnhocegpdbfnpfnedpeionfkbh/related – to mark links directly at Facebook before you even click through them.
View alert.js
// alert.js
const stripes = document.createElement('div');
stripes.style.cssText = `
height: 20px;
width: 100%;
position: fixed;
z-index: 99999;
opacity: 0.7;
pointer-events: none;
You can’t perform that action at this time.