View fastSelect.js
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 "#": |
View each.js
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) { |
View gist:3e0ab3543499f821fb92
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 |
View removeDuplicates.js
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++) { |
View innerHTMLToDom.js
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; |
View functional-inheritance.js
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!") | |
} | |
} | |
} |
View functional-utils.js
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) |
View nodelist-iteration.js
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 |
View random-color.js
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); |
View alphabet.js
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