Skip to content

Instantly share code, notes, and snippets.

View elskwid's full-sized avatar
🤡

Don Morrison elskwid

🤡
View GitHub Profile
@josevalim
josevalim / 0_README.md
Created September 13, 2012 21:52
Sinatra like routes in Rails controllers

Sinatra like routes in Rails controllers

A proof of concept of having Sinatra like routes inside your controllers.

How to use

Since the router is gone, feel free to remove config/routes.rb. Then add the file below to lib/action_controller/inline_routes.rb inside your app.

@supernullset
supernullset / levenshtein_ranking.coffee
Created October 17, 2012 19:13
Fuzzy string comparison/sort in javascript
curry = (fn)->
slice = Array.prototype.slice
args = slice.apply arguments, [1]
return ->
fn.apply null, args.concat(slice.apply arguments)
levenshteinD = (s,t) ->
if !s.length then return t.length
if !t.length then return s.length
@wesgarrison
wesgarrison / gist:3921560
Created October 20, 2012 01:10
October 19 2012 - rubygems.org - notes on server

[transcript from http://www.youtube.com/watch?v=z73uiWKdJhw and irc]

Why is the server unhappy?

  • Bundle API is 70%-80% of traffic and it has to resolve the dependency graph and Marshal
  • x Processes are spinning in Ruby with 380% (of 400% total CPU [4 x 100%])
  • x Bundle can only use vanilla gems, so that's why we have to use Marshal
  • Redis Heapsize
  • Diskspace

Timing - middle of the day US

$VERBOSE = nil
require File.expand_path('../rooby', __FILE__)
Person = Rooby::Class.new 'Person' do
define :initialize do |name|
@name = name
end
define :name do
@ahoward
ahoward / polluted.rb
Created November 8, 2012 16:15
ruby libs have *got* to stop doing this...
libs = ARGV.size == 0 ? all_gems : ARGV
list =
libs.
forkify(16){|lib| puts "#{ lib }..."; [lib, polluted_by(lib)]}.
sort_by{|pair| pair.last}
list.each do |lib, polluted|
puts "polluted_by('#{ lib }') #=> #{ polluted }"
@ahoward
ahoward / js-class.js
Created November 12, 2012 21:55
my latest favorite way to declare js classes...
//
var Grid = new Function();
Grid.initialize = function(){
var args = Array.prototype.slice.apply(arguments);
var grid = new Grid();
grid.initialize.apply(grid, args);
@stas
stas / Rakefile
Created November 22, 2012 15:51
Rails Engine: rake task and generator to DRY `spec/dummy`
#!/usr/bin/env rake
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec => :dummy_app) do |t|
t.pattern = File.expand_path('../spec/**/*_spec.rb', __FILE__)
end
task :default => :spec
desc 'Generates a dummy app for testing'
task :dummy_app => [:setup, :migrate]
@alecperkins
alecperkins / gist:4263031
Created December 11, 2012 22:44
CoffeeScript-friendly Backbone.Marionette module definition pattern.
# Since CoffeeScript wraps everything in a closure by default, the module
# definition function pattern that Marionette normally uses is unnecessary.
# (And cumbersome with having to indent everything.) Instead, creating the
# module at the very begining makes it available to everything in the file, and
# the initializers and exported classes can be added at the end of the file.
# (This relies on things like the App and Backbone being on window, but they
# already have to be for CoffeeScript-based code to work.)
# Create the module.
Foo = App.module 'Foo'
require 'rubygems'
require 'benchmark/ips'
class ExampleClass
def foo; 42; end
end
module ExampleMixin
def foo; 43; end
end
@practicingruby
practicingruby / mrdi.md
Created December 19, 2012 22:29
Models, Roles, Decorators, and Interactions -- A modest proposal for a toned done version of DCI that isn't as janky as Concerns.

Models, Roles, Decorators, and Interactions

A modest alternative to DCI that might be worth further thought

One of the problems with advancing the discussion on DCI is that we lack a comparable alternative pattern that has the same goals, but favors a low ceremony approach. The closest thing we have to that is Rails concerns, but they are more like distant relatives of the DCI concepts rather than first cousins, and that makes comparisions between the two approaches not especially fruitful.

I am considering the idea of experimenting with my own paradigm that captures the intent and purity of DCI, but with the convenience of concerns. Please note that this is just the starting point of a conversation, it is NOT a promise of comercially available cold fusion or a cure for cancer. It's just a gist with an idea on it I'd like to hear your thoughts on.

What if we had a top-level topology that was split into Models, **Rol