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
// |
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
node_modules | |
*.js | |
*.jsx |
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
// Returns e as HTML string | |
function serialize(e) { | |
const s = new XMLSerializer(); | |
return s.serializeToString(e); | |
} | |
// Recursively removes all classes and ids that do not affect styling from element e | |
function removeUnused(e) { | |
const s0 = window.getComputedStyle(e).cssText; | |
const c = Array.from(e.classList.values()); |
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
function compose<T>(...fna: Array<(p: T) => Promise<T>>) { | |
return (p: T) => { | |
return fna.reduce((a, fn) => a.then(fn), Promise.resolve(p)); | |
}; | |
} | |
const pipe = compose(foo, bar, baz); | |
const res1 = pipe(arg); | |
// equivalent |
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
// convert headers object to object | |
Array.from(headers).reduce((a: { [k: string]: string }, kv) => (a[kv[0]] = kv[1], a), {}) | |
// parse curl-compatible -H arguments in command-line into object | |
function seq(first: number, last: number): number[] { | |
if (first < last) { | |
return [first].concat(seq(first + 1, last)); | |
} else if (first > last) { | |
return [last].concat(seq(first, last - 1)); | |
} else { |
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
// Resize rows and columns to fit the data we're inserting. This requires special | |
// permission for some reason. | |
function setSizes() { | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheets = ss.getSheets(); | |
for (var i=0; i < sheets.length; i++) { | |
var sheet = sheets[i]; | |
var range = sheet.getDataRange(); | |
var numRows = range.getNumRows(); | |
for (var r=2; r <= numRows; r++) { |
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
// Not completely sure these do the right thing on reject... | |
function pand(...args) { | |
return args.length != 0 ? new Promise((resolve, reject) => { | |
let [tc, fc] = [0, 0]; | |
function f(v) { | |
tc += v ? 1 : 0; | |
fc += v ? 0 : 1; | |
if (tc == args.length) resolve(true); | |
if (fc == 1) resolve(false); |
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 BASE = "https://beebo.org"; | |
const http = require("http"); | |
const https = require("https"); | |
const URL = require("url").URL; | |
const server = http.createServer((req0, res0) => { | |
const options = new URL(req0.url, BASE); | |
console.log(`${req0.method} ${options.toString()}`); |
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
window.myLibrary = (() => { let a, p = new Promise((...args) => a = args); [p.resolve, p.reject] = a; return p; })(); | |
window.myLibrary.resolve("jjj"); // when library ready | |
window.myLibrary.then(console.log); // outputs "jjj" |
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
// Simple functions for querying the SW cache. | |
// Only approximate! (1) Only includes bodies. (2) Can't count opaque resources. | |
function cacheDump(c) { | |
return c.keys().then(a => { | |
return Promise.all(a.map(req => | |
c.match(req).then(res => res.clone().blob().then(b => [req.url, b.size])) | |
)).then(a => new Map(a)); | |
}); |
NewerOlder