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 empty = | |
run => | |
run() | |
const enqueue = | |
(q, fn) => | |
next => | |
q(() => fn(next)) | |
let q = empty |
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
// see here for details | |
// https://medium.com/@samgoldman/ville-saukkonen-thanks-and-thanks-for-your-thoughtful-questions-24aedcfed518 | |
// https://github.com/facebook/flow/issues/7125 | |
/* | |
S = State | |
A = Action | |
OP = OwnProps | |
SP = StateProps | |
DP = DispatchProps |
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
docker run ruby ruby -e 'loop { fork { fork { sleep 0.1 } } }' |
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
// lib | |
const sleep = t => new Promise(res => setTimeout(res, t)); | |
const getRandom = () => sleep(100).then(() => Math.random()); | |
// native solution | |
async function getRandomsNative(count) { | |
await sleep(100); | |
const randoms = []; |
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 { openSync, readSync } = require('fs') | |
const DEV_RANDOM = openSync('/dev/random') | |
function getVeryRandomString(length) { | |
const buf = Buffer.alloc(length) | |
readSync(DEV_RANDOM, buf, 0, length) | |
return buf.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
// timer.js | |
function main(global) { | |
global.mySetTimeout(function () { | |
console.log("500ms"); | |
}, 500); | |
global.mySetTimeout(function () { | |
console.log("100ms"); | |
}, 100); |
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
async function main() { | |
async function f1() { | |
return new Promise((res) => { | |
setTimeout(() => { | |
res("1.1"); | |
}, 1000); | |
}); | |
} | |
async function f2() { |
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
class RootScope { | |
constructor() { | |
this.map = new Map(); | |
} | |
add(name, value) { | |
return this.map.set(name, value); | |
} | |
set(name, value) { |
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
foo / 1 + 2 * 3 + 4 ; bar = /rex1/ /* bla-bla */ / /rex2/ | |
// gives this naive AST | |
({ | |
type: 'program', | |
body: [ | |
{ | |
type: 'statement', | |
body: { | |
type: 'expression', |
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 CODE_A = "A".charCodeAt(0); | |
const CODE_a = "a".charCodeAt(0); | |
const CODE_0 = "0".charCodeAt(0); | |
const CODE_p = "+".charCodeAt(0); | |
const CODE_s = "/".charCodeAt(0); | |
// Dear v8, inline this please | |
const toA = (n) => | |
n === 63 | |
? CODE_s |