Skip to content

Instantly share code, notes, and snippets.

@jacknoble
jacknoble / has_many.rb
Created December 9, 2013 18:53
My version of AR's has_many
def has_many(name, params = {})
assoc = HasManyAssocParams.new(name, params, self.class.to_s)
@assoc_params ||= {}
@assoc_params[name.to_sym] = assoc
primary_key = assoc_params[name][:primary_key].to_sym
define_method(name) do
owned = DBConnection.execute(<<-SQL, self.send(primary_key))
SELECT
*
FROM
@jacknoble
jacknoble / gist:52fef060248f4a80c1aa
Created September 17, 2014 03:13
memo make change
def make_change(amount)
mc(amount, 5)
end
def mc(amount, kinds_of_coins)
return 1 if amount == 0
return 0 if amount < 0 || kinds_of_coins == 0
other_coins = mc(amount, kinds_of_coins - 1)
remove_largest_coin = mc(amount - next_denom(kinds_of_coins), kinds_of_coins)
other_coins + remove_largest_coin
def fibs(0), do: []
def fibs(1), do: [1]
def fibs(2), do: [1, 0]
def fibs(num) do
lower_fibs = fibs(num - 1)
[sum(take(lower_fibs, 2)) | lower_fibs ]
end
require "spec_helper"
require "signup"
describe Signup do
describe "#save" do
it "creates an account with one user" do
signup = Signup.new(email: "user@example.com", account_name: "Example")
allow(Account).to receive(:create!).and_return(Account.new)
allow(User).to receive(:create!).and_return(User.new)
Good Day...
I am United Nations Diplomat Dr. Johnson Harry from the United Nations Diplomatic Courier Commission. I just want to notify you that I am currently at John F Kennedy International Airport With your consignment boxes which was assigned from the United Kingdom to dispose the 2 boxes tagged family values which were recovered by men of the Bureau of National Investigation of the Ethiopia Government.Subsequent to a High Level Forum ("Towards "Towards Sustainable Business Relations for All in Africa") meeting held on the 14th of November, 2015 at the African Union Summit held in Ethiopia, it was jointly agreed that a committee, be put in place to ensure the release of outstanding debts and recovered inheritance funds. These is as a result of several petitions from Individuals,Co-Operate institution and International Countries of the failure to receive their various goods.
Presently your two consignment boxes are among those to be disposed and delivered to you, and that is the reason why i'm mailing
class FooBarService
def self.call(arg)
new(arg).call
end
def initialize(thing)
@thing = thing
end
def call
class FooBar
def self.call(arg)
new(arg).call
end
def initialize(thing)
@thing = thing
end
def call
FooBar = -> (thing) do
# ...
end
TRY_REGEX = /\.try!?\((?<args>.*?)\)/
Dir.glob("app/**/*{.rb,.erb,.jbuilder}").each do |fname|
text = File.open(fname, 'rb', &:read)
new_text = text.gsub(TRY_REGEX) do
(method_name, *args) = Regexp.last_match[:args].tr(' ', '').split(',')
if args.any?
"&#{method_name.tr(':', '.')}(#{args.join(', ')})"
else
"&#{method_name.tr(':', '.')}"
end

Keybase proof

I hereby claim:

  • I am jacknoble on github.
  • I am jnobledox (https://keybase.io/jnobledox) on keybase.
  • I have a public key ASAYwC2QgVaOfYrFY1vNR92aRfIIQr6bxZV5YVSF8zVCIwo

To claim this, I am signing this object: