View fix_underscore.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
View gist:6529733
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
View gist:5918435
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// put in name: | |
Factory.register('MovableBoard', { | |
'base': 'WidgetBoard', | |
'widget': WidgetContainer, | |
'enterDocument.override': fn(){ | |
}, |
View gist:4090018
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
View goog.json.serialize for cycles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |