Skip to content

Instantly share code, notes, and snippets.

View stasgavrylov's full-sized avatar

Stas Gavrylov stasgavrylov

View GitHub Profile
Element.prototype.closest = function(selector)
{
var element = this;
do if (element.matches(selector)) return element;
while (element = element.parentElement);
return null;
};
@stasgavrylov
stasgavrylov / links.js
Created September 24, 2015 20:33
Useful frontend links.
@stasgavrylov
stasgavrylov / on.js
Last active November 18, 2015 14:31
shortcut for addEventListener
function on($emitter, types, handler)
{
types.split(/\s+/).forEach(function(type)
{
$emitter.addEventListener(type, handler)
})
return handler
}
@stasgavrylov
stasgavrylov / array_of_values.js
Last active December 7, 2015 13:37
Init array with values
function arrayOfInts(n) {
return Array.apply(null, {length: n}).map(function(v,i) {return i})
}
@stasgavrylov
stasgavrylov / blur.js
Created December 8, 2015 11:48
Blur on resize
// Adjust blur on resize.
var proto = Object.create(HTMLElement.prototype);
proto.attachedCallback = function()
{
var feGaussianBlur = this.query('feGaussianBlur')
var MAX_DEVIATION = 10
var MIN_DEVIATION = 3
var MIN_WIDTH = 320
var MAX_WIDTH = 1366
var k = (MAX_WIDTH - MIN_WIDTH) / (MAX_DEVIATION - MIN_DEVIATION)
@stasgavrylov
stasgavrylov / godmode.js
Created December 24, 2015 21:37
God Mode in JavaScript
// что возвращает эта функция?
(function fun(Infinity, length, __proto__)
{
return [,,~0.[0|0]][fun.__proto__.length && Infinity, -~String(this).length >> __proto__] << (0. === .0) + Infinity;
}).apply(typeof fun, [,,2]);
// рассмотрим массив с аргументами:
// "0" in [,,2] => false
// "1" in [,,2] => false
function _debounce(callable, wait)
{
var id
function call(context, list)
{
requestAnimationFrame(function()
{
callable.apply(context, list)
id = 0
@stasgavrylov
stasgavrylov / gist:211ad63e340e7de88ee4
Created January 21, 2016 08:48
CSS - Font smoothing
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
// http://szafranek.net/works/articles/font-smoothing-explained/
a
{
text-decoration: none;
color: inherit;
}
h1, h2, h3, p, dl, dd, body, figure
{
margin: 0;
}