Skip to content

Instantly share code, notes, and snippets.

View bruce's full-sized avatar
🤝
Here to help!

Bruce Williams bruce

🤝
Here to help!
View GitHub Profile
# http://en.wikipedia.org/wiki/Simple_linear_regression
# Exchange.Calc.Regression.run([{1,1},{2,2},{3,3}])
defrecord Exchange.Calc.Regression.Result, products_avg: nil, x_avg: nil, y_avg: nil, x_sqr_avg: nil do
def complete?(result) do
result.products_avg && result.x_avg && result.y_avg && result.x_sqr_avg
end
end
@bruce
bruce / app-controllers-images_controller.rb
Created January 4, 2012 21:00 — forked from jathayde/app-controllers-images_controller.rb
Trying to figure out polymorphic association with image to other items
def new
@image = Image.new
respond_with @image
end
@bruce
bruce / gist:257326
Created December 15, 2009 21:29 — forked from mperham/gist:257316
def exists?(attribs)
CustomImage.find_by_account_id_and_hash(attribs['account_id'], attribs['id'])
end
# Memoize using <tt>defined?</tt>
def some_method(attribs)
return @some_method if defined?(@some_method)
@some_method = exists?(attribs)
end