Skip to content

Instantly share code, notes, and snippets.

View coryschires's full-sized avatar
💭
Code King

Cory Schires coryschires

💭
Code King
View GitHub Profile
@coryschires
coryschires / encoding_fixer.rb
Created September 20, 2011 19:08
Script to replace bad encoding with HTML entities.
class EncodingFixer
ENCODING_TO_ENTITY = {
"\222" => "’",
"\223" => "“",
"\224" => "”",
"\205" => "…",
"\226" => "–",
"\227" => "—"
}
#!bash
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
@coryschires
coryschires / factory_girl_question.rb
Created August 5, 2011 20:24
factory_girl_question.rb
# Having trouble getting nested factories working. Is this not supported? Seems like it would be.
#
# The associations are definitely setup correctly in the models:
# A campaign has_many :placements and a placement has_many :deliveries
#
@campaign = Factory(:campaign, :placements => [
Factory(:placement, :agency_rate => 3.00, :deliveries => [
Factory(:delivery, :quantity => 600),
Factory(:delivery, :quantity => 100)
]),
@coryschires
coryschires / cuke_error
Created July 22, 2011 14:25
cuke_error
Background: Analyst logged in and viewing campaigns # features/campaigns.feature:6
Given campaign "ABC001" has ordered "50_000" and so far billed: # features/step_definitions/custom_steps.rb:25
| posting period | billable total | billed total |
| Jun 2009 | 10_000 | 10_000 |
| Jul 2009 | 15_000 | 15_000 |
| Aug 2009 | 20_000 | 20_000 |
And campaign "ABC002" has ordered "250_000" and so far billed: # features/step_definitions/custom_steps.rb:25
| posting period | billable total | billed total |
| Jun 2009 | 100_000 | 100_000 |
| Jul 2009 | 50_000 | 50_000 |
# Any idea why this works:
named_scope :delivering_during, lambda { all(:include => {:campaign_billables => [:posting_period] }) }
# but this:
named_scope :delivering_during, all(:include => {:campaign_billables => [:posting_period] })
# raises "TypeError (Symbol as array index)"
@coryschires
coryschires / apply_role.rb
Created June 20, 2011 20:33
apply_role.rb
describe "AFTER CREATE apply_member_role" do
it "should apply the role of 'user' to the newly created user" do
user = Factory(:user)
user.role?('member').should be_true
end
end
@coryschires
coryschires / factory_girl_example.rb
Created June 20, 2011 18:33
factory_girl_example.rb
Factory.define :user do |f|
f.sequence(:email) { |n| "foo#{n}@example.com" }
f.email_confirmation { |u| u.email }
f.password "password"
f.password_confirmation { |u| u.password }
end
Factory.define :super_admin, :parent => :user do |f|
f.after_create { |user| user.roles << Role.find_or_create_by_name('super_admin') }
end
@coryschires
coryschires / stub_role.rb
Created June 20, 2011 18:09
stub_role.rb
# in spec helper
class User
def role?(role)
true
end
end
@coryschires
coryschires / index.html
Created May 16, 2011 17:33
splatter example for BNC
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<style>
.contenta {margin-top: 25px;}
.contenta h1 {color: #333; font-weight: normal; border-bottom: 1px solid #bbb; margin: 25px 0px; padding-bottom: 7px;}
.contenta h2 {color: #777; font-weight: normal; margin: 20px 0px 0px 2px;}
</style>
@coryschires
coryschires / test_dewey.rb
Created December 10, 2010 19:14
Get method returns nil when fetching a document
Dewey.authentication :client, :email => 'your-email', :password => 'your-pass'
id = Dewey.put(File.new('example.txt'), 'My Second Upload')
puts id # => in my case returned: document:1DDxIGsmK3wIJpdJC-qGK4y-R8onzDrBPm89y7BbO_Zg
original = Dewey.get(id)
puts original.inspect # => nil