Skip to content

Instantly share code, notes, and snippets.

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
class A
def a_method
"a_method"
end
@@a_class_attribute = "A::a_class_attribute"
def a_class_attribute
@@a_class_attribute
end
/*
* 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.
*/
[user]
name =
email =
[github]
user =
token =
[sendemail]
smtpuser =
smtpencryption = tls
smtpserver = smtp.gmail.com
@abriening
abriening / default.rb
Created May 4, 2011 13:17
Gem Install Chef Recipe
bash "install #{name} gems" do
cwd "/tmp/#{name}"
code <<-end_code
for gem_file in `ls *.gem`
do
gem install ./$gem_file
done
end_code
end
@abriening
abriening / connection_fix.rb
Created May 17, 2011 19:26 — forked from defunkt/connection_fix.rb
MySQL server has gone away fix
## https://gist.github.com/977188
#
# If your workers are inactive for a long period of time, they'll
# lose their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is lost.
#
# From: https://gist.github.com/238999
#
# Added retrying to prevent infinite loop.
@abriening
abriening / bash
Created September 10, 2011 14:40
Hijack a running nack_worker ( Pow server )
gem install hijack
ps aux | grep ruby
# andrew 10879 0.0 2.4 2538948 100668 ?? S 10:30AM 0:03.09 ruby .../node_modules/nack/bin/nack_worker .../config.ru /tmp/nack.56823.5122799426.sock
hijack 10879
class ApplicationController < ActionController::Base
rescue_from ActiveRecord::RecordNotFound, :with => :resource_not_found
rescue_from ActionController::RoutingError, :with => :check_request_uri_and_method
rescue_from AbstractController::ActionNotFound, :with => :page_not_found
rescue_from ActionController::MethodNotAllowed, :with => :method_not_allowed
@abriening
abriening / application_controller.rb
Created September 30, 2011 21:42
Add support for handling 405 Method Not Allowed & 501 Not Implemented
# As used with CanCan and Devise
class ApplicationController < ActionController::Base
protect_from_forgery
include ErrorResponseActions
rescue_from CanCan::AccessDenied, :with => :authorization_error
rescue_from ActiveRecord::RecordNotFound, :with => :resource_not_found
before_filter :authenticate!
#!/usr/bin/env ruby
filename = ARGV.pop
urls = []
processing_method = {}
File.open filename do |f|
while l = f.gets
if l =~ /.* prism rails\[([0-9]+)\]: .* Processing .* \[([A-Z]+)\]/
processing_method[$1] = $2
end