Skip to content

Instantly share code, notes, and snippets.


Mike Jansen mjansen401

View GitHub Profile
View coin_changer.rb
class CoinChanger
def self.change(amount)
change = []
[25,10,5,1].each do |coin|
while amount >= coin
change << coin
amount -= coin
mjansen401 / gist:5735432
Created Jun 8, 2013
SFW spec failures, Ruby 1.9.2-p180
View gist:5735432
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"}]
GET /recent-changes.json the JSON does not show page with journal but without date
# No reason given
# ./spec/server_spec.rb:195
View gist:5542910
def payment_account
class PaymentAccountPresenter
def billing_info
def subscription
mjansen401 / gist:4588620
Last active Dec 11, 2015
Observer pattern example in Ruby, using stocks and stock tickers
View gist:4588620
class Stock
def initialize(symbol)
@symbol = symbol
@observers = []
def register_observer(observer)
@observers << observer
View gist:3968740
;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 / core.clj
Created Sep 26, 2012
GildedRose Clojure solution (with @patrickgombert)
View core.clj
;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 / gist:3779498
Created Sep 25, 2012
Coin Changer solution in Clojure
View gist:3779498
(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 / !tests
Created Jun 28, 2012
GildedRose solution
View !tests
A solution to the Gilded Rose kata in Ruby with specs included.
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 / gist:2630461
Created May 7, 2012
Tune Ruby's garbage collector
View gist:2630461
Courtesy of
Add to your .bash_profile:
export RUBY_HEAP_MIN_SLOTS=500000
export RUBY_GC_MALLOC_LIMIT=50000000
mjansen401 / gist:1362587
Created Nov 13, 2011
Todo Collection 2
View gist:1362587
namespace("Todo.collections", {
Todos : Backbone.Collection.extend({
model: Todo.models.Todo
url: "todos"