Skip to content

Instantly share code, notes, and snippets.

View meaganewaller's full-sized avatar

Meagan Waller meaganewaller

View GitHub Profile
@meaganewaller
meaganewaller / html_formatter.rb
Created January 1, 2015 01:39
strategy pattern
# html_formatter
class HTMLFormatter
def output_report(context)
puts '<html>'
puts ' <head>'
puts " <title>#{context.title}</title>"
puts ' </head>'
puts ' <body>'
context.text.each do |line|
puts " <p>#{line}</p>"
@meaganewaller
meaganewaller / after.rb
Created January 1, 2015 01:35
Refactoring Coin Changer Kata
class CoinChanger
def initialize
@purse = Hash.new(0)
@coin_values = { :quarter => 25, :dime => 10, :nickel => 5, :penny => 1}
end
def make_change(amount)
@coin_values.each_value do |value|
if amount >= value
meagan = Employee.new('Meagan', 'Apprentice', 100000)
meagan.salary = 250000
# Warning! Inconsistent state here!
meagan.title = 'President of the United States'
@meaganewaller
meaganewaller / example.rb
Created January 1, 2015 01:00
adding environment to rake task
desc "Rake task description"
task :task => :environment do
puts "My rask taks does this thing!"
end
@meaganewaller
meaganewaller / gotchas.vim
Created January 1, 2015 00:59
getting started with clojure
" Vim indent file
....
"Speclj Indentation Support
setlocal
lispwords+=describe,it,context,around,should=,should-not=,should-not,should,should-be,with,run-specs
...
@meaganewaller
meaganewaller / anon.clj
Created January 1, 2015 00:57
anonymous functions in clojure
; the syntax
(fn [param-list]
function body)
(map (fn [n] (str "hello " n)) [ "alice" "bob" "carl"])
; => ("hello alice", "hello bob", "hello carl")
((fn [x] (* x 3)) 5)
;=> 15
@meaganewaller
meaganewaller / 1.clj
Created January 1, 2015 00:51
clojure fizzbuzz
(ns fizzbuzz.core-spec
(:require [speclj.core :refer :all]
[fizzbuzz.core :refer :all]))
(describe "fizzbuzz"
(it "1 is 1"
(should=1 (fizzbuzz 1))))
@meaganewaller
meaganewaller / wishlist-spec.clj
Last active August 29, 2015 14:12
Mocking Functions in Clojure
(ns wishes.wishlist-spec
(:require
[wishes.wishlist :refer all]
[speclj.core :refer all]))
(describe "Wishlist"
(with fake-wishlist
{:name "Fake Wishlist"
:description "My Fake Wishlist"})
@meaganewaller
meaganewaller / before_clojure.clj
Created January 1, 2015 00:38
Conditional Binding in Clojure
(defn first-function [args]
(let [first (first/suggest (:input args))]
{:status 200 :headers {"Content-Type" "application/json"} :body {:first-entity
first}}))
(defn second-function [args]
(let [second (second/suggest (:input args))]
{:status 200 :headers {"Content-Type" "application/json"} :body {:second-entity
second}}))
super_simple_rack_proc = lambda { puts 'Super Simple Rack App' }
super_simple_rack_proc.call