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 each(nodelist, callback) { | |
var i = -1, | |
l = nodelist.length | |
while (++i < l) | |
callback.call(nodelist.item(i), i) | |
} | |
// Usage: | |
var divs = document.querySelectorAll("div") | |
each(divs, function(index) { |
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
set nocompatible | |
set encoding=utf-8 nobomb | |
" enable syntax highlighting and line numbers | |
syntax on | |
set number | |
" color scheme | |
let g:solarized_termtrans=1 | |
set background=dark |
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
// Imperative style | |
const createDivs = num => { | |
for (var i = 0; i < num; i++) | |
document.body.insertAdjacentHTML("beforeend", "<div></div>"); | |
}; | |
createDivs(10); | |
// Functional style: recursion | |
const createDivs = num => { |
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
const cloneSet = (() => | |
new Set(new Set().add(1)).has(1) | |
? set => new Set(set) | |
: set => { | |
const clone = new Set(); | |
set.forEach(item => clone.add(item)); | |
return clone; | |
})(); |
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
const isNumber = x => | |
!Number.isNaN(parseInt(x)) && Number.isInteger(Math.trunc(x)); |
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
const set = new Set(["foo", "bar"]); | |
const iterate = iterator => { | |
const iteration = iterator.next(); | |
if (iteration.done) return; | |
console.log(iteration.value); | |
return iterate(iterator); | |
}; | |
iterate(set.values()); // => foo, bar |
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
const scrollRoot = (() => { | |
if ("scrollingElement" in document) | |
return document.scrollingElement; | |
const initial = document.documentElement.scrollTop; | |
document.documentElement.scrollTop = initial + 1; | |
const updated = document.documentElement.scrollTop; | |
document.documentElement.scrollTop = initial; | |
return updated > initial |
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
const isObject = obj => Object(obj) === obj; |
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
const getPathBoundingBox = (() => { | |
const toPolygon = (path, points = 50) => { | |
const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon"); | |
const total = path.getTotalLength(); | |
const step = total / points; | |
const getPoints = (dist = 0, arr = []) => { | |
const {x, y} = path.getPointAtLength(dist); | |
arr.push(`${x},${y}`); | |
const next = step + dist; |
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
const duplicate = obj => JSON.parse(JSON.stringify(obj)); |
OlderNewer