code
stringlengths
1
1.73M
language
stringclasses
1 value
$:.unshift File.dirname(__FILE__) $:.unshift File.dirname(__FILE__) + '/../../lib' require 'test/unit' require 'object_ext' require 'micro_id'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/lib/egg' html_file = ARGV.shift unless html_file and File.exists?(html_file) raise "Usage: egg2ofx path/to/egg-html-file" end html = File.open(html_file) { |f| f.read } parser = Egg::Parser.new(html) puts parser.to_ofx
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/lib/egg' html_file = ARGV.shift unless html_file and File.exists?(html_file) raise "Usage: egg2ofx path/to/egg-html-file" end html = File.open(html_file) { |f| f.read } parser = Egg::Parser.new(html) puts parser.to_ofx
Ruby
require 'rubygems' require 'hpricot' statement_html_file = File.dirname(__FILE__) + '/INGDirect.html' html = File.open(statement_html_file) { |f| f.read } doc = Hpricot(html) # Read account details (transaction_period, customer_name, account_number, account_name) account_details = {} (doc/"tr.grey_table_top td b").ea...
Ruby
module Ofx require 'builder' class Statement def initialize(statement) @statement = statement @xml = nil end def to_xml @xml ||= ( buffer = '' builder = Builder::XmlMarkup.new(:target => buffer) builder.OFX do builder.BANKMSGSRSV1 do builde...
Ruby
Dir[File.dirname(__FILE__) + '/ing/*.rb'].each { |f| require f }
Ruby
require 'rubygems' require 'hpricot' Dir[File.dirname(__FILE__) + '/egg/*.rb'].each { |f| require f } require File.join(File.dirname(__FILE__), 'ofx')
Ruby
module Ofx require 'builder' class Statement def initialize(statement) @statement = statement @xml = nil end def to_xml @xml ||= ( buffer = '' builder = Builder::XmlMarkup.new(:target => buffer, :indent => 2) builder.instruct! builder.instruct!(:OFX, :OF...
Ruby
module Ing class Description attr_reader :payee, :note, :territory def initialize(description) @payee = description end end end
Ruby
module Ing class Account def initialize(currency, number, sort_code, type = 'SAVINGS') @currency, @number, @sort_code, @type = currency, number, sort_code, type end attr_reader :currency, :number, :sort_code, :type end end
Ruby
require 'digest/md5' require File.expand_path(File.dirname(__FILE__) + '/description') module Ing class Transaction def initialize(date, description, money) @date = Date.build(date) @raw_description = description @description = Description.new(description) @amount = Money.new(money).to_f ...
Ruby
module Ing class Statement def initialize(statement_date, closing_balance, account) from_date, to_date = statement_date.split(' to ') @from_date = Date.build(from_date) @to_date = Date.build(to_date) @closing_balance = Money.new(closing_balance).to_f @account = account @transac...
Ruby
module Ing class Money def initialize(money) @money = money.to_f end def to_f @money end end end
Ruby
require 'date' module Ing class Date def self.build(date) return nil if date == '' ::Date.parse(date).strftime('%Y%m%d') end end end
Ruby
module Egg class StatementParser def initialize(html) @html = html end def to_ofx doc = Hpricot(@html) card_number = (doc/"span#lblCardNumber").inner_html statement_date = (doc/'#ctl00_content_eggCardStatements_lstPreviousStatements'/'option[@selected=selected]').first.attributes[...
Ruby
module Egg class Description attr_reader :payee, :note, :territory def initialize(description) if m = description.match(/(.{23}) (.{13}) (.{2})?/) # territory (last two chars) is not in recent transactions @payee = m[1].strip.squeeze(' ') @note = m[2].strip @territory = m[3].stri...
Ruby
module Egg class Account def initialize(currency, number) @currency, @number = currency, number end attr_reader :currency, :number end end
Ruby
module Egg class Parser def initialize(html) @parser = if html =~ /\<h1.*?>your egg card statement/i StatementParser.new(html) else RecentTransactionsParser.new(html) end end def to_ofx @parser.to_ofx end end end
Ruby
require 'digest/md5' require File.expand_path(File.dirname(__FILE__) + '/description') module Egg class Transaction def initialize(date, description, money) @date = Date.build(date) @raw_description = description @description = Description.new(description) @amount = Money.new(money).to_f ...
Ruby
module Egg class RecentTransactionsParser def initialize(html) @html = html end def to_ofx doc = Hpricot(@html) card_number = (doc/"span#lblCardNumber").inner_html first_transaction_date = (doc/'#tblTransactionsTable'/'tbody'/'tr'/'td.date').first.inner_text last_transa...
Ruby
module Egg class Statement def initialize(statement_date, closing_balance, account) from_date, to_date = statement_date.split(' to ') @from_date = Date.build(from_date) @to_date = Date.build(to_date) @closing_balance = Money.new(closing_balance).to_f @account = account @transac...
Ruby
module Egg class Money def initialize(money) money = money.sub(/£/, '').gsub(/,/, '') md = money.match(/(\d+\.\d+) ([A-Z]+)/) @money = md ? Float(md[1]) : 0 @money = -@money if md && md[2] == 'DR' end def to_f @money end end end
Ruby
require 'date' module Egg class Date def self.build(date) return nil if date == '' ::Date.parse(date).strftime('%Y%m%d') end end end
Ruby
credentials = {} print "Enter your Sort Code: " credentials['sort_code'] = gets.chomp print "Enter your Account Number: " credentials['account_number'] = gets.chomp print "Enter your Internet Banking Id: " credentials['internet_banking_id'] = gets.chomp print "Enter your Date of Birth (ddmmyy): " credentials['date_...
Ruby
require 'yaml' # Load the credentials from a file or STDIN (to allow us to read in encrypted output from a gpg command) # e.g. gpg --decrypt encrypted_credentials.yml | ruby hsbc.rb if credentials_filename = ARGV.shift Credentials = YAML.load(File.read(credentials_filename)) else yaml_credentials = '' while data...
Ruby
require 'egg-credentials' def execute_curl(cmd) `#{cmd}` end COOKIE_LOCATION = "/tmp/egg.cookie" STATEMENT_DATE = '18 January 2007' RECENT_TRANSACTIONS_FILE = '/Users/chrisroos/Desktop/egg-recent-transactions.html' STATEMENT_FILE = '/Users/chrisroos/Desktop/egg-statement.html' # Logging in requires a cookie that ...
Ruby
require 'rubygems' require 'hpricot' html = File.open('/Users/chrisroos/Desktop/ingdirect-b1.html') { |f| f.read } # The request for our PIN digits appears within the following text # <b>Using the Key Pad, please enter the 3rd, 5th and 2nd digits from your PIN</b> pin_a, pin_b, pin_c = html.scan(/Using the Key Pad, p...
Ruby
require 'ing-direct-credentials' COOKIE_JAR = '/tmp/ing-direct.cookie' TRANSACTIONS_FILENAME = '/Users/chrisroos/Desktop/ing-transactions.html' # POST our customer number and surname curl_cmd = %[curl -s -X"POST" -c"#{COOKIE_JAR}" -d"command=enterCustomerNumber" -d"locale=en_GB" -d"device=web" -d"ACN=#{CUSTOMER_NUMBE...
Ruby
require "rubygems" require "rake/gempackagetask" require "rake/rdoctask" task :default => :test require "rake/testtask" Rake::TestTask.new do |t| t.libs << "test" t.test_files = FileList["test/**/*_test.rb"] t.verbose = true end # This builds the actual gem. For details of what all these options # mean, and ot...
Ruby
# -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = %q{egg2ofx} s.version = "0.1.2" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Chris Roos"] s.date = %q{2009-11-14} s.default_executable = %q{egg2ofx} s.email = %q{chri...
Ruby
$: << File.dirname(__FILE__) require 'hpricot' require 'egg/date' require 'egg/statement' require 'egg/account' require 'egg/transaction' require 'egg/money' require 'egg/description' require 'egg/parser' require 'ofx'
Ruby
require 'builder' module Ofx class Statement def initialize(statement) @statement = statement @xml = nil end def to_xml @xml ||= ( buffer = '' builder = Builder::XmlMarkup.new(:target => buffer, :indent => 2) builder.instruct! builder << "<?OFX OFXHEADER=...
Ruby
module Egg class Description attr_reader :payee, :note, :territory def initialize(description) if m = description.match(/(.{23}) (.{13}) (.{2})?/) # territory (last two chars) is not in recent transactions @payee = m[1].strip.squeeze(' ') @note = m[2].strip @territory = m[3].stri...
Ruby
module Egg class Account def initialize(currency, number) @currency, @number = currency, number end attr_reader :currency, :number end end
Ruby
$: << File.dirname(__FILE__) require 'parsers/document_parser' require 'parsers/transaction_parser' require 'parsers/statement_document_parser' require 'parsers/statement_transaction_parser' require 'parsers/recent_transactions_document_parser' require 'parsers/recent_transactions_transaction_parser' module Egg ...
Ruby
require 'digest/md5' module Egg class Transaction def initialize(date, description, money) @date = Date.build(date) @raw_description = description @description = Description.new(description) @amount = Money.new(money).to_f @ofx_id = nil end attr_reader :date, :amount def...
Ruby
module Egg class Statement def initialize(statement_date, closing_balance, account) from_date, to_date = statement_date.split(' to ') @from_date = Date.build(from_date) @to_date = Date.build(to_date) @closing_balance = Money.new(closing_balance).to_f @account = account @transac...
Ruby
module Egg class Money def initialize(money) money = money.sub(/£/, '').gsub(/,/, '') md = money.match(/(\d+\.\d+) ([A-Z]+)/) @money = md ? Float(md[1]) : 0 @money = -@money if md && md[2] == 'DR' end def to_f @money end end end
Ruby
require 'date' module Egg class Date def self.build(date) return nil if date == '' ::Date.parse(date).strftime('%Y%m%d') end end end
Ruby
module Egg class RecentTransactionsDocumentParser < DocumentParser private def transaction_parser_class RecentTransactionsTransactionParser end def statement_date first_transaction_date = (doc/'#tblTransactionsTable'/'tbody'/'tr'/'td.date').first.inner_text last_transaction...
Ruby
module Egg class StatementTransactionParser < TransactionParser def description description = super if row.next_sibling && (row.next_sibling/"td.date").inner_text == '' && (row.next_sibling/"td.description").inner_text != '' description += ' / ' + (row.next_sibling/"td.description").inne...
Ruby
module Egg class TransactionParser attr_reader :row def initialize(row) @row = row end def skip? false end def money (row/"td.money").inner_text.sub(/^\?/, '').sub(/^£/, '') end def date (row/"td.date").inner_text end def descripti...
Ruby
module Egg class DocumentParser attr_reader :doc def initialize(html) @doc = Hpricot(html) end def to_ofx account = Egg::Account.new('GBP', card_number) statement = Egg::Statement.new(statement_date, closing_balance, account) each_transaction do |tran...
Ruby
module Egg class RecentTransactionsTransactionParser < TransactionParser def money money = super money =~ /^\-/ ? money + ' CR' : money + ' DR' end end end
Ruby
module Egg class StatementDocumentParser < DocumentParser private def transaction_parser_class StatementTransactionParser end def statement_date (doc/'#ctl00_content_eggCardStatements_lstPreviousStatements'/'option[@selected=selected]').first.attributes['value'] end ...
Ruby
require 'test/unit' require 'rubygems' require 'mocha' require File.join(File.dirname(__FILE__), '..', 'lib', 'egg') FIXTURES = File.join(File.dirname(__FILE__), 'fixtures') unless defined?(FIXTURES)
Ruby
require 'lloydstsb_credentials' require 'rubygems' require 'hpricot' def execute_curl(cmd) `#{cmd}` end COOKIE_LOCATION = '/Users/chrisroos/lloydstsb_cookie' DOWNLOADED_STATEMENT_LOCATION = '/Users/chrisroos/Desktop/lloyds.qif' # Store some cookies for later curl_cmd = %[curl -s -c"#{COOKIE_LOCATION}" "https://on...
Ruby
USERID = 'YOUR_USERID' PASSWORD = 'YOUR_PASSWORD' MEMORABLE = 'YOUR_MEMORABLE_INFO' SORT_CODE_AND_ACCOUNT_NUMBER = 'YOUR_SORT_CODE_AND_ACCOUNT_NUMBER_CONCATENATED'
Ruby
require 'hpricot' require 'date' class Parser def initialize(html) @doc = Hpricot(html) end def each (@doc/'table.summarytable'/'tbody'/'tr').each do |table_row| date, description, deposit, withdrawal = (table_row/'td').collect { |e| e.inner_text } # Ignore the last line of the transaction ta...
Ruby
SecurityDetails = { 'sortCode' => 'your-sort-code', 'accountNumber' => 'your-account-number', 'securityCode' => SecurityCode.new('your-security-code'), 'lastSchool' => 'your-last-school', 'firstSchool' => 'your-first-school', 'memorableName' => 'your-memorable-name', 'memorabledate' => ['your-memorable-da...
Ruby
require 'hpricot' class SecurityCode < String [:first, :second, :third, :fourth].each_with_index do |method_name, index| define_method(method_name) { self[index].chr } end end require File.join(File.dirname(__FILE__), 'security_details') def cookie_path File.join(File.dirname(__FILE__), 'cookies', 'smile.c...
Ruby
secret_message = " ************************************************************************************** Woohoo, you found this very poorly hidden, mega-secret, message. I say mega-secret, but to be honest, this is just a thinly veiled job advert for reevoo.com. Sorry, but I was bored on the train... Anyhoo, if you...
Ruby
require 'test/unit' eval DATA.read.unpack('m').first class Candidate def secret_message @secret_message.unpack('m').first end end class CandidateTest < Test::Unit::TestCase def setup @candidate = Candidate.new end def test_should_love_learning assert @candidate.loves_learning? end def test_s...
Ruby
class Person < ActiveRecord::Base end
Ruby
# To replicate, you need to create a mysql database called rails_timestamps_test (or change the details in assets/database.yml) # CREATE DATABASE rails_timestamps_test; # The database must contain a table called people which can be created with this sql # CREATE TABLE people (id INTEGER AUTO_INCREMENT, created_on DATE,...
Ruby
set :application, "mail-to-delicious" set :repository, "http://chrisroos.googlecode.com/svn/trunk/scratch/mail-to-delicious" # If you aren't deploying to /u/apps/#{application} on the target # servers (which is the default), you can specify the actual location # via the :deploy_to variable: set :deploy_to, "/home/chr...
Ruby
load 'deploy' if respond_to?(:namespace) # cap2 differentiator Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } load 'config/deploy'
Ruby
require 'rubygems' require 'net/https' require 'uri' require 'cgi' require 'yaml' require 'tmail' module Delicious Credentials = YAML.load(File.read(File.join(File.dirname(__FILE__), '..', 'config', 'delicious.yml'))) class BookmarkParser attr_reader :title, :url, :notes, :tags def initialize(email) ...
Ruby
require File.join(File.dirname(__FILE__), 'lib', 'delicious') run Proc.new { |env| bookmark = Delicious::Bookmark.from_email(env['rack.input'].read) if bookmark.save [ 200, {"Content-Type" => "text/plain"}, 'success' ] else [ 400, {"Content-Type" => "text/plain"}, 'failure' ] end }
Ruby
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person',...
Ruby
# These settings change the behavior of Rails 2 apps and will be defaults # for Rails 3. You can remove this initializer when Rails 3 is released. if defined?(ActiveRecord) # Include Active Record class name as root for JSON serialized output. ActiveRecord::Base.include_root_in_json = true # Store the full clas...
Ruby
# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone
Ruby
set :application, "deliciolytics.co.uk" set :repository, "http://chrisroos.googlecode.com/svn/trunk/scratch/#{application}" # If you aren't deploying to /u/apps/#{application} on the target # servers (which is the default), you can specify the actual location # via the :deploy_to variable: # If you aren't using Subv...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Enable threaded mode # config.threadsafe! # Use a different logger for distributed setups # config....
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between...
Ruby
# Be sure to restart your server when you modify this file # Uncomment below to force Rails into production mode when # you don't control web/app server and can't set it the proper way # ENV['RAILS_ENV'] ||= 'production' # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.2...
Ruby
# Don't change this file! # Configure your app in config/environment.rb and config/environments/*.rb RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) module Rails class << self def boot! unless booted? preinitialize pick_boot.run end end def booted? ...
Ruby
ActionController::Routing::Routes.draw do |map| map.root :controller => 'domains' map.about '/about', :controller => 'static_pages', :action => 'about' map.resources :domains, :only => [:index, :show, :new, :create] do |domain| domain.resources :urls, :only => [:index] do |url| url.resources :boo...
Ruby
load 'deploy' if respond_to?(:namespace) # cap2 differentiator Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } load 'config/deploy'
Ruby
xml.instruct! xml.feed(:xmlns => 'http://www.w3.org/2005/Atom') do xml.title "Bookmarks for #{@domain.domain}" xml.link :href => domain_bookmarks_url(@domain) xml.link :href => domain_bookmarks_url(@domain, :format => 'atom'), :rel => 'self' if @domain.bookmarks.any? xml.updated atom_datetime(@domain.most_r...
Ruby
module UrlHelper def url(url) h(url.url) end def url_path(url) URI.parse(url.url).path end end
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def link_to_source_url(url) link_to h(url.url), h(url.url) end def link_to_delicious_url_history(url) link_to h(url.url_hash), h("http://delicious.com/url/#{url.url_hash}") end def l...
Ruby
module AtomHelper def atom_datetime(datetime) datetime.strftime("%Y-%m-%dT%H:%M:%SZ") end def tag_uri(object) "tag:deliciolytics.co.uk,2009:#{object.class}/#{object.id}" end end
Ruby
module DomainHelper def domain_host(domain) URI.parse(domain.domain).host end def link_to_domain_host(domain) link_to domain_host(domain), domain_path(domain) end end
Ruby
require 'md5' class Domain < ActiveRecord::Base has_many :urls has_many :bookmarks, :through => :urls, :order => 'bookmarked_at DESC' has_many :domain_events, :order => 'started_at DESC' validates_presence_of :domain validates_uniqueness_of :domain before_create :set_default_state def normali...
Ruby
class Bookmark < ActiveRecord::Base belongs_to :url validates_presence_of :url validates_uniqueness_of :username, :scope => :url_id serialize :tags def self.new_from_delicious_attributes(delicious_attributes) new(Delicious::BookmarkAttributeConvertor.convert(delicious_attributes)) end end
Ruby
class DomainEvent < ActiveRecord::Base belongs_to :domain validates_presence_of :domain, :description, :started_at validates_presence_of :finished_at, :on => :update before_validation_on_create :start! def finish! self.finished_at = Time.now self.save end private def start! self.s...
Ruby
require 'md5' class Url < ActiveRecord::Base belongs_to :domain has_many :bookmarks, :order => 'bookmarked_at DESC' validates_presence_of :domain, :url, :url_hash validates_uniqueness_of :url serialize :top_tags before_validation_on_create :hash_url def hash_url self.url_hash = MD5.md5(url).to_...
Ruby
class DomainBookmarksController < ApplicationController def index @domain = Domain.find_by_domain_hash!(params[:domain_id]) end end
Ruby
class BookmarksController < ApplicationController def index @domain = Domain.find_by_domain_hash!(params[:domain_id]) @uri = @domain.urls.find_by_url_hash!(params[:url_id]) @bookmarks = @uri.bookmarks end end
Ruby
class UrlsController < ApplicationController def index @domain = Domain.find_by_domain_hash!(params[:domain_id]) @urls = @domain.urls.all(:order => 'total_posts DESC') end end
Ruby
class DomainEventsController < ApplicationController def index @domain = Domain.find_by_domain_hash(params[:domain_id]) @domain_events = @domain.domain_events end end
Ruby
class StaticPagesController < ApplicationController def about end end
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base helper :all # include all helpers, all the time # See ActionController::RequestForgeryProtection for details...
Ruby
class DomainsController < ApplicationController def index @domains = Domain.all end def show @domain = Domain.find_by_domain_hash!(params[:id]) end def new @domain = Domain.new end def create @domain = Domain.new(params[:domain]) if @domain.save redirect_to domains_pa...
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/dbconsole'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/request'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/request'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/dbconsole'
Ruby