Skip to content

Instantly share code, notes, and snippets.

View fix_underscore.js
// add methods ending in 'f' to flip first two args
_.extend(_,_.reduce(_.keys(_),function(m,k){m[k+'f']=function(a,b){return _[k](b,a)};return m},{}));
// add a 'flip' property to functions (loses context if important):
Function.prototype.flip = function() {
var args = [].slice.apply(arguments);
var tmp = args[0]; args[0] = args[1]; args[1] = args[0];
return this.apply(this, args);
rhysbrettbowen / gist:6529733
Last active Dec 22, 2015
how to get next friday
View gist:6529733
tricky one, but doable. You do want to get the number day, so Zuojiang is close, but setting date may not work because of the end of the month...
so get the day:
var date = new Date();
var day = date.getDay();
now we need to normalize those numbers to see how many days forward we need to move. Friday is day 5, but we really want it at day 7 (or 0). so we add 2 and take the modulus of 7.
var normalizedDay = (day + 2) % 7;
rhysbrettbowen / gist:5918435
Created Jul 3, 2013
AdviceFactory interface choices
View gist:5918435
// put in name:
Factory.register('MovableBoard', {
'base': 'WidgetBoard',
'widget': WidgetContainer,
'enterDocument.override': fn(){
View gist:4090018
I'm not saying you can't build larger applications using Backbone, I'm just saying the journey to completing one and then maintaining it will be harder. Large javascript application used to bw written without any frameworks but I'm not bringing them up as examples. What would be interesting to see would be the same examples written across frameworks in terms of code written, code organization, maintainability and size.
The main issue as I see it is that people choose a framework for a project in a short period of time and larger frameworks tend to take time before you see where they shine. I hear people's reason for going with Backbone because it was really the first major MVC out there and because of it's popularity. When I hear why people go with another framework it's because of features - not popularity.
Add on to this whenever I've talked to people or read blogs on systems made with other frameworks the majority of talks on backbone are how to solve problems they encountered while talks about larger fr
View gist:3692331
var bound =, type, function);
// should dispatch event of type on provided targets (or else the src)[optional_targets]);
// will call unbind the event
// can do things like:
var bound =, type, function).fire();
rhysbrettbowen / goog.json.serialize for cycles
Created Aug 15, 2012
safe goog.json.serialize for cycles with description
View goog.json.serialize for cycles
The below I have changed from the goog.json.serialize. It's just a proof of concept so don't expect good code! it will return an array with two items. The first item is the json. The second will describe any cycles that were found and are structured like so:
//this is an array of the keys to get to the value where the cycle was
//this is the number of steps along the keys that the object was found
so if you're returned something like:
[['foo', 'bar'],1]