Skip to content

Instantly share code, notes, and snippets.

View mjansen401's full-sized avatar

Mike Jansen mjansen401

View GitHub Profile
class CoinChanger
def self.change(amount)
change = []
[25,10,5,1].each do |coin|
while amount >= coin
change << coin
amount -= coin
end
end
change
@mjansen401
mjansen401 / gist:5735432
Created June 8, 2013 15:00
SFW spec failures, Ruby 1.9.2-p180
bundle exec rake spec
/Users/mike/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -S bundle exec rspec ./spec/favicon_spec.rb ./spec/integration_spec.rb ./spec/page_spec.rb ./spec/server_helpers_spec.rb ./spec/server_spec.rb ./spec/stores/couch_spec.rb
.FFFFFFFFFFFFFFFFFFFFF......F..FFFF.......FFFF.........................F[{"type"=>"paragraph", "id"=>"435d07cf9bf34a70", "text"=>"Here we list neighborhood pages with those most recently changed listed first. See also [[Local Changes]]."}, {"type"=>"activity", "id"=>"e9e9f102158e1382"}]
F.*...........
Pending:
GET /recent-changes.json the JSON does not show page with journal but without date
# No reason given
# ./spec/server_spec.rb:195
def payment_account
PaymentAccountPresenter.new(@member)
end
class PaymentAccountPresenter
def billing_info
...
end
def subscription
@mjansen401
mjansen401 / gist:4588620
Last active December 11, 2015 10:39
Observer pattern example in Ruby, using stocks and stock tickers
class Stock
def initialize(symbol)
@symbol = symbol
@observers = []
end
def register_observer(observer)
@observers << observer
end
@mjansen401
mjansen401 / gist:3968740
Created October 28, 2012 14:28
FP for OO typo
;Original function, p. 41 of FP for OO
user=> (def shift
(fn [this xinc yinc]
(Point (+ (x this) xinc)
(+ (y this) yinc))))
CompilerException java.lang.RuntimeException: Unable to resolve symbol: y in this context, compiling:(NO_SOURCE_PATH:1)
;Updated function with correct :x :y key use
user=> (def shift
@mjansen401
mjansen401 / core.clj
Created September 26, 2012 02:03
GildedRose Clojure solution (with @patrickgombert)
;the code
(ns gilded-rose.core)
(def vest "+5 Dexterity Vest")
(def brie "Aged Brie")
(def elixir "Elixir of the Mongoose")
(def sulfuras "Sulfuras, Hand of Ragnaros")
(def passes "Backstage passes to a TAFKAL80ETC concert")
(def cake "Conjured Mana Cake")
@mjansen401
mjansen401 / gist:3779498
Created September 25, 2012 01:42
Coin Changer solution in Clojure
(ns coin-changer.core)
(defn can-use-coin? [coin amount]
(<= coin amount))
(defn largest-coin [amount]
(some #(if (can-use-coin? % amount) %) [25 10 5 1]))
(defn change-for [n]
(loop [amount n coins []]
@mjansen401
mjansen401 / !tests
Created June 28, 2012 13:17
GildedRose solution
A solution to the Gilded Rose kata in Ruby with specs included.
Tests:
describe GildedRose do
VEST = "+5 Dexterity Vest"
ELIXIR = "Elixir of the Mongoose"
BRIE = "Aged Brie"
SULFURAS = "Sulfuras, Hand of Ragnaros"
BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert"
@mjansen401
mjansen401 / gist:2630461
Created May 7, 2012 21:10
Tune Ruby's garbage collector
Courtesy of http://www.rubyenterpriseedition.com/documentation.html#_garbage_collector_performance_tuning
Add to your .bash_profile:
export RUBY_HEAP_MIN_SLOTS=500000
export RUBY_HEAP_SLOTS_INCREMENT=250000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=50000000
@mjansen401
mjansen401 / gist:1362587
Created November 13, 2011 19:52
Todo Collection 2
namespace("Todo.collections", {
Todos : Backbone.Collection.extend({
model: Todo.models.Todo
url: "todos"
})
});