View event_bus_spec.rb
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
describe 'EventBus methods cascade' do | |
Invariant { result.should == EventBus } | |
context 'clear' do | |
When(:result) { EventBus.clear } | |
Then { } | |
end | |
context 'publish' do | |
When(:result) { EventBus.publish('aa123bb', {}) } |
View temp2.rb
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
describe Stack do | |
# Suggested Syntax... | |
Invariants do | |
If { stack.empty? } | |
Then { stack.depth.should == 0 } | |
Then { stack.should be_pushable } | |
ElseIf { stack.full? } | |
Then { stack.depth.should == stack.max_depth } | |
Then { stack.should_not be_pushable } |
View urinal.rb
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 Urinal | |
def initialize(occupied, line) | |
@occupied = occupied | |
@line = line | |
end | |
def select | |
scores = stalls.map { |n| [score(n), n] } | |
best = scores.sort.last | |
best.first < 0 ? nil : best.last |
View change-case.el
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
;; Grateful thanks are given to Brian Marick (@marick) for helping me | |
;; write these. I got the original idea while reading through | |
;; http://xahlee.org/emacs/elisp_idioms.html, but couldn't work out | |
;; the elisp regexes. Brian Marick (@marick) stepped in and helped. He | |
;; took my tortured and broken camelcase-region and turned it into | |
;; something that actually worked. I then created | |
;; camelcase-word-or-region. I then wrote the snakecase versions but I | |
;; see now that all I did was copy the camelcase defuns over and, | |
;; meaning to go back and finish them Real Soon Now, forgot all about | |
;; them. I've had a quick look (2011-02-27) but elisp regexes are |
View gist:189244
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
;; SICP 1.4 | |
;; | |
;; Exercise 1.4. Observe that our model of evaluation allows for | |
;; combinations whose operators are compound expressions. Use this | |
;; observation to describe the behavior of the following procedure: | |
(define (a-plus-abs-b a b) | |
((if (> b 0) + -) a b)) | |
;; (a-plus-abs-b 2 3) |
View gist:189242
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
;; SICP 1.3 | |
;; Exercise 1.3. Define a procedure that takes three numbers as | |
;; arguments and returns the sum of the squares of the two larger | |
;; numbers. | |
(define (square x) (* x x)) | |
(define (sum-of-squares a b) | |
(+ (square a) (square b)) ) |
View gist:189237
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
;; SICP Exercise 1.2: | |
;; Translate the following expression into prefix form | |
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 1 5))))) | |
(* 3 (- 6 2) (- 2 7)) ) | |
;; => -71/300 | |
;; or -0.236666666666667 |
View gist:189233
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
;; Exercise 1.1. Below is a sequence of expressions. What is the | |
;; result printed by the interpreter in response to each expression? | |
;; Assume that the sequence is to be evaluated in the order in which | |
;; it is presented. | |
;; 10 | |
;; => 10 | |
;; (+ 5 3 4) | |
;; => 12 |
View quiz.rb
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
# COMMUNITY CHALLENGE | |
# | |
# How would you test this Quiz#problem method? Only two rules: | |
# | |
# 1. The tests should fail if any part of the application breaks. | |
# For example: If "gets" is moved before "puts" then the tests should | |
# fail since that breaks the application. | |
# | |
# 2. You cannot change the Quiz class. But you can use whatever framework | |
# and tools you want for the tests. (RSpec, Cucumber, etc.) |
View quiz.rb
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
# COMMUNITY CHALLENGE | |
# | |
# How would you test this Quiz#problem method? Only two rules: | |
# | |
# 1. The tests should fail if any part of the application breaks. | |
# For example: If "gets" is moved before "puts" then the tests should | |
# fail since that breaks the application. | |
# | |
# 2. You cannot change the Quiz class. But you can use whatever framework | |
# and tools you want for the tests. (RSpec, Cucumber, etc.) |
NewerOlder