Skip to content

Instantly share code, notes, and snippets.

View darrencauthon's full-sized avatar

Darren Cauthon darrencauthon

View GitHub Profile
@darrencauthon
darrencauthon / 1.rb
Last active August 29, 2015 13:56
Implicit returns. (1) and (2) and (3) do the same thing. But with implicit returns, the "cruft" around (1) melts away to produce flat (2). And with the refactoring of (2), do you think (3) is better?
module Seam
class WaitWorker < ::Seam::Worker
def initialize
handles :wait
end
def process
time_of_last_execution = if effort.history.count == 0
@darrencauthon
darrencauthon / spec.rb
Last active August 29, 2015 13:57
Testing example
describe "visiting the home page" do
let(:controller) { HomeController.new }
describe "when you are logged in" do
let(:user) { User.new(name: Object.new) }
before { controller.stubs(:current_user).returns user }
it "should show your name" do
@darrencauthon
darrencauthon / public_setters.rb
Last active August 29, 2015 13:59 — forked from djbender/public_setters.rb
public setters
def public_setters
public_methods.select { |m| m =~ /=$/ }
.reject { |m| %i(== === !=).include? m }
end
@darrencauthon
darrencauthon / 1_before.rb
Last active August 29, 2015 13:59
Refactoring, a class for Hello World Open
class Message
def initialize value = nil
@data = {}
if value.is_a? Hash
value.each do |k, v|
@data[k.to_s.underscore] = v
end
else
self.type = value if value
@darrencauthon
darrencauthon / elephant_controller_spec.rb
Created April 30, 2014 20:47
Should I hit the database or fake it????
describe ElephantController do
before { Elephant.delete_all }
let(:controller) { ElephantController.new }
describe "getting the hungry elephants" do
it "should work just fine if I hit the database here, no big deal" do
@darrencauthon
darrencauthon / first.rb
Last active August 29, 2015 14:05
Kilt Things
gem 'kilt-cms'
@darrencauthon
darrencauthon / bagpipe_controller.rb
Last active August 29, 2015 14:05
Kilt Front-end Example
class BagpipeController < ApplicationController
def index
@bagpipes = Kilt.bagpipes
end
def view
@bagpipe = Kilt.get(params[:id])
end
@darrencauthon
darrencauthon / 1_record_finder.rb
Created August 25, 2014 21:48
Overriding the constructor
class RecordFinder
def initialize username, password
@username = username
@password = password
end
end
@darrencauthon
darrencauthon / install-17.0.sh
Created August 28, 2014 03:41 — forked from bryanhunter/install-r14b03.sh
Installed on Ubuntu 12.04, Erlang 17.0
apt-get -y install build-essential m4 libncurses5-dev libssh-dev unixodbc-dev libgmp3-dev libwxgtk2.8-dev libglu1-mesa-dev fop xsltproc default-jdk
apt-get -y install make
apt-get -y install libncurses5-dev
mkdir -p /src/erlang
cd /src/erlang
wget http://www.erlang.org/download/otp_src_17.0.tar.gz
tar -xvzf otp_src_17.0.tar.gz
chmod -R 777 otp_src_17.0
cd otp_src_17.0
./configure
@darrencauthon
darrencauthon / 1_install_erlang.sh
Created August 28, 2014 14:27
Install Elixir v0.14.2
apt-get -y install build-essential m4 libncurses5-dev libssh-dev unixodbc-dev libgmp3-dev libwxgtk2.8-dev libglu1-mesa-dev fop xsltproc default-jdk
apt-get -y install make
apt-get -y install libncurses5-dev
mkdir -p /src/erlang
cd /src/erlang
wget http://www.erlang.org/download/otp_src_17.0.tar.gz
tar -xvzf otp_src_17.0.tar.gz
chmod -R 777 otp_src_17.0
cd otp_src_17.0
./configure