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 "benchmark" | |
| @callbacks = %w( | |
| TimerFired | |
| ConnectionData | |
| ConnectionUnbound | |
| ConnectionAccepted | |
| ConnectionCompleted | |
| LoopbreakSignalled | |
| ConnectionNotifyReadable |
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 "benchmark" | |
| require 'bigdecimal' | |
| class BigDecimal | |
| # raggi after hint from apeiros (round 1) | |
| def raggi_round(n = 15) | |
| s = to_s('f')[0,n+1] | |
| i = s.index('.') | |
| dp = n - i | |
| dp = 0 if dp < 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
| # The Question: Should this work? | |
| # The Bonus Question: Does it, and in what capacity? | |
| def parse_message(str) | |
| last = nil | |
| @parser ||= Parser.new { |message| last = message } | |
| @parser << str | |
| last | |
| 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 'benchmark' | |
| def many | |
| 10000 | |
| end | |
| def push(left_array_size, right_array_size) | |
| left = Array.new(left_array_size) { |n| n } | |
| right = Array.new(right_array_size) { |n| n } | |
| Benchmark.realtime{ many.times{ |i| left.push(*right) } } |
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 "benchmark" | |
| STRING = '1234567890' | |
| FROZEN = STRING.dup.freeze | |
| FROZEN_KEY = { | |
| FROZEN => :something | |
| } |
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 "benchmark" | |
| KEY = '1234567890' | |
| HASH = { | |
| KEY => KEY | |
| } | |
| TESTS = 2_000_000 |
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
| def times_for_period(date) | |
| regular_hours_by_week = Hash.new(0) | |
| regular_hours = 0 | |
| other_hours = Hash.new(0) | |
| work_days_for_period(date).each do |d| | |
| times = d.times | |
| regular_hours += times[:regular_hours] |
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 | |
| domain, room, *message = ARGV | |
| token = File.read(ENV['HOME'] + '/.talker').strip | |
| abort <<-TEXT unless domain && room && token | |
| Usage: #{File.basename($0)} domain room_id [message] | |
| Reads from stdin if no message supplied | |
| Expects a user token in $HOME/.talker | |
| TEXT |
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
| def alias_task(name, old_name) | |
| t = Rake::Task[old_name] | |
| desc t.full_comment if t.full_comment | |
| task name, *t.arg_names do |_, args| | |
| # values_at is broken on Rake::TaskArguments | |
| args = t.arg_names.map { |a| args[a] } | |
| t.invoke(args) | |
| 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
| # This bug seems to occur on 1.8.6..1.9 on OSX and FreeBSD. It's known not to occur on Linux. | |
| require 'rubygems' | |
| require 'minitest/unit' | |
| include MiniTest::Assertions | |
| require 'tempfile' | |
| path = nil | |
| begin |