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
| #include "stdafx.h" | |
| #include "time.h" | |
| unsigned long summMod3Or5_1(); | |
| unsigned long summMod3Or5_2(); | |
| void run(unsigned long (*)(), size_t); | |
| const size_t N = 999999999999; | |
| int main() |
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 tpl = (str, res = str.match(/([0-9])\[([a-z]+)\]/)) => | |
| res ? tpl(str.replace(`${res[1]}[${res[2]}]`, res[2].repeat(res[1] | 0))) : str | |
| // test | |
| aaa -> aaa | |
| 3[a]aa -> aaaaa | |
| 2[a3[c]2[d]]bb -> acccddacccddbb |
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
| // {x:1, y:1, z:{a:1,b:2}} flattens to {x:1, y:1, z.a:1, z.b: 2} | |
| const walk = (obj, root = {}, prefix = '') => | |
| Object.keys(obj).reduce((res, key) => "object" === typeof obj[key] ? walk(obj[key], root, prefix + key + '.') : (root[prefix + key] = obj[key], res), root) |
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 recognition = new webkitSpeechRecognition(); | |
| recognition.onresult = function(event) { | |
| var text = event.results[0][0].transcript; | |
| speak(text); | |
| } | |
| function speak(msg) { | |
| var text = new SpeechSynthesisUtterance(msg); | |
| speechSynthesis.speak(text); |
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
| export default (list, done) => { | |
| const acc = [] | |
| const next = data => list.length === acc.push(data) && done(acc) | |
| list.forEach(fn => fn(next)) | |
| }; | |
| // second implementation: | |
| export default (list, done) => { | |
| let drop = false; | |
| const acc = [], next = (err, data) => drop || ( |
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
| class PipeModification { | |
| constructor(input) { | |
| this.queue = ['initial'] | |
| this.value = [input] | |
| } | |
| _action(fn) { | |
| this.value.push(fn(this.value[this.value.length - 1])) | |
| return this; |
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 filterObj(base, filter) { | |
| return Object.keys(state) | |
| .filter(name => !!~filter.indexOf(name)) | |
| .reduce((obj, name) => (obj[name] = state[name], obj), {}); | |
| } |
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 async() { | |
| var list = [].slice.call(arguments) | |
| var fn = function (err, res) { | |
| err ? list.pop()(err, res) | |
| : list.shift()(res, fn) | |
| } | |
| return function (arg, fin) { | |
| list.push(fin) |
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 toUpperCase(str) { | |
| return ('' + str).split(' ').map(function (a) { | |
| return 3 == a.length ? a.toUpperCase() : a | |
| }).join(' ') | |
| } | |
| toUpperCase('the quick brown fox, jumps over the lazy dog.') |
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 serializeStringToArray(str) { | |
| return str.split('&').reduce(function (o, p) { | |
| var t = p.split('=') | |
| o.push({name: t[0], value: t[1]}) | |
| return o | |
| }, []) | |
| } |