Skip to content

Instantly share code, notes, and snippets.

View Deliaz's full-sized avatar

Denis Leonov Deliaz

View GitHub Profile
@Deliaz
Deliaz / uri.js
Created December 7, 2016 10:38 — forked from jlong/uri.js
URI Parsing with Javascript
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"
@Deliaz
Deliaz / es6-object-iteration.js
Created November 22, 2016 10:17
ES6 object itareraton
// 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]]);
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);
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, ['найдена', 'найдено', 'найдены']);
/**
* 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,
},
$element.css({
"transition-duration":"0s",
backgroundColor:'#8f8'
});
setTimeout(function() {
$element.css({
transition:"background 2s linear",
backgroundColor:'#E7E7E7'
});
},500);
/**
* Прототип. Возвращает строку с безопасными HTML символами
* @type {Function|*}
*/
String.prototype.encodeHTML = String.prototype.encodeHTML || function () {
return this
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
/**
* Дефолтный boolean параметр функции
* Учитывает 3 вариант: передаем true || false или вовсе не передаем (true по дефолту)
*/
join = typeof join === 'undefined' ? true : join;
<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;
}