This file contains 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
<html lang="ru"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<style> | |
#canv { | |
border: 2px solid #eee; | |
margin: 20px auto; | |
display: block; | |
color: #7a93b4; | |
} |
This file contains 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
/** | |
* Дефолтный boolean параметр функции | |
* Учитывает 3 вариант: передаем true || false или вовсе не передаем (true по дефолту) | |
*/ | |
join = typeof join === 'undefined' ? true : join; |
This file contains 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
/** | |
* Прототип. Возвращает строку с безопасными HTML символами | |
* @type {Function|*} | |
*/ | |
String.prototype.encodeHTML = String.prototype.encodeHTML || function () { | |
return this | |
.replace(/&/g, "&") | |
.replace(/</g, "<") | |
.replace(/>/g, ">") | |
.replace(/"/g, """) |
This file contains 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
$element.css({ | |
"transition-duration":"0s", | |
backgroundColor:'#8f8' | |
}); | |
setTimeout(function() { | |
$element.css({ | |
transition:"background 2s linear", | |
backgroundColor:'#E7E7E7' | |
}); | |
},500); |
This file contains 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
/** | |
* Prism: Lightweight, robust, elegant syntax highlighting | |
* MIT license http://www.opensource.org/licenses/mit-license.php/ | |
* @author Lea Verou http://lea.verou.me | |
*/ | |
Prism.languages.nginx = Prism.languages.extend('clike', { | |
comment: { | |
pattern: /(^|[^"{\\])(#.*?(\r?\n|$))/g, | |
}, |
This file contains 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 declOfNum(number, titles) { | |
cases = [2, 0, 1, 1, 1, 2]; | |
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ]; | |
} | |
use: | |
declOfNum(count, ['найдена', 'найдено', 'найдены']); |
This file contains 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 getNumerology(num) { | |
var strNum = num.toString(); | |
var strLen = strNum.length; | |
var sum = 0; | |
for(var i = 0; i < strLen; i++) { | |
sum += parseInt(strNum[i]); | |
} | |
return sum.toString().length < 2 ? sum : getNumerology(sum); |
This file contains 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
// using a generator function | |
function* entries(obj) { | |
for (let key of Object.keys(obj)) { | |
yield [key, obj[key]]; | |
} | |
} | |
// an alternative version using a generator expression | |
function entries(obj) { | |
return (for (key of Object.keys(obj)) [key, obj[key]]); |
This file contains 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 parser = document.createElement('a'); | |
parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
parser.protocol; // => "http:" | |
parser.hostname; // => "example.com" | |
parser.port; // => "3000" | |
parser.pathname; // => "/pathname/" | |
parser.search; // => "?search=test" | |
parser.hash; // => "#hash" | |
parser.host; // => "example.com:3000" |
This file contains 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 arrayBufferToBase64(buffer) { | |
let binary = ''; | |
let bytes = new Uint8Array(buffer); | |
let len = bytes.byteLength; | |
for (let i = 0; i < len; i++) { | |
binary += String.fromCharCode(bytes[i]); | |
} | |
return window.btoa(binary); | |
} |
OlderNewer