… | eval flag = printf("%c%c", 127452 + tonumber(substr(countrycode,1,1), 36), 127452 + tonumber(substr(countrycode,2,1), 36)),
country=countrycode+" ("+percent+"%) "+flag
View selectArg.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Constructs a new function type from `F`, instead returning `R` */ | |
export type Returns<F, R> = F extends (...args: any[]) => infer _ | |
? (...args: Parameters<F>) => R | |
: never; | |
/** | |
* Given a (zero-indexed) positional argument number `n` | |
* and a function call signature generic type `F`, | |
* produce a well-typed function that selects that `n`th arg. | |
* @example |
View README.md
View humanizeDuration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const units = [["ms", 1000], ["s", 60], ["m", 60], ["h", 24], ["d", 7], ["w", 52.142857142858986], ["y", Infinity]]; | |
const duration = (ms) => units.reduce( | |
({ left, s }, [u, o]) => { | |
const n = left % o; | |
left -= n; | |
n && s.unshift(`${~~n}${u}`); | |
return { left: ~~(left / o), s }; | |
}, | |
{ left: ms, s: [] } |
View editdistance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env node | |
// for a JSON array of strings, or an array of lines on stdin, | |
// shows edit distances between all the inputs, ascending | |
const fs = require('fs'); | |
const ed = require('edit-distance'); | |
// read all strings from stdin: | |
let names = fs.readFileSync(0, 'utf-8'); |
View sentence-highlight-word-count-minor-mode.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; A minor mode inspired by Gary Provost's notes on making sentence length music | |
;; via https://www.aerogrammestudio.com/2014/08/05/this-sentence-has-five-words/ | |
;; | |
;; The sentence at point gains its colour from how many words it has: | |
;; yellow - one or two words | |
;; pink - three or four words | |
;; red - five words | |
;; green - medium sentences | |
;; blue - long sentences | |
;; |
View dec-2022.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<base href="https://www.timeanddate.com/date/workdays.html?d1=01&m1=05&y1=2018&d2=9&m2=7&y2=2018&"> | |
<title>Vacation Day Planner</title> | |
<script> | |
const sumUp = (td) => { const t = td.parentNode.parentNode, r = t.rows[t.rows.length-1], c = r.cells[r.cells.length-1]; c.textContent = Array.from(t.querySelectorAll('td')).filter(c => c.classList.contains('hl')).length; c.style.color = '#000'; } | |
document.onclick = (e) => { if (e.target.nodeName === 'TD') { const t = e.target, cl = t.classList; cl.contains('hl-b') || cl.contains('hl') ? cl.remove('hl-b', 'hl') : cl.add('hl'); sumUp(t); } }; | |
const pad = (n) => (n < 10 ? '0' : '') + n; | |
const date = (t) => t.getFullYear() + '-' + pad(t.getMonth() + 1) + '-' + pad(t.getDate()); | |
const ONE_DAY = 864e5; | |
const ghostThePast = () => { |
View .gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/date-from.txt | |
/date-to.txt | |
/dates.txt | |
/export_dir.txt | |
/in-us.js | |
/json | |
/node_modules | |
/us.txt | |
/world.geo.json |
View index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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 |
View fb-friends-to-csv.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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}' | |
) |
View .gitconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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" |
NewerOlder