Skip to content

Instantly share code, notes, and snippets.

[user]
name =
email =
[github]
user =
token =
[sendemail]
smtpuser =
smtpencryption = tls
smtpserver = smtp.gmail.com
/*
* Extend the Ajax.Autocompleter
*
* Defaults to using a json response.
*
* If the response looks like html, send it to the updateChoices() function.
* Otherwise assume it is json and build the unordered list from the json array.
* If you set the header to 404 when there are no results, the onComplete() function is not called.
*/
class A
def a_method
"a_method"
end
@@a_class_attribute = "A::a_class_attribute"
def a_class_attribute
@@a_class_attribute
end
named_scope :conditions, lambda { |args| {:conditions => args} }
named_scope :filter, lambda{ |options|
options ||= {}
options.stringify_keys!
scope = scoped(Hash.new)
unless options['active'].blank?
scope = scope.conditions :active => options['active']
end
module UpdatedAtLocking
def self.included(base)
base.alias_method_chain :update, :stale_object_detection
base.class_inheritable_accessor :updated_at_locking_enabled, :instance_writer => false
base.updated_at_locking_enabled = true
end
def updated_at_locking_enabled?
self.updated_at_locking_enabled == true
ActionController::Routing::RouteSet::Mapper
class ActionController::Routing::RouteSet::Mapper
def initialize(set)
@set = set
end
# Create an unnamed route with the provided +path+ and +options+. See
# SomeHelpfulUrl for an introduction to routes.
def connect(path, options = {})
puts "map.connect #{path}, #{options.inspect[1..-2]}"
##
# Like ck_fu ( http://github.com/r38y/ck_fu ) but not
# I really like ck_fu. But I am not fond of adding tests, rake tasks, and a whole plugin folder for
# one method, two helper methods and some css. I also made it safe for Rails 1.2.6.
#
# in app/helpers/application_helper.rb
def environment_div(options={})
return '' if (options.has_key?(:if) ? !options[:if] : RAILS_ENV.to_s == 'production' )
separator = options[:separator] || "|"
text = [content_tag(:strong, RAILS_ENV.to_s.titlecase)]
/*
* Extend the Event Object
*
* ready_dom: add functions to run on DOMContentLoaded
*
* ready_ajax: add functions to run after Ajax onComplete responses
*
* ready: add functions to run on both ready_dom & ready_ajax. These should
* be constructed so that running more than once will not have any
* side-effects.
##
# Include this in your app as config/initializers/identity_map.rb
# But don't really, this is untested and not used in any production code.
#
# It is a partial implementation of Martin Fowler's IdentityMap.
# http://martinfowler.com/eaaCatalog/identityMap.html
#
# Combined with QueryCache it is a complete implementation ( almost ).
#
module IdentityMap
# Sometimes tests just keep rolling on when you would really like
# them to die so you can inspect the database without teardown
# or the next setup
def test_something
x_it = proc{ puts "This test failed!"; Kernel.exit(1) }
class << x_it
def to_s; call; end
alias inspect to_s
end