Skip to content

Instantly share code, notes, and snippets.

View milushov's full-sized avatar
😏
crafting new bugs

roma milushov

😏
crafting new bugs
View GitHub Profile
@sudodoki
sudodoki / gulpfile.js
Created December 14, 2014 18:20
Adds a list of files in resulting concatenated file
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);
}
@igrigorik
igrigorik / rack_routes.rb
Created March 29, 2011 04:17
Goliath + http_router.rb
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
@dmitryame
dmitryame / followers association with mongoid twitter style
Created April 2, 2011 20:29
followers association with mongoid twitter style
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
@scottharvey
scottharvey / Backbone.js has_many and belongs_to
Created April 18, 2011 05:20
This snippet allows you to define relationships between you backbone models
$.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']);
@arestov
arestov / gist:1543229
Created December 31, 2011 07:22
non blocking js load
(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];
@mikeknoop
mikeknoop / backbonecache.coffee
Created February 7, 2012 05:12
Backbone Simple Cache
###
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.
@thegrubbsian
thegrubbsian / rails_engine_test.rb
Created March 18, 2012 19:07
blog: Emulate Rails auto loading for testing engines
include ActiveSupport
["app/**/", "lib/**/"].each do |glob|
Dir.glob(glob).each do |dir|
Dependencies.autoload_paths << File.join(File.dirname(__FILE__), dir)
end
end
{
browser : 'Chrome',
mail : 'Sparrow',
calendar : 'iCal',
twitter : 'Twitter.app',
campfire : 'Propane',
contacts : 'Cobook',
terminal : 'iTerm2',
editor : 'vim',
notes : 'Evernote',
@steveklabnik
steveklabnik / log.txt
Created August 19, 2012 09:59
A fun shell script from #euruku
$ 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
@milushov
milushov / test.js
Created October 10, 2012 03:08
js inheritance
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;