Skip to content

Instantly share code, notes, and snippets.

View filippomangione's full-sized avatar

Filippo Mangione filippomangione

  • Boolean Careers
  • Milano
View GitHub Profile
@there4
there4 / .jshintrc
Last active March 20, 2020 13:46
JSHint Configuration, with requirejs
{
// --------------------------------------------------------------------
// 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
@fnakstad
fnakstad / gist:5383750
Created April 14, 2013 18:43
Attaches a function called "seed" to Mongoose models, which basically wraps the create function, but returns a promise. This way seeding can be done through a promise chain.
var mongoose = require('mongoose');
mongoose.Model.seed = function(entities) {
var promise = new mongoose.Promise;
this.create(entities, function(err) {
if(err) { promise.reject(err); }
else { promise.resolve(); }
});
return promise;
};
@funkjedi
funkjedi / marionette.handlebars.js
Last active April 5, 2024 14:29
Integrates Handlebars with Marionette. First attempts to load pre-compiled templates, then by selector, and finally via XHR.
/**
Usage: Just include this script after Marionette and Handlebars loading
IF you use require.js add script to shim and describe it in the requirements
*/
(function(Handlebars, Marionette) {
Marionette.Handlebars = {
path: 'templates/',
extension: '.handlebars'
};
@esamattis
esamattis / asevents.js
Last active October 22, 2021 20:41
Use listenTo/stopListening from Backbone.js with any DOM element
/**
* Use listenTo/stopListening from Backbone.js with any DOM element
*
* Example:
*
* view.listenTo(asEvents(window), "resize", handler);
*
* and the listener will be remove automatically on view.remove() or
* view.stoplistening()
*
@lastguest
lastguest / JavascriptMiddlewares.js
Created September 20, 2013 15:50
Wrap a function with a middleware decorator.
// Generate a middleware
function middleware(mw){
return function(fn){
fn = (typeof fn == "function") ? fn : window[fn];
return function(){
var args = arguments || [];
if(false !== mw.apply(this,args)) fn.apply(this,args);
};
};
}
@branneman
branneman / better-nodejs-require-paths.md
Last active April 27, 2024 04:16
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@Paratron
Paratron / agents.md
Last active February 26, 2024 12:28
Social Network Crawler User Agents

#Social Network Crawler User Agents Users can post URLs on a lot of different platforms nowadays. Most of those platforms will send a request to that URL to generate some preview data from it.

These are a couple of user agents I quickly tested out.

##Facebook

facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)
@lastguest
lastguest / dehydrateFloat.js
Created February 14, 2014 19:13
JavaScript Fixed Float Dehydratation
// Assuming 5 fixed digits
function dehydrateFloat(f){
return Math.floor(f.toFixed(5)*100000).toString(36);
}
function hydrateFloat(dryf){
return (parseInt(dryf,36)/100000).toFixed(5);
}
@demisx
demisx / angularjs-providers-explained.md
Last active May 17, 2024 03:38
AngularJS Providers: Constant/Value/Service/Factory/Decorator/Provider
Provider Singleton Instantiable Configurable
Constant Yes No No
Value Yes No No
Service Yes No No
Factory Yes Yes No
Decorator Yes No? No
Provider Yes Yes Yes

Constant

@JamieMason
JamieMason / annotated-jshintrc.txt
Created June 13, 2014 10:59
An annotated .jshintrc file, based on the docs at http://jshint.com/docs/options.
{
/**
* Tell JSHint about global variables.
*/
"predef": [
// https://github.com/pivotal/jasmine
"after",
"afterEach",