Skip to content

Instantly share code, notes, and snippets.

View mcelaney's full-sized avatar

Brian E. McElaney mcelaney

View GitHub Profile
@mcelaney
mcelaney / when_brevity_is_not_a_thing.rb
Last active August 31, 2016 13:30
When brevity doesn't matter...
# Run if necessary:
# RubyVM::InstructionSequence.compile_option = {
# tailcall_optimization: true,
# trace_instruction: false
# }
class FizzBuzz
def self.find_answers_for(max)
self.new(max).find_answers_for([], 1)
end
@mcelaney
mcelaney / slow-but_beautiful_in_a_way.rb
Created August 31, 2016 11:42
Slow - but beautiful in a way
class FizzBuzz
def self.find_answers_for(max)
self.new.find_answers_for(max)
end
def find_answers_for(max)
1.upto(max).map do |current|
[find_result_hash(current), current]
.find { |result| result != '' }
end
@mcelaney
mcelaney / normalish.rb
Last active August 31, 2016 13:32
Normalish FizzBuzz
class FizzBuzz
def self.find_answers_for(max)
1.upto(max).each do |n|
result = ''
result << 'Fizz' if n % 3 == 0
result << 'Buzz' if n % 5 == 0
result = n if result.empty?
result
end
end
@mcelaney
mcelaney / ugly_but_fast.rb
Created August 31, 2016 11:34
Ugly but fast
class FizzBuzz
def self.find_answers_for(max)
self.new.find_answers_for(max)
end
def initialize
@result = [
Proc.new do |x| x; end,
Proc.new do |x| x; end,
Proc.new do |x| "Fizz"; end,
defmodule ProductVehicle do
def vehicles_that_fit_product(query \\ ProductVehicle, product_id) do
query
|> join(:inner,
[products_vehicles],
product in assoc(products_vehicles, :product))
|> join(:inner,
[products_vehicles],
vehicle in assoc(products_vehicles, :vehicle))
|> join(:inner,
defmodule ProductVehicle do
def vehicles_that_fit_product(query \\ ProductVehicle, product_id) do
query
|> join(:inner,
[products_vehicles],
product in assoc(products_vehicles, :product))
|> join(:inner,
[products_vehicles],
vehicle in assoc(products_vehicles, :vehicle))
|> join(:inner,
defmodule ProductVehicle do
def vehicles_that_fit_product(query \\ ProductVehicle, product_id) do
query
|> join(:inner,
[products_vehicles],
product in assoc(products_vehicles, :product))
|> join(:inner,
[products_vehicles, _product],
vehicle in assoc(products_vehicles, :vehicle))
end
defmodule ProductVehicle do
def vehicles_that_fit_product(query \\ ProductVehicle, product_id) do
query
|> join(:inner,
[products_vehicles],
product in assoc(products_vehicles, :product))
|> join(:inner,
[products_vehicles],
vehicle in assoc(products_vehicles, :vehicle))
end
defmodule VehicleMake do
schema "vehicle_makes" do
field :name, :string
has_many :vehicle_models, VehicleModel
has_many :vehicles, through: [:vehicle_models, :vehicles]
end
end
defmodule VehicleModel do
April 11, 2016
10:15 - Salon A David Ferrucci: Salon A - AI: A Return to Meaning
11:30 - Salon D James Roper: Rethinking REST in a Microservices World
13:30 - Salon C Yehuda Katz: Stability Without Stagnation: Lessons Learned Shipping Ember
14:45 - Salon A Evan Chan: NoLambda: A new architecture combining streaming, ad hoc, machine learning, and batch analytics
16:00 - Salon D Jean Yang: Securing Software by Construction
April 12, 2016
08:45 - Salon D Bryan Helmkamp: Code Quality in Practice
10:15 - Salon A Raffi Krikorian: How Your Organization is Killing your Software