Skip to content

Instantly share code, notes, and snippets.

@davidjbeveridge
davidjbeveridge / test.coffee
Created April 23, 2012 16:23
My Coffee Script test. I am trying to figure out what is wrong with my scoping to make it not increment.
jQuery ->
count = 0
$("a").click (e) ->
e.preventDefault()
alert("Hello World #{++count}")
@davidjbeveridge
davidjbeveridge / attribute_observers.rb
Created March 28, 2012 03:01 — forked from mrgenixus/Gemfile
Attribute Observers
module ProofTest
class Model
def self.attr_reader property
define_method property do
puts "reading #{attributes[property]} from #{property}"
attributes[property]
end
end
def self.attr_writer property
@davidjbeveridge
davidjbeveridge / strategy.rb
Created January 31, 2012 01:36 — forked from mrgenixus/strategy.rb
Strategy Pattern
class Router
@@routes = {}
@name
attr_accessor :name
def Router.register ( name)
@@routes[name] = self
name
end
def Router.factory (klass_name)
created_route = @@routes[klass_name] || nil
# Don't know about better, but fewer lines:
def mock_controller
['test_request','test_response'].each {|fname| require "action_dispatch/testing/#{fname}" }
controller = ApplicationController.new
controller.perform_caching = true
controller.cache_store = ActiveSupport::Cache::MemoryStore.new
['request','response'].each {|r| controller.send("#{r}=", ActionDispatch.const_get("Test#{r.capitalize}").new) }
controller.initialize_template_class controller.response
controller.assign_shortcuts controller.request, controller.response