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 path = ''; | |
| function JSON2File(error, success, code) { | |
| var writer = fs.createWriteStream(path + '.json'); | |
| var json = JSON.stringify(success.data); | |
| writer.write(json); | |
| } |
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
| /** | |
| * Функции для работы со storage, как с очередью. | |
| */ | |
| /** | |
| * Очистить старые записи. | |
| * @param tailIndexValue | |
| * @param nextIndexValue | |
| */ | |
| function free(tailIndexValue, nextIndexValue) { |
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
| /** | |
| * Добавить в стэк listName значение value. | |
| * При в storage будет храниться ключ ${listName}_last со значением индекса последнего элемента в этом списке. | |
| * Новое значение сериализованное в JSON добавится в storage с ключом ${listName}_last + 1. | |
| * | |
| * Пример: | |
| * В списке listName=log есть 3 элемента, storage будет выглядеть так: | |
| * { | |
| * 'log_last': '2', | |
| * 'log_0': '{...}', |
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
| # swap names of 2 files | |
| if [ $# -eq 2 ] | |
| then | |
| mv $1 $1.backup | |
| mv $2 $1 | |
| mv $1.backup $2 | |
| fi | |
| # swap %file_name% with %file_name%.backup | |
| if [ $# -eq 1 ] && [ -f $1.backup ] || [ -d $1.backup ]; |
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 prime() { | |
| this.primes = [], | |
| this.number = 1, | |
| this.stop = false, | |
| this.x = 600851475143, | |
| this.checkPrime = function() { | |
| var number = this.number, | |
| i = 0, | |
| l = this.primes.length; |
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
| // shim layer with setTimeout fallback | |
| window.requestAnimFrame = (function(){ | |
| return window.requestAnimationFrame || | |
| window.webkitRequestAnimationFrame || | |
| window.mozRequestAnimationFrame || | |
| function( callback ){ | |
| window.setTimeout(callback, 1000 / 60); | |
| }; | |
| })(); |
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
| // Bad method, don't use it. | |
| var a = [0,1,2,3,4] | |
| for (var i = 0; i < a.length; i++) { | |
| console.log(i, a[i]); | |
| if (a[i] === 0) { | |
| console.log(a); | |
| a.splice(i, 1); | |
| console.log(a); | |
| } | |
| } |
NewerOlder