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
#!/usr/bin/env ruby | |
N=10_000_000 | |
module CheapString | |
def `(s); s; end | |
end | |
class Stringer | |
include CheapString |
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
#!/usr/bin/env ruby | |
def outer | |
outer2 | |
rescue Exception => e | |
puts "Caught error: #{e}" | |
puts e.backtrace.join("\n") | |
end | |
def outer2 |
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
#!/usr/bin/env ruby | |
require 'set' | |
require 'benchmark' | |
nerrors = 1 | |
iterations = 1000000 | |
def count_allocations(label, iterations) | |
stat_before = GC.stat |
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
#!/usr/bin/env ruby | |
require 'active_support' | |
class Frobnicator | |
def frobnicate | |
ActiveSupport::Notifications.instrument('frobnicate') do | |
puts 'frobnicating' | |
end | |
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
#!/usr/bin/env ruby | |
# This implementation is adapted from Peter Cooper's - original available here: | |
# https://github.com/peterc/whatlanguage/blob/master/lib/whatlanguage/bitfield.rb | |
class ArrayBitField | |
attr_reader :size | |
attr_accessor :field | |
include Enumerable | |
ELEMENT_WIDTH = 32 |
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
#!/usr/bin/env ruby | |
# Pass 'fork' as the first argument to use Process.fork, otherwise Process.daemon is used. | |
do_fork = (ARGV[0] == 'fork') | |
thread = Thread.new do | |
loop { sleep(1) } | |
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
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
# This file is distributed under New Relic's license terms. | |
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details. | |
require 'tempfile' | |
require 'rbconfig' | |
def fail(msg, opts={}) |
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
#!/usr/bin/env ruby | |
# | |
# When run against rails/rails commit 91684fb193a91671d682701cc1357e7b4b3fbe2b, | |
# this code produces the following output on my machine: | |
# | |
# long start @ 0.000 | |
# short start @ 0.510 | |
# short finish @ 1.511 | |
# short reported 1.511186 s |
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
#!/usr/bin/env ruby | |
require 'yajl' | |
depth = ARGV[0].to_i | |
root = [] | |
a = root | |
depth.times { a << []; a = a[0] } | |
puts Yajl::Encoder.encode(root) |
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
# Install ruby-build | |
git clone [email protected]:sstephenson/ruby-build.git ~/.ruby-build | |
cd ~/.ruby-build | |
./install.sh | |
# List definitions | |
ruby-build --definitions | |
# Install some Rubies | |
ruby-build jruby-1.7.6 ~/.rubies/jruby-1.7.6 |