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 gulp = require('gulp'); | |
var concat = require('gulp-concat-util'); | |
var through = require('through'); | |
var gutil = require('gulp-util'); | |
var refObj = {wallOfText: ''}; | |
function write(file) { | |
refObj.wallOfText += "/* " + file.path + " */" + gutil.linefeed; | |
this.emit('data', file); | |
} |
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
require 'goliath' | |
require 'http_router' | |
# https://github.com/joshbuddy/http_router | |
HttpRouter::Rack.override_rack_builder! | |
class RackRoutes < Goliath::API | |
map('/get/:id') do |env| | |
[200, {'Content-type' => 'text/plain'}, ["My id is #{env['router.params'][:id]}\n"]] | |
end |
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
What is the best way to model user/follower (twitter style) relationships with mongo? Most prominent solution is to embed an array of followers ids in every user object. I'm an idealist, and believe that if we are modeling twitter, we eventually will run into a situation when a user has millions of followers which will blow. The relational many_to_many is not easy to model with mongo, mongo_id tries to offer some implementation of basic associations, but the many_no_many, or has_many through is not there yet and I doubt it ever will be. | |
My solution is a compromise between relational normalization and "embed everything in one document". | |
class User | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
# user will have many followerships, each will embedd a follower user, | |
# the user_id is stored on the followership object |
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
$.extend(Backbone.Model.prototype, { | |
hasMany: function(collectionName, associationColumn, opts) { | |
var parent = this, | |
associationName = (collectionName.substr(0, 1).toLowerCase() + collectionName.substr(1)), | |
options = $.extend({ parentId: 'id' }, opts), | |
collection; | |
this[associationName] = function() { | |
collection = window[collectionName].select(function(child) { | |
return child.get(associationColumn) == parent.get(options['parentId']); |
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
(function(){ | |
function isFileReady ( readyState ) { | |
// Check to see if any of the ways a file can be ready are available as properties on the file's element | |
return ( ! readyState || readyState == 'loaded' || readyState == 'complete' ); | |
} | |
var p = document.getElementsByTagName('script'), | |
p = p[p.length-1]; | |
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
### | |
Lightweight Backbone Cache | |
Mike Knoop, 2012 (knoopgroup.com, zapier.com) | |
Simply execute this script file sometime after you load Backbone. | |
It hooks into the Backbone sync function to give a lightweight local | |
cache for models and collections. Will work for both models and collections. | |
Only GET requests are eligible for cacheing and caches are stored by URL. |
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
include ActiveSupport | |
["app/**/", "lib/**/"].each do |glob| | |
Dir.glob(glob).each do |dir| | |
Dependencies.autoload_paths << File.join(File.dirname(__FILE__), dir) | |
end | |
end |
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
{ | |
browser : 'Chrome', | |
mail : 'Sparrow', | |
calendar : 'iCal', | |
twitter : 'Twitter.app', | |
campfire : 'Propane', | |
contacts : 'Cobook', | |
terminal : 'iTerm2', | |
editor : 'vim', | |
notes : 'Evernote', |
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
$ history | awk {'print $2, $3, $4'} | sort | uniq -c | sort -k1 -rn | head -n 30 | |
610 git status | |
568 git commit -m | |
491 git add . | |
252 git push origin | |
176 bundle | |
138 rails s | |
128 ls | |
120 git commit --amend | |
114 git reset --hard |
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 extend = function(child, parent) { | |
for (var key in parent) { | |
if(parent.hasOwnProperty(key)) child[key] = parent[key]; | |
} | |
function ctor() { | |
this.constructor = child; | |
} | |
ctor.prototype = parent.prototype; |
OlderNewer