Skip to content

Instantly share code, notes, and snippets.

View pricees's full-sized avatar

Ted Price pricees

View GitHub Profile
@pricees
pricees / gist:6913501
Created October 10, 2013 05:32
scraper morningstar 2.0
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require "selenium-webdriver"
Capybara.run_server = false
Capybara.app_host = 'http://financials.morningstar.com'
mimes = [
"text/plain",
@pricees
pricees / gist:7088969
Created October 21, 2013 18:54
Yahoo! finance api with Ruby driver
# Driver program for this hidden yahoo financie api from here
# http://greenido.wordpress.com/2009/12/22/yahoo-finance-hidden-api/
#
#
require "csv"
require "net/http"
require "uri"
def uri(symbols, format)
res= "http://download.finance.yahoo.com/d/quotes.csv?"
@pricees
pricees / gist:7819378
Last active December 30, 2015 10:59
Exploratory hacking ... looking for a way to check my specs before I wreck my 'jects.
require "rspec"
class Person
# Run the tests.
# For funzies, implement #salutation, #goodbye
end
module IntegrationCheck
@pricees
pricees / gist:7881640
Created December 9, 2013 21:51
Hash dot notation for the JS Fanboys
# Ruby hash w/ Javascript dot notation
#
#
#
# The Code
#
class Hash
@pricees
pricees / gist:7894329
Last active December 30, 2015 22:29
StubSync -- What if you stub a method that doesn't exist? And you forget about it? What if you delete a method that you stubbed? What if you misspell a stub or something? Stubs can be dangerous. This module can help.
# spec/stub_sync.rb
# StubSync keeps track of the instance and class methods that are stubbed by the
# class under test.
#
# Say Wha!?!?!?!
#
# Why would you stub the class under test, thats just crazy!
# Yes it is! Crazy like a fox.
#
@pricees
pricees / Splitting a Ruby on a Rail
Last active August 1, 2023 18:21
How I split a fat rails model
Background
Raise.com is built on top of Spree. We have in-lined spree, and have decorators
on the models to beat the band. We want to move away from Spree altogeher.
This involves taking the models from Spree, moving them to the Raise
base app. This merge has the potential to create lots of big classes. Big classes
are difficult to maintain. One of the first steps towards returning classes/models to
being "right sized." is splitting the business logic and the persistence.
What I did
@pricees
pricees / splitting_a_ruby
Created December 31, 2013 16:31
Possible approaches to splitting Business and Persistence
# Splitting Rails models let me count the ways
#
# Assume that I start with the base class and tests
#
class Transactions < ActiveRecord::Base
# contains :amount
end
@pricees
pricees / gist:8524744
Last active January 3, 2016 21:59
The perils of local variable binding!
# Example 1
# This is cool!
if x = true
puts x
end
# => true
# Example 2
# Statement modifiers with local variable assignment can explode!
@pricees
pricees / gist:8963659
Created February 12, 2014 20:15
Extending an Array/ActiveRelation vs Subclassing Array
names = %w[SK Steve Pedro Anthony Milo Xiping]
Person = Struct.new :name
module Helloable
def hello_all_the_names
each { |person| puts "Helloable | Hello #{person.name}" }
end
end
# An interesting way to add functionality to an array is to extend it
@pricees
pricees / Ruby Basic
Last active August 29, 2015 13:56
My Ruby Litmus Test.rb
# Integer vs Float div by zero gotchas
#
#
1 / 0 = [answer]
1.0 / 0 = [answer]
1 / 0.0 = [answer]
0 / 0.0 = [answer]
# String concatenation vs interpolation
x = 5