Skip to content

Instantly share code, notes, and snippets.

View filippomangione's full-sized avatar

Filippo Mangione filippomangione

  • Boolean Careers
  • Milano
View GitHub Profile
Verifying that +filippomangione is my blockchain ID. https://onename.com/filippomangione
@filippomangione
filippomangione / extend.js
Last active August 29, 2015 14:20
Extending objects
function extend() {
var args = Array.prototype.slice.call(arguments);
for(var i=1; i<args.length; i++) {
for(var key in args[i]) {
if(args[i].hasOwnProperty(key)) {
args[0][key] = args[i][key];
}
}
}
return args[0];
function openWindow(url, title, w, h) {
// Fixes dual-screen position
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
@filippomangione
filippomangione / querystring.js
Created November 26, 2014 18:11
querystring.js
var _ = require('./underscore.js');
/*
* Append querystring to the url
* @param string url
* @param object parameters
*/
function qs(url, params){
if(params){
@filippomangione
filippomangione / .jshintrc
Last active August 29, 2015 14:09 — forked from there4/.jshintrc
{
// --------------------------------------------------------------------
// JSHint Configuration, Strict Edition
// --------------------------------------------------------------------
//
// This is a options template for [JSHint][1], using [JSHint example][2]
// and [Ory Band's example][3] as basis and setting config values to
// be most strict:
//
// * set all enforcing options to true
@filippomangione
filippomangione / add_up.js
Created November 3, 2014 12:03
Add Up to 100%
var _ = require('./underscore.js');
function foo(l, target) {
var off = target - _.reduce(l, function(acc, x) { return acc + Math.round(x) }, 0);
return _.chain(l).
sortBy(function(x) { return Math.round(x) - x }).
map(function(x, i) { return Math.round(x) + (off > i) - (i >= (l.length + off)) }).
value();
}
@filippomangione
filippomangione / mousehold.js
Created August 18, 2014 17:42
Mousehold jQuery Event
(function($) {
function startTrigger(e,data) {
var $elem = $(this);
$elem.data('mouseheld_timeout', setTimeout(function() {
$elem.trigger('mouseheld');
}, e.data));
}
function stopTrigger() {
var $elem = $(this);
@filippomangione
filippomangione / console.js
Created June 12, 2014 12:55
A simple wrapper for console in browsers that don't support it.
(function() {
'use strict';
var method;
var noop = function () {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeStamp', 'trace', 'warn'
@filippomangione
filippomangione / promise.js
Created June 1, 2014 17:55
A simple promise implementation that meets the Promises/A+ spec.
function cbSucc(val) {
console.log("Got my value! Yay!", val);
}
function cbErr(val) {
console.log("D'oh!", val);
}
var defer = function () {
var state = 'pending';
@filippomangione
filippomangione / basename.js
Created May 22, 2014 09:55
Returns trailing name component of path.
var path = '/m/static/media/file-8861b49be6e21675f87b174cb824d79f.jpg';
var basename = path.split(/[\\/]/).pop();