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 coro(g) { | |
let gId = 0; | |
wireTimeout(g.next(), gId); | |
function resume(value) { | |
wireTimeout(g.next(value), ++gId); | |
}; | |
function wireTimeout(result, id) { | |
if (result && result.value instanceof Promise) { |
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* knockCodeHandler(preset) { | |
while (true) { | |
const input = []; | |
// after read first input | |
input.push(getCode(yield)); | |
// keep reading input with timeout(1s) | |
while (true) { | |
const e = yield timeout(1000); | |
if (e) { |
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* map(values, gf) { | |
const result = []; | |
for (let i = 0; i < values.length; i++) { | |
result.push(yield* gf(values[i], i, values)); | |
} | |
return result; | |
} | |
function* knockCodeHandler(preset) { | |
while (true) { |
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 success() { | |
run(showToast("pass")); | |
} | |
function* showToast(message) { | |
var div = document.createElement("div"); | |
div.className = "toast in"; | |
div.textContent = message; | |
document.body.appendChild(div); | |
yield delay(1000); |
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
<h1>Knock code : 0113</h1> | |
<div id="knock-code-2" class="knock"> | |
</div> |
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 coro(g) { | |
g.next(); | |
return g.next.bind(g); | |
} |
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* knockCodeHandler(preset) { | |
while (true) { | |
const input = []; | |
for (let i=0; i<preset.length; i++) { | |
input.push(getCode(yield)); | |
} | |
if (input.join("") === preset) { | |
success(); | |
} else { | |
failure(); |
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 makeKnockCodeHandler(preset) { | |
let input = []; | |
return function knockCodeHandler(e) { | |
input.push(getCode(e)); | |
if (input.length === preset.length) { | |
if (input.join("") === preset) { | |
success(); | |
} else { | |
failure(); | |
} |
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 coro = require('symcoro'); | |
const {create, transfer} = coro; | |
// Figure 4. Implementing one-shot continuations with symmetric coroutines | |
// http://www.inf.puc-rio.br/~roberto/docs/MCC15-04.pdf | |
function* call1cc(f) { | |
// save the continuation "creator" | |
let currentCoro = coro.current; |
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
// http://www.inf.puc-rio.br/~roberto/docs/MCC15-04.pdf | |
function prim(str) { | |
const len = str.length; | |
return function* primMatcher(S, pos) { | |
if (S.substr(pos, len) === str) { | |
yield pos + len; | |
} | |
}; | |
} |