Skip to content

Instantly share code, notes, and snippets.

View Vaguery's full-sized avatar

Bill Tozier Vaguery

View GitHub Profile
block {
value «float»
value «float»
do float_duplicate
do float_add
do int_add
value «float»
do float_divide }
«float» 8.2
«float» -92.0
answers.each do |answer|
execute <<-query
INSERT INTO scores (name, value, answer_id) VALUES (
'#{answer.name}',
#{answer.score.value},
#{answer.answer_id})
query
end
guts = answers.inject("") do |query,answer|
# assume that we'll be attaching to a dataset with 9 records,
# and that the 'records' in our dataset are [0,1,2,3,4,5,6,7,8]
# the Grab interpreter splits scripts into lines;
# any line that isn't an obvious instruction is ignored;
# all leading and trailing whitespace is stripped from every line;
# all characters on a line after an instruction has been recognized is ignored;
# instructions must be the first non-whitespace position of a line or the line is ignored
# running the script makes cumulative changes to a 'working subset' of the dataset,
describe "causes rspec-2.0.1 to hang when running from command line under ruby 1.9.2-p0" do
it "this sets up the problem" do
class String
alias :to_int :to_i # comment this out to silence the problem
end
end
it "hangs when you raise an exception" do
raise "x"
end
# method for inserting items into an Array without overlapping or nesting them
a = (1..10).to_a
# [1,2,3,4,5,6,7,8,9,10]
where = (10.times.collect {rand(10)}).sort {|a,b| b <=> a}
# e.g., [9, 9, 8, 8, 7, 5, 4, 3, 3, 0]
where.each {|position| a.insert(position,["foo","bar"]).flatten!}
a
# ["foo", "bar", 1, 2, 3, "foo", "bar", "foo", "bar", 4, "foo", "bar", 5, "foo", "bar", 6, 7, "foo", "bar", 8, "foo", "bar", "foo", "bar", 9, "foo", "bar", "foo", "bar", 10]
@Vaguery
Vaguery / gist:637484
Created October 20, 2010 22:35 — forked from trek/gist:637477
writer :whatever do |this_writer|
this_writer.block_depth = 10
end
describe "#random" do
it "should use the settings specified elsewhere" do
pending "what needs to be specced?"
boring_writer = NudgeWriter.new
boring_writer.block_width 10
boring_writer.block_depth 0
boring_writer.int_range 13...13
boring_writer.use_instructions :float_add
boring_writer.use_refs :t66
boring_writer.use_random_values :int
@Vaguery
Vaguery / scary_string.rb
Created October 23, 2010 21:32
possibly foolish extension of String class to take optional parameters via a Hash
# I'm inviting suggestions for refactoring this initialize method---without losing the fact that it's a subclass of String
# should accept empty arguments;
# should accept a string, and set default attributes;
# should accept a string, with optional Hash args to set attributes;
# should raise an error if there is no String but there is a Hash
class ExtraString < String
attr_accessor :optional_parameter
# encoding: UTF-8
class DoBlendingCrossover < Machine
def initialize
@number_to_create = 1
end
def create (n)
@number_to_create = n
end
@Vaguery
Vaguery / example_1.rb
Created November 9, 2010 01:25
The StrawpigScript class for creating and evaluating random arithmetic expressions in a simple linear GP language, and two examples from the book I'm working on.
require './strawpig'
puts "sample, x-20, x-10, x-1, x0, x1, x10, x20"
100.times do |i|
straw = StrawpigScript.new(10)
puts "#{i}" +
[-20,-10,-1,0,1,10,20].inject("") {|line, x| line + ", #{straw.evaluate(x).round(5)}"}
end