Skip to content

Instantly share code, notes, and snippets.

View fupslot's full-sized avatar
💭
I may be slow to respond.

Eugene Brodsky fupslot

💭
I may be slow to respond.
View GitHub Profile
@fupslot
fupslot / unique
Created October 29, 2015 13:44
javascript, unique, uniq, filtering
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;
@fupslot
fupslot / guid
Created November 2, 2015 14:40
javascript, guid, uid, id
function guid(){
function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
@fupslot
fupslot / requestAnimFrame.js
Last active November 17, 2015 11:31 — forked from joelambert/README
Drop in replacements for setTimeout()/setInterval() that makes use of requestAnimationFrame() where possible for better performance
// 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);
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
};
}
@fupslot
fupslot / createBoundingBox
Last active February 2, 2016 16:03
Draws a bounding box for a given element on the page
/*
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');
@fupslot
fupslot / swap_variables.js
Created February 8, 2016 13:08
swap variable values (not temporary variable)
// 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);
var currentIndex = 0;
var listLength = 9;
var dir = 1; // -1 - to go backwards
var nextIndex = ((currentIndex + listLength) + dir) % listLength;
// returns an array of src values for an currently selected element
copy([].slice.call($0.querySelectorAll('img')).map(function(el){ return el.getAttribute('src'); }))
function safeParse(n) {
n = +n;
if (isNaN(n)) throw new TypeError('NANUMERR');
if (0 > n) throw new TypeError('NEGNUMERR');
return n
}
function safeFixed(n) {
{"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"}}