const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
const pipe = (...fns) => compose.apply(compose, fns.reverse());
This file contains hidden or 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 suffixNumber = (n) => { | |
// gives us the last digit of n | |
const d = n % 10; | |
if (d === 1 && n !== 11) return `${n}st`; | |
if (d === 2 && n !== 12) return `${n}nd`; | |
if (d === 3 && n !== 13) return `${n}rd`; | |
return `${n}th`; | |
} | |
// test it out |
This file contains hidden or 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 | |
# Redirect output to stderr. | |
exec 1>&2 | |
# enable user input | |
exec < /dev/tty | |
consoleregexp='^\+.*console\.\(log\|error\|info\)(' | |
# CHECK | |
if test $(git diff --cached | grep $consoleregexp | wc -l) != 0 | |
then |
This file contains hidden or 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
function ConvertGoogleDocToCleanHtml() { | |
var body = DocumentApp.getActiveDocument().getBody(); | |
var numChildren = body.getNumChildren(); | |
var output = []; | |
var images = []; | |
var listCounters = {}; | |
// Walk through all the child elements of the body. | |
for (var i = 0; i < numChildren; i++) { | |
var child = body.getChild(i); |
This file contains hidden or 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
'Use Strict'; | |
// isInteger polyfill. | |
Number.isInteger = Number.isInteger || function(value) { | |
return typeof value === "number" && | |
isFinite(value) && | |
Math.floor(value) === value; | |
}; | |
// Calculate and return the factorial of n. |
This file contains hidden or 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 isLocalhost = Boolean( | |
window.location.hostname === 'localhost' || | |
window.location.hostname === '[::1]' || // [::1] is the IPv6 localhost address | |
window.location.hostname.match( // 127.0.0.1/8 is considered localhost for IPv4 | |
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ | |
) | |
); |
This file contains hidden or 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
// The Babylonian Method | |
// http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method | |
// @param n - the number to compute the square root of | |
// @param guess - the best guess so far (can omit from initial call) | |
function squirt(n, guess) { | |
if (!guess) { | |
guess = n / 2.0; // Take an initial guess at the square root | |
} | |
const divided = n / guess; // Divide our guess into the number | |
const newGuess = (divided + guess) / 2.0; // Use average of guess and divided as our new guess |
This file contains hidden or 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 tag = (tag, param) => { | |
console.log(tag, param); | |
return param; | |
}; | |
const foobar = tag('foobar', tag('foo', 100 * tag('bar', 500))); | |
console.log('foobar is: ', foobar); | |
//>> bar 500 | |
//>> foo 50000 | |
//>> foobar 50000 | |
//>> foobar is: 50000 |
This file contains hidden or 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 traceProperty = (object, property) => { | |
let value = object[property]; | |
Object.defineProperty(object, property, { | |
get() { | |
console.trace(`${property} requested`); | |
return value; | |
}, | |
set(newValue) { | |
console.trace(`setting ${property} to `, newValue); | |
value = newValue; |