Skip to content

Instantly share code, notes, and snippets.

View andypike's full-sized avatar

Andy Pike andypike

View GitHub Profile
# Real implimentations:
# =====================
#
# This isn't really testing anything but the point is, rather than
# reading the module to use from config and fixing the module for
# all tests here we inject the module in the function call and supply
# a default for normal operation. This is akin to dependency injection
# in OO. Not sure if this is a good idea but seems more flexible as
# different tests can pass in a different fake (if needed).
@andypike
andypike / gist:5e11b236f4682eec1411b2c863d69986
Last active September 5, 2016 09:17
Intro to Star Trek
Originals
---------
The Trouble With Tribbles
Space Seed
Originals Movies
----------------
Wrath of Khan
Search for Spock
Voyage Home
@andypike
andypike / index.html.erb
Created February 13, 2016 19:43
Notes and experiments for the view objects in Rectify
<!--
In the template just use the @view object and call it's methods to clean up
the presentation logic. Maybe think about adding a helper method called `view`
that just returns `@view` so we can remove the noise of the `@`.
-->
<%= @view.users.each do |user| %>
<%= @view.user_link(user) %>
<% end %>
@andypike
andypike / fizzbuzz.exs
Created January 4, 2016 10:30
FizzBuzz in Elixir
defmodule FizzBuzz do
def convert_num(0, 0, _), do: "FizzBuzz"
def convert_num(0, _, _), do: "Fizz"
def convert_num(_, 0, _), do: "Buzz"
def convert_num(_, _, n), do: n
def fizz_buzz(n) do
convert_num rem(n, 3), rem(n, 5), n
end
@andypike
andypike / gist:82eb791e948171e6ad4e
Last active October 21, 2022 12:25
Self registering classes that works within a Rails app without turning on eager_loading loading in development
# ./config/environments/development.rb
config.eager_load = false
# ./lib/registry.rb
module Registry
def self.included(base)
base.send(:extend, ClassMethods)
end
module ClassMethods
@andypike
andypike / gist:6fd735862302b09f5259
Last active October 21, 2022 12:25
Self registering ruby classes
class Toolbox
@tools = {}
def self.register(tool)
@tools[tool.material] = tool
end
def self.tool_for(material)
@tools.fetch(material) { BareHands }
end
@andypike
andypike / gist:3cbe45d5c5c42623a4a9
Created July 23, 2014 11:20
Brighton Ruby Slides
@samphippen: https://speakerdeck.com/samphippen/types-and-refactoring
@andypike: https://speakerdeck.com/andypike/take-the-pain-out-of-your-tdd
@benlovell: https://speakerdeck.com/benlovell/fast-testable-and-sane-json-apis-with-rails-api-et-al
@tenderlove: https://speakerdeck.com/tenderlove/brighton-ruby-conf-2014
@andypike
andypike / classes.rb
Last active December 15, 2015 22:09
My first experiment with a simple IoC container in Ruby. To run this sample do this: $ ruby ioc.rb
# defining various components of the system
# notice the classes know nothing about the container
# as they require the dependencies to operate, they should be passed into the constructor
class Nails
def to_s
"nails"
end
end
class Glue
@andypike
andypike / gist:1762680
Created February 7, 2012 22:52
simple_form 2.0.0.rc improved api for twitter bootstrap
-# Instead of this simple_form 2.0.0.rc Twitter Bootstrap complication:
= form.input :savings, :label => "Your Savings:", :input_html => {:class => 'span2'}, :wrapper => :prepend do
%span.add-on= £
= form.input_field :savings
%p.help-block Enter the amount of money you have in your savings account
-# I'd like to do something like this (simpler)