Skip to content

Instantly share code, notes, and snippets.

@nagachika
nagachika / block_benchmark.rb
Created November 5, 2011 14:01
CRuby extension for stacksize.
require "benchmark"
require_relative "stacksize"
class EnumBlkCall
def initialize(num)
@num = num
end
def each(&blk)
i = 0
while i < @num
@nagachika
nagachika / test_engine.rb.patch
Created November 14, 2011 15:34
patch for openssl test to suppress message.
diff --git a/test/openssl/test_engine.rb b/test/openssl/test_engine.rb
index fce5f76..db80521 100644
--- a/test/openssl/test_engine.rb
+++ b/test/openssl/test_engine.rb
@@ -41,6 +41,10 @@ class OpenSSL::TestEngine < Test::Unit::TestCase
end
def test_openssl_engine_cipher_rc4
+ # suppress message from OpenSSL
+ tmpfile = Tempfile.new("openssl_cipher_rc4")
@nagachika
nagachika / record_soundflower.rb
Created November 20, 2011 16:05
record via Soundflower with ruby-coreaudio
#!/usr/bin/env ruby
require "coreaudio"
# Usage: record_soundflower.rb output.m4a
def silent?(wav)
wav.max == 0 and wav.min == 0
end
@nagachika
nagachika / benchmark.txt
Created December 27, 2011 03:04
benchmark result (ruby-trunk r34138)
@GNU/Linux 2.6.9-89.ELsmp Intel Xeon CPU 3.80GHz
OLD = ruby 2.0.0dev (2011-12-26 trunk 34132) [x86_64-linux]
NEW = ruby 2.0.0dev (2011-12-26 trunk 34138) [x86_64-linux]
name OLD NEW diff (diff %)
vm3_gc 4.86306 2.51985 -2.34321 (-48.184%)
vm_thread_pass_flood 0.95898 0.69652 -0.26246 (-27.369%)
app_mandelbrot 5.21070 4.14362 -1.06709 (-20.479%)
so_random 2.61012 2.13744 -0.47268 (-18.109%)
@nagachika
nagachika / banchmark_r34134.txt
Created December 27, 2011 04:08
benchmark result (ruby-trunk r34134)
@GNU/Linux 2.6.9-89.ELsmp Intel Xeon CPU 3.80GHz
OLD = ruby 2.0.0dev (2011-12-26 trunk 34132) [x86_64-linux]
NEW = ruby 2.0.0dev (2011-12-26 trunk 34134) [x86_64-linux]
OLD NEW diff (diff %)
vm3_gc 4.99243 2.60234 -2.39009 (-47.874%)
app_mandelbrot 5.28168 4.16063 -1.12105 (-21.225%)
so_mandelbrot 16.82127 13.69298 -3.12829 (-18.597%)
so_partial_sums 16.27839 13.77973 -2.49866 (-15.350%)
diff --git a/lib/test/unit.rb b/lib/test/unit.rb
index eb0666a..00313a3 100644
--- a/lib/test/unit.rb
+++ b/lib/test/unit.rb
@@ -457,7 +457,9 @@ module Test
bang = $1
worker.status = :ready
if @tasks.empty?
- break unless @workers.find{|x| x.status == :running }
+ unless @workers.find{|x| [:running, :prepare].include? x.status}
@nagachika
nagachika / test_io.rb.patch
Created January 6, 2012 17:29
patch for test_autoclose
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 76eb82c..0fbec35 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -1409,13 +1409,15 @@ class TestIO < Test::Unit::TestCase
end
def try_fdopen(fd, autoclose = true, level = 100)
- if level > 0
- try_fdopen(fd, autoclose, level - 1)
@nagachika
nagachika / godscope.rb
Created January 26, 2012 04:33
godscope
# `publish' all private instance methods
ObjectSpace.each_object(Module) do |mod|
mod.private_instance_methods(false).each do |meth|
mod.__send__(:public, meth)
end
end
# define accessor methods as ghost method
class Object
def method_missing(meth, *args)
@nagachika
nagachika / puzzle_1.alloy
Created February 5, 2012 06:24
alloy exercise for a puzzle
enum Cap { Black, White }
abstract sig Children {
cap: one Cap,
visible: set Children
}
one sig A extends Children {} {
visible = none
cap = Black
@nagachika
nagachika / example_lazy_flat_map.rb
Created March 9, 2012 06:59
example of Enumerable::Lazy#flat_map
ary = (0..10).to_a
o = Object.new
o.instance_variable_set(:@ary, ary)
def o.to_ary
@ary
end
l = [o].lazy.flat_map{|x| x}
p l.next # => 0
ary.clear