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 dataBase; // cache | |
| function mergeBig(texts) { | |
| texts = texts || text; | |
| return q.all(texts.map(function (el) { | |
| return task(el) | |
| .reduce(bigramArray) | |
| .run() | |
| })).then(function reducer(data) { |
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
| // simples would be return dataBase[word]; | |
| // string => array | |
| function predict(word) { | |
| var needle = dataBase[word]; | |
| if (!needle) { | |
| return []; | |
| } | |
| var total = _.reduce(needle, function (acc, el) { |
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 train(fileName, splitter) { | |
| var parts = fs.readFileSync(fileName).toString().split(splitter).map(function (el) { | |
| return _.prepare(el).split(' '); | |
| }); | |
| return mergeBig(parts); | |
| } |
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 match_brackets(str){ | |
| var stack = [], | |
| lookup = { | |
| //key : value pairs | |
| '(' : ')', | |
| '{' : '}', | |
| '[' : ']', | |
| }, | |
| _keys = Object.keys(lookup), |
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
| // char => char | |
| function closingTag(char) { | |
| return { | |
| '(': ')', | |
| '{': '}', | |
| '[': ']' | |
| }[char]; | |
| } | |
| // char => boolean |
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
| // here condR === undefined | |
| const falsy = (condL, condR) => condL !== condR; | |
| const map = (fn, [first, ...rest]) => | |
| (falsy(first) && []) && [fn(first), ...map(fn, rest)]; | |
| console.log(':)', map((x) => (x + x), [1, 2, 3])); |
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
| if (require.main === module) { | |
| console.log('Called from bash') | |
| } else { | |
| console.log('Called as a module') | |
| } |
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 $scrolledelement = document.getElementById("left"); | |
| $scrolledelement.scrollTop = localStorage.scrollPosition; | |
| $scrolledelement.onscroll = function() { | |
| $pos = $scrolledelement.scrollTop | |
| localStorage.setItem("scrollPosition", $pos); | |
| $outelement.innerHTML = localStorage.scrollPosition; | |
| }; |
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
| if (module.parent) { | |
| return | |
| } | |
| const readline = require('readline') | |
| const rl = readline.createInterface({ | |
| input: process.stdin, | |
| output: process.stdout, | |
| // terminal: false // isTTY | |
| }) |
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 dotPath = R.useWith(R.path, [R.split('.')]) | |
| const propsDotPath = R.useWith(R.ap, [R.map(dotPath), R.of]) | |
| var obj = { | |
| a: { b: { c: 42 } }, | |
| d: 2 | |
| } | |
| propsDotPath(['a.b.c', 'd'], obj) | |
| // => [ 42, 2 ] |