This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CoinChanger | |
def self.change(amount) | |
change = [] | |
[25,10,5,1].each do |coin| | |
while amount >= coin | |
change << coin | |
amount -= coin | |
end | |
end | |
change |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def payment_account | |
PaymentAccountPresenter.new(@member) | |
end | |
class PaymentAccountPresenter | |
def billing_info | |
... | |
end | |
def subscription |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stock | |
def initialize(symbol) | |
@symbol = symbol | |
@observers = [] | |
end | |
def register_observer(observer) | |
@observers << observer | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 []] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace("Todo.collections", { | |
Todos : Backbone.Collection.extend({ | |
model: Todo.models.Todo | |
url: "todos" | |
}) | |
}); |
NewerOlder