Skip to content

Instantly share code, notes, and snippets.

View pauljamesrussell's full-sized avatar

Paul Russell pauljamesrussell

View GitHub Profile
@pauljamesrussell
pauljamesrussell / one_account_to_csv.rb
Created April 22, 2012 22:42
A quick ruby script to take HTML exported from oneaccount.com and convert it to a CSV file of transactions for online banking.
# 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|
@pauljamesrussell
pauljamesrussell / i18n_debug.rb
Created December 4, 2011 23:23
Output debugging information about i18n translation lookups that are occurring.
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 / spec_helper.rb
Created November 9, 2011 23:15
RSpec matcher for ensuring a model is accepting nested attributes for an association, and accepting/rejecting the right values.
# 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
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)
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