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
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 / 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);
@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 / 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 / abbriviate.js
Created August 24, 2015 13:10
abbriviate, ellipsis, filter, anguar
angular
.module('myProject', [])
.filter('abbreviate', function () {
// Hello World | abbreviate:6:2 //-> 'Hello...Wo'
// Hello World | abbreviate:5 //-> 'Hello...'
return function(str, num, prefix) {
if (str == null) { str = ''; }
if (num == null) { num = str.length; }
if (prefix == null) { prefix = 0; }
if (document.addEventListener) {
document.addEventListener('contextmenu', function(e) {
alert("You've tried to open context menu"); //here you draw your own menu
e.preventDefault();
}, false);
} else {
document.attachEvent('oncontextmenu', function() {
alert("You've tried to open context menu");
window.event.returnValue = false;
});
@fupslot
fupslot / memoize
Last active August 29, 2015 14:27
Memoization For Improved Application Performance
function memoize(fn) {
fn.memoize || (fn.memoize = {});
return function(arg) {
if (fn.memoize.hasOwnProperty(arg)) {
console.log('memoized //-> %s', arg);
return fn.memoize[arg];
}
else {
console.log('computed //-> %s', arg);
fn.memoize[arg] = fn(arg);
it('Property', inject(function($parse){
function Property(context, fieldName) {
this.$getter = $parse(fieldName);
this.$setter = this.$getter.assign;
this.$context = context;
}
Property.prototype.get = function() {
return this.$getter(this.$context);
};
Property.prototype.set = function(value) {
@fupslot
fupslot / index.html
Last active August 29, 2015 14:06
title with action buttons
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Title with action buttons</title>
<style id="jsbin-css">
.bar {
position: relative;
}
;(function($, window, document, undefined) {
'use strict';
var pluginName = 'FunnelViz'
, defaults = {
};
function init () {