This file contains hidden or 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
| require 'benchmark' | |
| require 'json' | |
| require 'redis' | |
| def rand_string(len) | |
| rand(36**len).to_s(36) | |
| end | |
| random_data = Array.new(1000000).map do | |
| { field1: rand_string(100), field2: rand_string(100), field3: rand_string(100), field4: rand(10000) } |
This file contains hidden or 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
| function lexer(code) { | |
| var strings = [], | |
| normalize = function(code) { | |
| return code.replace(/\(/g, " ( ") | |
| .replace(/\)/g, " ) ") | |
| .replace(/\s\s*/g, " ") | |
| .replace(/^\s*/g, "") | |
| .replace(/\s*$/g, ""); | |
| }; | |
| code = code.replace(/(".*?")/g, function(str) { return "ç" + (strings.push(str) - 1) + "ç"; }); |
This file contains hidden or 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 Cacheable = { | |
| mixed: function(klass) { | |
| var klassInit = klass.prototype.init || function() {}, | |
| superFetch = klass.prototype.fetch; | |
| /* Need to decorate the method by hand */ | |
| klass.prototype.init = function() { | |
| console.log(klass._instance) | |
| if (!klass._instance) { | |
| klass._instance = (klassInit.apply(this, arguments) || this); |
This file contains hidden or 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
| {type: "image", data: {}} | |
| {type: "post", data: {}} | |
| var Element = Backbone.Model.extend({ | |
| initialize: function(options) { | |
| }, | |
| subtypes: { | |
| "image": Image, | |
| "post": Post | |
| }, |
This file contains hidden or 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 Votable = { | |
| mixed: function(klass) { | |
| var events = { | |
| "click .js-votes-plus": "plusVote", | |
| "click .js-votes-minus": "minusVote", | |
| }, | |
| proto = klass.prototype | |
| proto.events = _.extend({}, events, proto.events) | |
| }, | |
| plusVote: function(e) { |
This file contains hidden or 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
| /* Base classes */ | |
| var BaseView = R.extend(Backbone.View, { | |
| init: function() { | |
| return Backbone.View.apply(this, arguments) | |
| }, | |
| render: function() { | |
| var model = (this.model || this.collection), | |
| data = model.toJSON(), | |
| html = this.template(data) |
This file contains hidden or 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
| /* Collections */ | |
| var PostCollection = R.extend(BaseCollection, { | |
| model: Post, | |
| /* DEBUG */ | |
| fetch: function(options) { | |
| var PostFactory = Solipsist.Factory({ | |
| id: Solipsist.Factory.int_sequence(), | |
| title: "Soy un post", | |
| description: "Soy una descripción de un post", |
This file contains hidden or 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
| /* Router */ | |
| var AppRouter = R.extend(SmartRouter, { | |
| init: function() { | |
| this._super() | |
| this.hottest() | |
| }, | |
| routes: { | |
| "": "index", | |
| "latest": "latest", |
This file contains hidden or 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
| distance: function(coords) { | |
| var barPos = this.get("location"), | |
| R = 6371*1000, | |
| dtr = Math.PI / 180, | |
| lat1 = coords.latitude*dtr, lon1 = coords.longitude*dtr, | |
| lat2 = barPos.latitude*dtr, lon2 = barPos.longitude*dtr, | |
| x = (lon2-lon1) * Math.cos((lat1+lat2)/2), | |
| y = (lat2-lat1), | |
| d = Math.sqrt(x*x + y*y) * R; |
This file contains hidden or 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 AnimatedRegion = Base.Region.extend({ | |
| show: function(view, dir) { | |
| this.forward = !dir; // true or false | |
| Base.Region.prototype.show.call(this, view); | |
| }, | |
| animationClass: "slide", | |
| open: function(view) { | |
| this.el = this.$el.get(0); | |
| var from = this.currentView, | |
| anim = this.animationClass, |