Skip to content

Instantly share code, notes, and snippets.

View plukevdh's full-sized avatar
🔥

Luke van der Hoeven plukevdh

🔥
View GitHub Profile
@plukevdh
plukevdh / billing_flow.rb
Last active August 29, 2015 14:22
a design challenge
class Order
has_one :receipt
def paid(receipt)
self.receipt = receipt
end
end
class Receipt
belongs_to :order
@plukevdh
plukevdh / roda-plugin.rb
Created April 28, 2015 15:21
scratch example for Roda plugin
class Roda
module RodaPlugins
module Storage
def self.configure(app, options: {})
app.opts[:redis] = Redis.new url: (options[:redis_url] || ENV['REDIS_URL'])
end
# ...
end
@plukevdh
plukevdh / methods-ips.rb
Last active August 29, 2015 14:16
benchmark ruby method delegation
require 'benchmark/ips'
class Bass
def initialize(hash)
@hash = hash
end
end
class Testing < Bass
def []=(key, value)
@plukevdh
plukevdh / fizz_buzz.ex
Last active August 29, 2015 14:16
Fizz Buzz
defmodule Streem do
def fb(n) when rem(n,15) == 0, do: "FizzBuzz"
def fb(n) when rem(n,3) == 0, do: "Fizz"
def fb(n) when rem(n,5) == 0, do: "Buzz"
def fb(n), do: n
end
@plukevdh
plukevdh / demo.rb
Last active August 29, 2015 14:15
Dump of Sinatra definition
require 'sinatra/base'
require 'rbtrace'
proc {
Dir.chdir("/tmp") do
Dir.pwd
Process.pid
sleep 30
class Demo < Sinatra::Base
@plukevdh
plukevdh / derp.rb
Last active August 29, 2015 14:15
api sketch for a project
GithubClient.config do |c|
c.endpoint "https://api.github.com/"
c.default_handler JSONHandler # handles responses as JSON
end
class JSONHandler
def initialize(data)
@data = data
end
@plukevdh
plukevdh / finders.rb
Last active August 29, 2015 14:13
method missing for finders
# This...
def by_id(id)
filter_by(:id, id)
end
def by_email(email)
filter_by(:email, email)
end
@plukevdh
plukevdh / list.ex
Last active August 29, 2015 14:11
lists, how do they work
iex(8)> list = [:width, 1024, :height, 768, :content_type, "image/png", :postProcess, true]
[:width, 1024, :height, 768, :content_type, "image/png", :postProcess, true]
iex(9)> is_list list
true
iex(10)> :erlang.list_to_binary list
** (ArgumentError) argument error
:erlang.list_to_binary([:width, 1024, :height, 768, :content_type, "image/png", :postProcess, true])
@plukevdh
plukevdh / Rakefile
Created November 2, 2014 18:06
migrations a la sequel
namespace :db do
desc "Run migrations"
task :migrate, [:version] do |t, args|
require "sequel"
Sequel.extension :migration
db = Sequel.connect(ENV.fetch("DATABASE_URL"))
if args[:version]
puts "Migrating to version #{args[:version]}"
@plukevdh
plukevdh / result.txt
Last active August 29, 2015 14:07
Why do mocked objects not assume identity of the object type they're mocking?
$> rspec test_case.rb
F.
Failures:
1) a failing case expects success
Failure/Error: expect(production_code(response)).to eq 'success'
expected: "success"
got: "failure"