I hereby claim:
- I am boone on github.
- I am boone (https://keybase.io/boone) on keybase.
- I have a public key whose fingerprint is 7713 6FEA DE34 477B 241F E9EB 9D8A 85BC B79C C67E
To claim this, I am signing this object:
# original slow method to find a number plus a divider (|) | |
# at the start of a line | |
def find_num(file, num) | |
found = false | |
File.read(file).each do |line| | |
if line.chomp.split('|', -1)[0] == num | |
found = true | |
break | |
end | |
end |
# file_column Shoulda macro, based off the Paperclip method given here: | |
# http://giantrobots.thoughtbot.com/2008/3/18/for-attaching-files-use-paperclip#comment--614050918 | |
# pass the extra option :magick => true to test the extra method for the columns that use RMagick | |
def self.should_have_file_column(attachment, options = {}) | |
klass = described_type | |
fields = ["#{attachment}", "#{attachment}=", "#{attachment}_temp", "#{attachment}_temp=", | |
"#{attachment}_dir", "#{attachment}_just_uploaded?", "#{attachment}_options", | |
"#{attachment}_relative_dir", "#{attachment}_relative_path"] | |
fields << "#{attachment}_magick_after_assign" if options[:magick] | |
should "have_file_column #{attachment}" do |
# monkey patch to allow authlogic's *_credentials cookies set the HttpOnly bit | |
# put this file in config/initializers/authlogic.rb and set the value after | |
# instantiating your session model, e.g. | |
# @user_session = UserSession.new(params[:user_session]) | |
# @user_session.httponly = true | |
module Authlogic | |
module Session | |
module Cookies | |
module Config |
class Project < ActiveRecord::Base | |
has_many :tasks | |
accepts_nested_attributes_for :tasks, :reject_if => :all_blank, :allow_destroy => true | |
def validate | |
# require a minimum of one task | |
undestroyed_task_count = 0 | |
tasks.each { |t| undestroyed_task_count += 1 unless t.marked_for_destruction? } |
# Ruby unexpected behavior when using .clone or .dup on a hash (or array) | |
# create a hash and freeze it so it shouldn't be modified | |
MY_HASH = { :one => { :first => 'eins', :second => 'zwei' } }.freeze | |
puts MY_HASH.inspect # {:one=>{:first=>"eins", :second=>"zwei"}} | |
new_hash = MY_HASH.dup # copy the hash, unfrozen | |
new_hash[:one][:second] = 'dos' |
# Monkey patch for CVE-2012-2660 and CVE-2012-2694 on Rails 2.3.14 | |
# put this file in your config/initializers directory | |
# comments/corrections: https://gist.github.com/2854095 | |
# Strip [nil] from parameters hash | |
# based on a pull request from @sebbacon | |
# https://github.com/rails/rails/pull/6580 | |
module ActionController | |
class Request < Rack::Request |
# Monkey patch for CVE-2012-2695 on Rails 2.3.14 | |
# put this file in your config/initializers directory | |
# comments/corrections: https://gist.github.com/2921706 | |
# Ruby on Rails SQL Injection | |
# based on a patch from @presidentbeef | |
# https://rubyonrails-security.googlegroups.com/attach/aee3413fb038bf56/2-3-sql-injection.patch?view=1&part=3 | |
module ActiveRecord | |
class Base |
# Monkey patch for CVE-2012-5664 on Rails 2.3.14 | |
# put this file in your config/initializers directory | |
# comments/corrections: https://gist.github.com/2921706 | |
# Ruby on Rails SQL Injection | |
# based on a patch from @tenderlove | |
# https://rubyonrails-security.googlegroups.com/attach/23daa048baf28b64/2-3-dynamic_finder_injection.patch?view=1&part=2 | |
module ActiveRecord | |
class Base |
I hereby claim:
To claim this, I am signing this object:
# truncate string by byte limit | |
# | |
# str - String | |
# limit - Maximum number of bytes | |
# | |
# Returns a String | |
def limit_string(str, limit) | |
limited_string = "" | |
str.each_char do |c| |