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 unique(in_list) { | |
var lookup = {}; | |
var values = []; | |
for (var i = 0; i < in_list.length; i++) { | |
if (!lookup[in_list[i]]) { | |
values.push(in_list[i]); | |
} | |
lookup[in_list[i]] = true; | |
} | |
return values; |
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 guid(){ | |
function s4() { | |
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); | |
} | |
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + | |
s4() + '-' + s4() + s4() + s4(); | |
} |
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
// requestAnimationFrame() shim by Paul Irish | |
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/ | |
window.requestAnimFrame = (function() { | |
return window.requestAnimationFrame || | |
window.webkitRequestAnimationFrame || | |
window.mozRequestAnimationFrame || | |
window.oRequestAnimationFrame || | |
window.msRequestAnimationFrame || | |
function(/* function */ callback, /* DOMElement */ element){ | |
window.setTimeout(callback, 1000 / 60); |
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 getInset(rectA, rectB) { | |
return { | |
top: (rectB.top - rectB.top), | |
right: (rectA.left + rectA.width) - (rectB.left + rectB.width), | |
bottom: (rectA.top + rectA.height) - (rectB.top + rectB.height), | |
left: rectB.left - rectB.left | |
}; | |
} |
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
/* | |
Before run the example copy and paste this function into a browser console. | |
Example: | |
createBoundingBox($0); | |
createBoundingBox(document.getElementById('element-id')); | |
*/ | |
function createBoundingBox(parentEl) { | |
var body = document.body; | |
var pRect = parentEl.getBoundingClientRect(); | |
var box = document.createElement('div'); |
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
// variables | |
var a = 10; | |
var b = 99; | |
// a^=b, b^=a, a^=b - swap variables using XOR operation, | |
// details: http://en.wikipedia.org/wiki/XOR_swap_algorithm | |
a^=b, b^=a, a^=b; | |
console.log('a', a); | |
console.log('b', b); |
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 currentIndex = 0; | |
var listLength = 9; | |
var dir = 1; // -1 - to go backwards | |
var nextIndex = ((currentIndex + listLength) + dir) % listLength; |
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
// returns an array of src values for an currently selected element | |
copy([].slice.call($0.querySelectorAll('img')).map(function(el){ return el.getAttribute('src'); })) |
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 safeParse(n) { | |
n = +n; | |
if (isNaN(n)) throw new TypeError('NANUMERR'); | |
if (0 > n) throw new TypeError('NEGNUMERR'); | |
return n | |
} | |
function safeFixed(n) { |
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
{"489":{"title":"chrome.bookmarks - Google Chrome","url":"https://developer.chrome.com/extensions/bookmarks#method-getTree"},"490":{"title":"Modern Web Apps With React and Redux - Reducers and Actions","url":"https://code.tutsplus.com/courses/modern-web-apps-with-react-and-redux/lessons/reducers-and-actions"},"491":{"title":"Life Less Literary - The Adventures of Dan Sumption","url":"http://www.sumption.org/"},"492":{"title":"Feature Toggles","url":"http://martinfowler.com/articles/feature-toggles.html"},"493":{"title":"The FACE of Amazon","url":"https://sites.google.com/site/thefaceofamazon/home"}} |