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
'use strict' | |
function promisify (fakeAjax){ | |
let content = null | |
let func = null | |
return function (url) { | |
fakeAjax(url, (err, data) => { | |
if (err) { | |
throw Error('unhandled error') | |
} |
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
'use strict' | |
/** | |
* note: substitute costs 2 | |
* | |
* if either string is empty => length of the other | |
* if the last chars of both match => | |
* recursively call edit without adding distance | |
* if not => | |
* Math.min of three ways |
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
(define call/cc call-with-current-continuation) | |
;;;;;;;;;;;;;; | |
(call/cc (lambda (cont) 2)) ; 2, cont do nothing | |
(call/cc (lambda (cont) (cont 2))) ; 2, cont do nothing | |
(* 3 (call/cc (lambda (cont) | |
(+ 1 2)))) ; 9, cont is not used |
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
'use strict' | |
module.exports = diff | |
const MATCH = 0 | |
const REMOVE = 1 | |
const INSERT = 2 | |
const REPLACE = 3 | |
function diff (fromArr, toArr, diffKey) { | |
const len1 = fromArr.length |
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 fakeAjax = (time, cb) => { | |
setTimeout(() => {cb('data...')}, time) | |
} | |
const noopPromise = new Promise(() => {}) | |
// cancel promise when timeout reached, using Promise.race | |
const timer = (fn, time) => | |
Promise | |
.race([ |
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 fakeGen (fromV = 0, toV, step = 1) { | |
// only one arg | |
if (toV == undefined) { | |
toV = fromV | |
fromV = 0 | |
} | |
// init status | |
const status = { | |
done: 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
'use strict' | |
const isObject = obj => typeof obj === 'object' | |
const hasKey = (obj, key) => key in obj | |
const Undefined = new Proxy({},{ | |
get (target, key, receiver) { | |
// always return Undefined when accessing Undefined.whatever | |
return receiver | |
} |
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 () { | |
setImmediate(function () { | |
console.log(6) // run macro-task | |
}) | |
setTimeout(function () { | |
console.log(8) // 4ms delay | |
}, 0) | |
Promise |
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
;; detailed continuation usage, see previous gist: https://gist.github.com/DadgadCafe/07b0b50bf9537522fed09b3dc8df2784 | |
(define call/cc call-with-current-continuation) | |
(let* ((yin | |
((lambda (cc) (display #\@) cc) | |
(call/cc (lambda (c) c)))) | |
(yang | |
((lambda (cc) (display #\*) cc) | |
(call/cc (lambda (c) c))))) |
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 proxied (obj) { | |
const o = Object.assign({}, obj) | |
function filterPrivate (key) { | |
if (key[0] === '_') { | |
throw Error('cannot access private key: ${key}') | |
} | |
} | |
const handler = { |
OlderNewer