This file contains 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" | |
arr = [1,2,3,4,5,6,7,8,9,0] * 100 | |
GC.start | |
TESTS = 10_000 | |
Benchmark.bmbm do |results| | |
results.report("map:") { TESTS.times { arr.map { |i| i } } } | |
results.report("inj:") { TESTS.times { a = []; arr.inject(a, :<<) } } | |
end |
This file contains 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
class Binding | |
def set(hash) | |
backup = Thread.current[:binding_set] | |
hash.each do |var, val| | |
Thread.current[:binding_set] = val | |
eval(%(#{var} = Thread.current[:binding_set])) | |
end | |
ensure | |
Thread.current[:binding_set] = backup | |
end |
This file contains 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 'eventmachine' | |
require 'sequel' | |
# I stole this code from em-mysql (tmm1 <3) | |
module Sequel | |
class Database | |
attr_accessor :_async | |
end | |
class Dataset |
This file contains 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 | |
file = ARGV.first | |
abort "Usage: #{File.basename($0)} file.conf" unless file | |
cfg = [] | |
current_subtree = cfg | |
parent = cfg |
This file contains 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 is example code for an ML response. |
This file contains 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
class String | |
def hash18 | |
# cheeky integer truncate TODO move to bitmask, and method | |
trunc = lambda { |v| [v].pack('i').unpack('i').first } | |
key = 0 | |
each_byte do |b| | |
key = trunc.call(trunc.call(key*65599) + b) | |
end | |
trunc.call(key + trunc.call(key >> 5)) | |
end |
This file contains 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 'eventmachine' | |
class HTTP < EM::Connection | |
include EM::P::LineText2 | |
RESPONSE = <<-PLAIN | |
HTTP/1.1 200 OK | |
Content-Type: text/html | |
Content-Length: 12 | |
Connection: keep-alive |
This file contains 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
raggi@mbk: ~ % ab -q -k -c 10 -n 1000 http://127.0.0.1/ | egrep "HTML|Complete" | |
Complete requests: 1000 | |
HTML transferred: 44000 bytes | |
raggi@mbk: ~ % ab -q -k -c 10 -n 1000 http://127.0.0.1/ | egrep "HTML|Complete" | |
Complete requests: 1000 | |
HTML transferred: 44088 bytes | |
raggi@mbk: ~ % ab -q -k -c 10 -n 1000 http://127.0.0.1/ | egrep "HTML|Complete" | |
Complete requests: 1000 | |
HTML transferred: 44088 bytes | |
raggi@mbk: ~ % ab -q -k -c 10 -n 1000 http://127.0.0.1/ | egrep "HTML|Complete" |
This file contains 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 'thin' | |
request = "GET / HTTP/1.0\r\nHost: 127.0.0.1:3001\r\nUser-Agent: ApacheBench/2.3\r\nAccept: */*\r\n\r\n" | |
def rss | |
system "ps -orss= #{$$}" | |
end | |
rss | |
while true |
This file contains 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
class A | |
def example; end | |
def leak | |
method(:example) | |
end | |
end | |
a = A.new | |
a.leak while true |