Skip to content

Instantly share code, notes, and snippets.

View timrandg's full-sized avatar

Tim Rand timrandg

View GitHub Profile
@timrandg
timrandg / fiber return values
Created September 17, 2011 22:09
why do fibers do this?
#I am curious why a fiber returns the arguments when there are no more yield statements left to evaluate--see below. Why not return nil?
fiber = Fiber.new do |first, second|
Fiber.yield first + 30
Fiber.yield first + 20
end
p fiber.resume 10, 20 # => 40
p fiber.resume 10, 20 # => 30
class Array
def test
end
end
class Tim
def test
end
end
public
def rec_flatten
collection ||= []
return collection if self == []
if self.class != Array
return collection << self
end
collection + self[0].rec_flatten + self[1..-1].rec_flatten
end
public
def rec_flatten
collection ||= []
return collection if self == []
if self.class != Array
return collection << self
end
collection + self[0].rec_flatten + self[1..-1].rec_flatten
end
public
def rec_flatten
collection ||= []
return collection if self == []
if self.class != Array
return collection << self
end
collection + self[0].rec_flatten + self[1..-1].rec_flatten
end
require 'rinruby'
collection = []
r=RinRuby.new(:echo=>false)
10.times{collection << rand(10)}
r.y = collection
r.eval "plot(c(1:10), y)"
#need to sleep so that when the script ends, and R closes, the plot window won't close also
require 'rinruby'
collection = []
100.times{collection << rand(100)}
y = collection
x = (1..100).to_a
def point_plot(x,y,color)
r=RinRuby.new(:echo=>false)
r.y = y
require 'rinruby'
collection = []
100.times{collection << rand(100)}
y = collection
x = (1..100).to_a
def point_plot(x,y,color)
r=RinRuby.new(:echo=>false)
r.y = y
require 'rinruby'
def point_plot(data_dir, data_file, pdf_file)
data_in = File.join(data_dir, data_file)
pdf = File.join(data_dir, pdf_file)
r = RinRuby.new(:echo=>false)
puts "Messages From R console:"
r.eval <<EOF
pdf(#{pdf.inspect}, onefile = TRUE)