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); | |
} | |
} |
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
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
# 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
/** | |
* Добавить в стэк 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
/** | |
* Функции для работы со 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
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
/** | |
* <a href='http://api.yandex.ru/dictionary/'>Реализовано с помощью сервиса «API «Яндекс.Словарь»</a> | |
*/ | |
(function() { | |
const YANDEX_DICTIONARY_KEY = 'dict.1.1.20150130T172350Z.0895b15babe24c90.431f35fa9af476be1b6d14d80f3809ab693a5970'; | |
const DICTIONARY_URL = `https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key=${YANDEX_DICTIONARY_KEY}&lang=en-ru` | |
function translate(word) { | |
fetch(`${DICTIONARY_URL}&text=${word}`) | |
.then(res => res.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
(function() { | |
var willHide = false; | |
var msgBox = document.createElement('div'); | |
msgBox.style.position = 'fixed'; | |
msgBox.style.top = '10px'; | |
msgBox.style.right = '10px'; | |
msgBox.style.display = 'none'; | |
document.body.appendChild(msgBox); |
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
/*! | |
\brief Если `flag` праведный, то выполнить `callback`, иначе подписаться на событие `sig` | |
Варианты реализации `flag`: | |
1. передать имя свойства (+ в любой момент времени можно проверить актуальность флага) | |
2. передать функтор (+ в любой момент времени можно проверить актуальность флага) | |
3. передать значение свойства (- узнать значение флага можно только в текущий момент времени) | |
Здесь используется последний, где `flag` — это буль | |
\param type:bool flag | |
\param type:Signal sig | |
\param type:function callback |
OlderNewer