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 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
| 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* 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 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
| var noop = []; | |
| function stream(arr){ | |
| if(arr.length === 0) return noop; | |
| return cons(function (){return arr[0]}, function (){ return stream(arr.slice(1))}) | |
| } | |
| function cons(head, tail){ | |
| return [head, tail]; | |
| } |
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 createAsyncIterator() { | |
| const promises = []; | |
| this.subscribe({ | |
| next(value) { | |
| promises.shift().resolve({ value, done: false }); | |
| } | |
| }); | |
| return { | |
| next() { | |
| return new Promise((resolve, reject) => { |
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
| async function consume(obs) { | |
| for await (const n of obs) { | |
| console.log(n); | |
| if (n >= 5) break; | |
| } | |
| } | |
| consume(Observable.interval(100)); |
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 createAsyncIterator() { | |
| const promises = []; | |
| const values = []; | |
| this.subscribe({ | |
| next(value) { | |
| if (promises.length > 0) { | |
| promises.shift().resolve({ value, done: false }); | |
| } else { | |
| values.push(value); |
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 createAsyncIterator() { | |
| const promises = []; | |
| const values = []; | |
| let done = false; | |
| const subscription = this.subscribe({ | |
| next(value) { | |
| if (promises.length > 0) { | |
| promises.shift().resolve({ value, done: false }); | |
| } else { |