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 fastSelect(selector) { | |
if (selector == "body") { | |
return document.body | |
} | |
else if (selector == "head") { | |
return document.head | |
} | |
else if (/^[\#.]?[\w-]+$/.test(selector)) { | |
switch (selector[0]) { | |
case "#": |
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
function removeDuplicates(arr) { | |
var clean = [] | |
var cleanLen = 0 | |
var arrLen = arr.length | |
for (var i = 0; i < arrLen; i++) { | |
var el = arr[i] | |
var duplicate = false | |
for (var j = 0; j < cleanLen; j++) { |
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 createNode = html => | |
new Range().createContextualFragment(html).firstElementChild; |
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 car() { | |
return { | |
start: function() { | |
console.log("Engine on.") | |
}, | |
accelerate: function() { | |
console.log("Let's go!") | |
} | |
} | |
} |
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
// array utils | |
// ================================================================================================= | |
const combine = (...arrays) => [].concat(...arrays); | |
const compact = arr => arr.filter(Boolean); | |
const contains = (() => Array.prototype.includes | |
? (arr, value) => arr.includes(value) | |
: (arr, value) => arr.some(el => el === value) |
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 elements = document.querySelectorAll("div"), | |
callback = (el) => { console.log(el); }; | |
// Spread operator | |
[...elements].forEach(callback); | |
// Array.from() | |
Array.from(elements).forEach(callback); | |
// for...of statement |
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 randomColor = (() => { | |
"use strict"; | |
const randomInt = (min, max) => { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
}; | |
return () => { | |
var h = randomInt(0, 360); | |
var s = randomInt(42, 98); |
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 letters = (() => { | |
const caps = [...Array(26)].map((val, i) => String.fromCharCode(i + 65)); | |
return caps.concat(caps.map(letter => letter.toLowerCase())); | |
})(); |
OlderNewer