Skip to content

Instantly share code, notes, and snippets.

View Deliaz's full-sized avatar

Denis Leonov Deliaz

View GitHub Profile
/**
* Дефолтный boolean параметр функции
* Учитывает 3 вариант: передаем true || false или вовсе не передаем (true по дефолту)
*/
join = typeof join === 'undefined' ? true : join;
/**
* Прототип. Возвращает строку с безопасными HTML символами
* @type {Function|*}
*/
String.prototype.encodeHTML = String.prototype.encodeHTML || function () {
return this
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
$element.css({
"transition-duration":"0s",
backgroundColor:'#8f8'
});
setTimeout(function() {
$element.css({
transition:"background 2s linear",
backgroundColor:'#E7E7E7'
});
},500);
/**
* 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,
},
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, ['найдена', 'найдено', 'найдены']);
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);
@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]]);
@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 / build.xml
Created February 12, 2017 19:07
Build script for Phing
<?xml version="1.0"?>
<project name="Clipboard History" basedir="." default="tester">
<property name="build_dir" value="../scm_build" />
<property name="dest_dir" value="../scm_build/scm" />
<property name="src_dir" value="." />
<!-- ДЛЯ ТЕСТЕРОВ -->
<target name="tester" description="Сборка в папку для тестеров">
<!-- Создаем каталог для билда -->
<mkdir dir="${build_dir}" />
@Deliaz
Deliaz / generate-guid.js
Created March 19, 2017 17:10
GUID generator
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}