This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before_filter :load_${1:model}, :except => [ :index, :new, :create ] | |
before_filter :build_${1}, :only => [ :new, :create ] | |
def index | |
self.page_title << '${1/(^|_)(\w)/\U$2/g}s' | |
@${1}s = ${1/(^|_)(\w)/\U$2/g}.new_search(search_params) | |
end | |
def new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def globals(root = Module) | |
root.constants.collect do |name| | |
object = eval(name) rescue nil | |
if (object === Module || object === Class) | |
name | |
elsif (object.is_a?(Module) || object.is_a?(Class)) | |
globals(object).collect do |subname| | |
[ name, subname ].join('::') | |
end << name | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Replug hack | |
# - Local install of plugin | |
require 'rubygems' | |
# Rails Plugin Manager. | |
# | |
# Listing available plugins: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# monkey patch HTTParty to use a configurable timeout | |
module HTTParty | |
class Request | |
private | |
def http | |
http = Net::HTTP.new(uri.host, uri.port, options[:http_proxyaddr], options[:http_proxyport]) | |
http.use_ssl = (uri.port == 443) | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
http.open_timeout = http.read_timeout = options[:timeout].to_i if options[:timeout].to_i > 0 | |
http |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_parse_address | |
[ | |
[ '[email protected]', [ '[email protected]', nil ] ], | |
[ '[email protected]', [ '[email protected]', nil ] ], | |
[ '[email protected] (Amy Test)', [ '[email protected]', nil ] ], | |
[ 'Bob Test <[email protected]>', [ '[email protected]', 'Bob Test' ] ] | |
].each do |test_case| | |
assert_equal test_case[1], Message.parse_email_address(test_case[0]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.each(key_column = :id, &block) | |
connection.select_values("SELECT `#{key_column}` FROM `#{table_name}`").each do |key| | |
begin | |
yield(find(key)) | |
rescue ActiveRecord::RecordNotFound | |
# Ignore records which may have been deleted between the time the | |
# list is created and the record is fetched. | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_filter :set_time_zone | |
protected | |
# -- Page Title ----------------------------------------------------------- | |
def page_title | |
@page_title ||= [ ] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.link(account, user, params = nil) | |
found = find(:first, :conditions => { :account_id => account.to_id, :user_id => user.to_id }) | |
if (found) | |
found.update_attributes!(params) if (params) | |
found | |
else | |
create_params = { :account_id => account.to_id, :user_id => user.to_id } | |
create_params.merge(params) if (params) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Multiplexer | |
instance_methods.each do |m| | |
undef_method m unless(m.match(/^__/)) | |
end | |
def initialize(*objects) | |
@objects = objects | |
end | |
def method_missing(m, *args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require File.dirname(__FILE__) + '/../config/environment' | |
conn = ActiveRecord::Base.connection | |
STDOUT.sync = true | |
while (true) | |
print "\e[;H" |