This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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| |
This file contains hidden or 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
| # 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, |
This file contains hidden or 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 "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 |
This file contains hidden or 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
| # 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] |
This file contains hidden or 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
| writer :whatever do |this_writer| | |
| this_writer.block_depth = 10 | |
| end |
This file contains hidden or 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 "#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 |
This file contains hidden or 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
| # 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 |
This file contains hidden or 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
| # encoding: UTF-8 | |
| class DoBlendingCrossover < Machine | |
| def initialize | |
| @number_to_create = 1 | |
| end | |
| def create (n) | |
| @number_to_create = n | |
| end | |
This file contains hidden or 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
| 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 |