-
Shortening
const
to something likeref
,val
,cst
because- it's the most frequently used keyword
- conflicts with
console.log
auto-completion
-
null
should beObject.freeze(Object.create(null))
or a specialSymbol.nullable
-
([] =~= []) // true
shallow compare -
({ a: {} } =*= { a: {} }) // true
deep compare
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
module.exports = function(gen) { // coroutine, equivalent to https://github.com/tj/co | |
const it = gen(); | |
return Promise.resolve().then(function pump(v) { | |
const next = it.next(v); | |
if(next.done) return next.value; | |
return Promise.resolve(next.value).then(pump, it.throw.bind(it)); | |
}); | |
}; |
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
create table foo_version ( | |
id VARCHAR(32), | |
v BIGINT, | |
data TEXT, | |
PRIMARY KEY (id, v) | |
); | |
create table foo ( | |
id VARCHAR(32), |
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
// 2 globals defined at boot of nodejs engine | |
rl = cb => require('readline').createInterface({input:process.stdin}).on('line',cb); | |
print = console.log; | |
/* | |
Let's call an integer "repetitive" if it contains two of the same digit in a row. For example, 12232 is repetitive but 1232 is not. | |
Given a positive integer n < 10^15, return the number of nonrepetitive integers in [1..n]. | |
*/ | |
// prog | |
rl(s=>{r=0;d=s.length-1;for(i=0;i<=d;i++){r+=(i>0&&s[i-1]<s[i]?s[i]-1:s[i])*9**(d-i);if(s[i-1]==s[i]){r--;break}}for(i=0;i<d;i++)r+=9**i;print(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
const { Readable } = require('stream'); | |
const ys = Buffer.from('y\n'.repeat(2**16)); | |
class Y extends Readable { | |
_read(size) { | |
this.push(ys.slice(0, size)); | |
} | |
} | |
new Y().pipe(process.stdout); // test with node yes | pv -r > /dev/null |
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 { Store } = require('express-session'); | |
const { knex } = require('.'); | |
class PGStore extends Store { | |
destroy(sid, cb) { | |
return knex('sessions').where('id', sid).delete().then(() => cb()); | |
} | |
get(sid, cb) { | |
// console.log('get', sid); |
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
diff --git a/bin/cli.js b/bin/cli.js | |
index 9dc79f9..cf68699 100755 | |
--- a/bin/cli.js | |
+++ b/bin/cli.js | |
@@ -33,11 +33,23 @@ function checkLocalModule(env) { | |
} | |
function initKnex(env) { | |
- | |
checkLocalModule(env); |
I hereby claim:
- I am caub on github.
- I am caub (https://keybase.io/caub) on keybase.
- I have a public key whose fingerprint is 252A 77AD 73A4 A8BC FF76 D655 303C 5F10 6F57 4D9B
To claim this, I am signing this object:
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.import = function (transformer) { | |
const ROOT = location.origin; | |
const REQUIRE_CACHE = new Map(); | |
const RE_EXT = /\.js\w*$/; | |
function fqn(url, dirname) { | |
const {href} = new URL(url.startsWith('http') ? url : (url.startsWith('/') ? ROOT : dirname) + url), | |
last = href.lastIndexOf('/'), dir = href.slice(0, last+1), name = href.slice(last+1), | |
filename = name ? (RE_EXT.test(name) ? name: name+'.js') : 'index.js'; | |
return {dir, abs: dir+filename}; |
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
// https://codesandbox.io/s/jznpj65nm5 | |
// ------- index.js | |
import React from 'react'; | |
import { render } from 'react-dom'; | |
import Hello from './Hello'; | |
import DataProvider from './DataProvider'; | |
import * as data from './dataStore'; | |
const styles = { |