Bill Burcham Bill

View morse_fsa.rb
1 2 3 4 5 6 7 8 9 10
 
require 'singleton'
 
# This is a parser pattern based on regexp as lexer.
# Express your tokens as parenthesized regexps separated by
# alternation (|). Erroneous input causes immediate return.
module Parse
def parse( s, p, &block)
i = 0
while i < s.length do
View morse_regexp.rb
1 2 3 4 5 6 7 8 9 10
require 'singleton'
 
# This is a parser pattern based on regexp as lexer.
# Express your tokens as parenthesized regexps separated by
# alternation (|). Erroneous input causes immediate return.
module Parse
def parse( s, p, &block)
i = 0
while i < s.length do
# could pass i to match and use block form in newer lib
View application_controller.rb
1 2 3 4 5 6 7 8 9 10
before_filter :set_database_for_cluster_stuff
 
# SourceSpecific and subclasses (Content, Cluster) take up a lot of space so we want them in
# their own per-Domain databases. This hook injects the appropriate database connection based
# on the Domain gleaned from the request so subsequent access (during this request)
# will go to the appropriate database.
def set_database_for_cluster_stuff
config = ActiveRecord::Base.configurations[RAILS_ENV]
# Get the database name from the Domain
View gist:96776
1 2 3 4 5 6 7 8 9 10
# capture a yaml dump of an object like this:
# capture { y request }
module Kernel
def capture # pass a block to capture
old_stdout = $stdout
out = StringIO.new
$stdout = out
begin
yield
ensure
View gist:95507
1 2 3 4 5
# the approved way to add methods to example groups in rspec
# from David Chelimsky's comment here http://www.benmabey.com/2008/06/08/writing-macros-in-rspec/
Spec::Runner.configure do |config|
config.include(AssignMacro, :type => :controllers)
end
View gist:95498
1 2 3 4 5 6 7 8 9 10
module Spec
module Rails
class ControllerContext < Rails::Context
module ContextEvalInstanceMethods
def setup_extra
(class << @controller; self; end).class_eval do
include ControllerInstanceMethods
end
@controller.integrate_views! if @integrate_views
@controller.session = session
View Optimizing For Patches.rb
1 2 3 4 5 6 7 8 9
# BAD:
foo.bar = 25
foo.biz = 'Hello World'
foo.bazzle = 42
 
# GOOD:
foo.bar = 25
foo.biz = 'Hello World'
foo.bazzle = 42
View seed-fu.rb.diff
1 2 3 4 5 6 7 8 9 10
===================================================================
--- vendor/plugins/seed-fu/lib/seed-fu.rb (revision 3419)
+++ vendor/plugins/seed-fu/lib/seed-fu.rb (working copy)
@@ -20,7 +20,7 @@
raise "You must set at least one constraint." if constraints.empty?
@constraints = []
constraints.each do |constraint|
- raise "Your constraint `#{constraint}` is not a column in #{@model_class}. Valid columns are `#{@model_class.column_names.join("`, `")}`." unless @model_class.column_names.include?(constraint.to_s)
+ raise "Your constraint `#{constraint}` is not a column in #{@model_class}. Valid columns are `#{@model_class.column_names.join("`, `")}`." unless @model_class.column_names.include?(constraint.to_s) || association = @model_class.reflect_on_association(constraint)
@constraints << constraint.to_sym
View blogger_comment_block.html
1 2 3 4 5 6 7 8 9 10
<dl id='comments-block'>
<dt class='comment-author openid-comment-icon' id='c5069974981380830367'>
<a name='c5069974981380830367'></a>
<a href='http://meme-rocket.com/' rel='nofollow'>Bill</a>
said...
</dt>
 
<dd class='comment-body'>
<p>testing an OpenID comment</p>
</dd>
View recognize_path.rb
1 2 3 4 5 6 7 8 9 10
# This is an attempt at an improved version of params_for or rspec rails. It is meant to
# support recognition of paths when the Rails environment has been extended via patches like these:
# http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2
# http://svn.danwebb.net/external/rails/plugins/request_routing/trunk/README
# So instead of route :conditions having only :method, they may now have other data such as :domain
def recognize_path( path, options)
if options[:host].kind_of?( Array )
result = options[:host].collect{ | h | route( path, options.merge( :host => h) ) }
else
begin
Something went wrong with that request. Please try again.