Skip to content

Instantly share code, notes, and snippets.

require 'benchmark'
require 'thread'
require 'disruptor'
require_relative 'atomic_linked_queue'
$thread_count = 50
$iterations = 10
Thread.abort_on_exception = true
array = Array.new
trap(:INT) do
p array.size
exit
end
Thread.new do
loop do
array << 2
~/projects/shopify > cap staging deploy
* 2012-11-19 22:55:20 executing `staging'
* 2012-11-19 22:55:20 executing `set_staging_servers'
* 2012-11-19 22:55:20 executing `deploy'
triggering before callbacks for `deploy'
* 2012-11-19 22:55:20 executing `deploy:lock'
servers: ["app1.core.staging.ec2.shopify.com"]
** sftp upload #<StringIO:0x007fe0c24fe2f0> -> /u/apps/shopify/shared/system/lock.txt
[app1.core.staging.ec2.shopify.com] /u/apps/shopify/shared/system/lock.txt
[app1.core.staging.ec2.shopify.com] done
class Foo
include Module.new {
def this_works
end
}
include Module.new do
def this_doesnt_work
end
end
class Foo
include Module.new {
def this_works
end
}
include Module.new do
def this_doesnt_work
end
end
module Kernel
def system(*args)
rd, wr = IO.pipe
# Create a new subprocess that will just exec the requested program.
pid = fork do
# The sub-process closes its copy of the reading end of the pipe
# because it only needs to write.
rd.close
Rehearsal -------------------------------------------------
string interp 0.200000 0.000000 0.200000 ( 0.202780)
array join 0.520000 0.020000 0.540000 ( 0.540294)
---------------------------------------- total: 0.740000sec
user system total real
string interp 0.210000 0.000000 0.210000 ( 0.216187)
array join 0.520000 0.000000 0.520000 ( 0.518884)
Jesse Storimer is the author of <a href="http://workingwithunixprocesses.com">Working With Unix Processes</a> and currently works at <a href="http://shopify.com">Shopify</a>. You can find him online as @jstorimer on Twitter/Github.</p>

RocketSocket

This library was created out of my frustrations working with the Ruby's built-in Socket classes when writing Working With Sockets. It provides two functions: 1) A better way of building sockets with the common options that are more configurable/portable, and 2) A built-in way of framing messages in an safe and efficient manner. Nothing fancy.

RocketSocket::Build

socket = RocketSocket::Build.host('0.0.0.0').port(8080).ssl.read_timeout(60).write_timeout(10).listen(512).tcp
socket.write_timeout #=> 10
require 'socket'
# Ruby 1.8
Process.getrlimit(Process::RLIMIT_CORE)
Process.getrlimit(Process::RLIMIT_NOFILE)
# Ruby 1.9
Process.getrlimit(:CORE)
Process.getrlimit(:NOFILE)