Skip to content

Instantly share code, notes, and snippets.

View tadman's full-sized avatar
🤔
Enumerating

Scott Tadman tadman

🤔
Enumerating
View GitHub Profile
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
def test_parse_address
[
[ 'amy@amy.com', [ 'amy@amy.com', nil ] ],
[ 'bob@bob.com', [ 'bob@bob.com', nil ] ],
[ 'amy@test.com (Amy Test)', [ 'amy@test.com', nil ] ],
[ 'Bob Test <bob@bob.com>', [ 'bob@bob.com', 'Bob Test' ] ]
].each do |test_case|
assert_equal test_case[1], Message.parse_email_address(test_case[0])
end
end
# 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
#!/usr/bin/env ruby
# Replug hack
# - Local install of plugin
require 'rubygems'
# Rails Plugin Manager.
#
# Listing available plugins:
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
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
#!/usr/bin/env ruby
PASSPHRASE_CHARS = [ ?0..?9, ?A..?Z, ?a..?z ].collect { |c| c.collect }.flatten.collect { |c| "%c" % c }
cert_name = ARGV[0]
unless (cert_name)
print "Usage: genrsa <certname>"
exit(-1)
end
module ActionView
module Helpers
def write_asset_file_contents(joined_asset_path, asset_paths)
FileUtils.mkdir_p(File.dirname(joined_asset_path))
File.atomic_write(joined_asset_path, File.join(Rails.root, 'tmp')) { |cache| cache.write(join_asset_file_contents(asset_paths)) }
# Set mtime to the latest of the combined files to allow for
# consistent ETag without a shared filesystem.
mt = asset_paths.map { |p| File.mtime(asset_file_path(p)) }.max
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent env=!dont-vary
</IfModule>
# Force checking of /opt path for OS X macports binaries
if (File.exist?('/opt/local/bin/identify'))
Paperclip.options[:command_path] = '/opt/local/bin'
end
# Monkeypatch to get thumbnails working by allowing proper chaining
class Paperclip::Attachment
def callback(which)