Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Russell pauljamesrussell

View GitHub Profile
@pauljamesrussell
pauljamesrussell / spec_helper.rb
Created Nov 9, 2011
RSpec matcher for ensuring a model is accepting nested attributes for an association, and accepting/rejecting the right values.
View spec_helper.rb
# Use: it { should accept_nested_attributes_for(:association_name).and_accept({valid_values => true}).but_reject({ :reject_if_nil => nil })}
RSpec::Matchers.define :accept_nested_attributes_for do |association|
match do |model|
@model = model
@nested_att_present = model.respond_to?("#{association}_attributes=".to_sym)
if @nested_att_present && @reject
model.send("#{association}_attributes=".to_sym,[@reject])
@reject_success = model.send("#{association}").empty?
end
model.send("#{association}").clear
@pauljamesrussell
pauljamesrussell / i18n_debug.rb
Created Dec 4, 2011
Output debugging information about i18n translation lookups that are occurring.
View i18n_debug.rb
require 'i18n'
if (Rails.env.development? || Rails.env.test?) && ENV['DEBUG_TRANSLATION']
module I18n
class << self
def translate_with_debug(*args)
puts "Translate: #{args.inspect}"
translate_without_debug(*args)
end
alias_method_chain :translate, :debug
@pauljamesrussell
pauljamesrussell / one_account_to_csv.rb
Created Apr 22, 2012
A quick ruby script to take HTML exported from oneaccount.com and convert it to a CSV file of transactions for online banking.
View one_account_to_csv.rb
# Usage: ruby one_account_to_csv.rb < html_dump.html > transactions.csv
# First row has column titles.
$text = readlines.join
puts "Date,Type,Merchant,Debit,Credit"
$text.scan %r{<tr class="content">.*?</tr>}m do |line|
unless line =~ /colspan="5"/
values = line.scan(%r{<td.*?>(?:<[^/].*?>)*(.*?)</}).map {|v| v.first}
values.each do |value|
View gist:705533
GEM
remote: http://rubygems.org/
specs:
RedCloth (4.2.3-java)
abstract (1.0.0)
actionmailer (3.0.0)
actionpack (= 3.0.0)
mail (~> 2.2.5)
actionpack (3.0.0)
activemodel (= 3.0.0)
View gist:705530
source 'http://rubygems.org'
gem 'rails', '3.0.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
if defined?(JRUBY_VERSION)
gem 'activerecord-jdbc-adapter'
gem 'jdbc-sqlite3', :require => false
You can’t perform that action at this time.