Skip to content

Instantly share code, notes, and snippets.

@Chris927
Chris927 / dci_experiment.rb
Created February 6, 2012 09:28
DCI experiment, using the R82 domain
# the role
# TODO: should the class be named 'MatchCreator'? What the role does
# is independent of needs
module NeedToOtherNeedConnector
def connect_needs(from, to)
match = Match.new(:user => self, :from => from, :to => to)
end
end
# the context
@Chris927
Chris927 / second_generator.rb
Created August 28, 2011 19:27
Adding a second generator to a gem
require 'rails/generators/migration'
# must be placed in the gem's dir 'lib/generators/my_gem/second/second_generator.rb'
module MyGem
# TODO: this module tries to DRY up a bit, should be elsewhere in
# its own file
module MigrationGenerator
def self.included(base)
base.extend(ClassMethods)
@Chris927
Chris927 / generic_repo.rb
Created August 21, 2011 09:51
Repository Ideas (DDD style) for Rails
module GenericRepo
def self.included(base)
base.class_eval do
extend ClassMethods
end
end
module ClassMethods
attr_accessor :model
def create(params)
@Chris927
Chris927 / gist:1128612
Created August 5, 2011 21:53
How to install sparkleshare on Ubuntu 10.04
# add repos and update apt
sudo add-apt-repository ppa:git-core/ppa
sudo add-apt-repository ppa:warp10/sparkleshare
sudo apt-get update
# install it
sudo apt-get install sparkleshare
@Chris927
Chris927 / reverse.coffee
Created July 13, 2011 08:08
Reverse a string in CoffeeScript
reverse = (s) ->
if s.length < 2 then s else reverse(s[1..-1]) + s[0]
s = "Hello"
console.log "s=#{s}, s.reverse=#{reverse(s)}"
def chop(v, values)
ix = values.length / 2
m = values[ ix ]
return ix if v == m
return nil if values.length < 2
if v > m
ix + 1 + chop(v, values[ix+1..-1]) rescue nil
@Chris927
Chris927 / log excerpt
Created May 27, 2011 13:29
adding refinery to rails 3.0.7 app, sign up / redirect issue
Started GET "/users/sign_up" for 127.0.0.1 at 2011-05-27 15:24:18 +0200
Processing by Devise::RegistrationsController#new as HTML
SQL (1.1ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
SQL (0.3ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
Page::Translation Load (0.2ms) SELECT page_id AS id FROM "page_translations" WHERE "page_translations"."locale" = 'en'