Skip to content

Instantly share code, notes, and snippets.

// 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
rhysbrettbowen / gist:6529733
Last active December 22, 2015 20:59
how to get next friday
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
rhysbrettbowen / gist:5918435
Created July 3, 2013 14:31
AdviceFactory interface choices
// put in name:
Factory.register('MovableBoard', {
'base': 'WidgetBoard',
'widget': WidgetContainer,
'enterDocument.override': fn(){
},
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
@rhysbrettbowen
rhysbrettbowen / gist:3692331
Created September 10, 2012 17:29
Bound event object
var bound = goog.events.listen(src, type, function);
// should dispatch event of type on provided targets (or else the src)
bound.fire([optional_targets]);
// will call unbind the event
bound.unlisten();
// can do things like:
var bound = goog.events.listen(src, type, function).fire();
@rhysbrettbowen
rhysbrettbowen / goog.json.serialize for cycles
Created August 15, 2012 04:36
safe goog.json.serialize for cycles with description
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]