Skip to content

Instantly share code, notes, and snippets.

View pragdave's full-sized avatar
🖍️
Alternating between Haskell and PDP-11 assembler

Dave Thomas pragdave

🖍️
Alternating between Haskell and PDP-11 assembler
View GitHub Profile
# encoding: utf-8
input = [ 1, 2, 3, 4, 5, 8, 9, 11, 12, 13, 15 ]
# Need to box the value to make it mutable
State = Struct.new(:last_value)
# divide the input into runs of consecutive numbers
s = input.slice_before(State.new(input.first)) do |value, state|
(_, state.last_value = value != state.last_value.succ, value)[0]
Stephenson, G. R. (1967). Cultural acquisition of a specific learned response among rhesus monkeys. In: Starek,
D., Schneider, R., and Kuhn, H. J. (eds.), Progress in Primatology, Stuttgart: Fischer, pp. 279-288.
mentioned in: Galef, B. G., Jr. (1976). Social Transmission of Acquired Behavior: A Discussion of Tradition and
Social Learning in Vertebrates. In: Rosenblatt, J.S., Hinde, R.A., Shaw, E. and Beer, C. (eds.), Advances in the
study of behavior, Vol. 6, New York: Academic Press, pp. 87-88:
[...] Stephenson (1967) trained adult male and female rhesus monkeys to avoid manipulating an object and then
placed individual naïve animals in a cage with a trained individual of the same age and sex and the object in
Stephenson, G. R. (1967). Cultural acquisition of a specific learned response among rhesus monkeys. In: Starek, D., Schneider, R., and Kuhn, H. J. (eds.), Progress in Primatology, Stuttgart: Fischer, pp. 279-288.
mentioned in: Galef, B. G., Jr. (1976). Social Transmission of Acquired Behavior: A Discussion of Tradition and Social Learning in Vertebrates. In: Rosenblatt, J.S., Hinde, R.A., Shaw, E. and Beer, C. (eds.), Advances in the study of behavior, Vol. 6, New York: Academic Press, pp. 87-88:
[...] Stephenson (1967) trained adult male and female rhesus monkeys to avoid manipulating an object and then placed individual naïve animals in a cage with a trained individual of the same age and sex and the object in question. In on case, a trained male actually pulled his naïve partner away from the previously punished manipulandum during their period of interaction, whereas the other two trained males exhibited what were described as "threat facial expressions while in a fear posture" when a naïve animal appro
validates :title, :description, :image_url, :presence => true
validates :price, :numericality => { :greater_than => 0 }
validates :title, :uniqueness => true
validates :image_url,
:format => { :with => %r{\.(gif|jpg|png)$}i,
:message => 'must be a URL for GIF, JPG or PNG image.' }
validates_presence_of :title, :description, :image_url
validates_numericality_of :price, :greater_than => 0
validates_uniqueness_of :title
validates_format_of :image_url,
:with => %r{\.(gif|jpg|png)$}i,
:message => 'must be a URL for GIF, JPG or PNG image.'
Card = Struct.new(:rank, :suit)
dealer = Fiber.new do
ranks = (1..13).to_a
suits = [:club, :diamond, :heart, :spade]
pack = ranks.product(suits).map {|card| Card.new(*card)}
all_cards = pack*7
cards = []
loop do
cards = all_cards.shuffle if cards.size < 2*52
Fiber.yield cards.pop