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
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
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.'
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.' }
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
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
# 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]
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)
def returning(value) yield; value; end
# divide the input into runs of consecutive numbers
s = input.slice_before(State.new(input.first)) do |value, state|
returning(value != state.last_value.succ) do
NAME = "ruby3" # eg: JAERLANG, RAILS -*- ruby -*-
# This stanza is for the creation of the code .zip and .tgz files.
# It's also used for the .mobi file
TITLE = "Programming Ruby 1.9"
AUTHOR = "Thomas, with Fowler and Hunt"
CODE_IGNORE_LIST = "README"
require "../PPStuff/util/rake/main.rb"
# A poor implementation of FizzBuzz, just to show code coverage stuff
1.upto(100).with_object('') do |i, x|
if i % 3 == 0
x += 'Fizz'
end
if i % 5 == 0
x += 'Buzz'
end
if x.empty?
require 'coverage'
Coverage.start
STDOUT.reopen("/dev/null")
require_relative 'fizzbuzz.rb'
Coverage.result.each do |file_name, counts|
File.readlines(file_name).each_with_index do |code_line, line_number|
count = counts[line_number] || "--"
STDERR.printf "%3s: %s", count, code_line
end
end