Skip to content

Instantly share code, notes, and snippets.

View simonrenoult's full-sized avatar
🏠
Working from home

Simon Renoult simonrenoult

🏠
Working from home
View GitHub Profile
@simonrenoult
simonrenoult / inheritance.coffee
Created February 26, 2014 16:14
Inherit parent property in Backbone
# Inherits parent events and allow overriding.
@events = _.extend {}, CardView::events, @events
# Call parent initialize method
SpellsCreateView.__super__.initialize.apply @,arguments
@simonrenoult
simonrenoult / Gulpfile.js
Created December 23, 2014 17:05
Gulpfile with browserify, handlebars, webserver, lint, minification, bower, watch, reload
var gulp = require('gulp'),
del = require('del'),
plugins = require('gulp-load-plugins')(),
bower = require('main-bower-files'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
browserify = require('browserify'),
browserSync = require('browser-sync');
var conf = {
@simonrenoult
simonrenoult / bumper.sh
Created January 21, 2015 02:47
Version bumper
#!/bin/bash
# Borrowed from a github gist somewhere on the Internet, can't find the source :(
# works with a file called VERSION in the current directory,
# the contents of which should be a semantic version number
# such as "1.2.3"
# this script will display the current version, automatically
# suggest a "minor" version update, and ask for input to use
#!/usr/bin/env node
@simonrenoult
simonrenoult / config.rb
Created September 5, 2013 11:05
Default Compass configuration file.
# Require any additional compass plugins here.
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "stylesheets"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"
# You can select your preferred output style here (can be overridden via the command line):
@simonrenoult
simonrenoult / typeChecking.js
Last active December 29, 2015 07:49
Checking types.
// Props to : http://techblog.badoo.com/blog/2013/11/01/type-checking-in-javascript/
var type = function (o) {
// handle null in old IE
if (o === null) {
return 'null';
}
// handle DOM elements
if (o && (o.nodeType === 1 || o.nodeType === 9)) {
@simonrenoult
simonrenoult / random.js
Created November 25, 2013 10:38
Generate a random number. Default range is 10 000. Will fail with a boolean (range will be cast into a number).
var getRandomID = function ( range ) {
var r = range;
if ( isNaN ( r ) ) {
r = 10000;
}
return Math.floor ( Math.random() * r );
};
@simonrenoult
simonrenoult / inheritance.js
Last active December 29, 2015 07:59
Classical inheritance. Use Object.create to inherit object. Javascript >= 1.8.5
var Parent = function ( settings ) {
this.name = settings.name;
};
Parent.prototype.greet = function () {
console.log ( 'Hello ' + this.name );
};
var Child = function ( settings ) {
Parent.call ( this, settings );
@simonrenoult
simonrenoult / hexToRGB.coffee
Created December 20, 2013 14:28
Hexadecimal color to RGB.
color = '#' + ( @model.get 'stroke_color' )
.map ( color ) ->
xColor = color.toString 16
if xColor.length is 1 then "0" + xColor else xColor
.reduce ( prev, cur, i ) ->
if i < 3 then prev + cur else prev
@simonrenoult
simonrenoult / hexToRGBA.coffee
Created December 20, 2013 14:28
Hexadecimal color to RGBA.
color = '#' + ( @model.get 'stroke_color' )
.map ( color ) ->
xColor = color.toString 16
if xColor.length is 1 then "0" + xColor else xColor