Skip to content

Instantly share code, notes, and snippets.

@jstorimer
jstorimer / -
Last active December 25, 2015 04:29
Vim plugins + vimrc
git_bundles = [
"git://github.com/ervandew/supertab.git",
"git://github.com/godlygeek/tabular.git",
"git://github.com/hallison/vim-rdoc.git",
"git://github.com/pangloss/vim-javascript.git",
"git://github.com/timcharper/textile.vim.git",
"git://github.com/tpope/vim-cucumber.git",
"git://github.com/tpope/vim-fugitive.git",
"git://github.com/tpope/vim-git.git",
"git://github.com/tpope/vim-haml.git",
require 'socket'
client = TCPSocket.new('localhost', 4481)
payload = "Lorem ipsum" * 100_000
total_bytes_written = 0
remaining_payload = payload
begin
puts 'looping'
@jstorimer
jstorimer / tclient.rb
Created June 25, 2013 21:09
These scripts were the result of the "Faster Rails test runs...with Unix!" screencast at https://www.youtube.com/watch?v=RSehcT4MnRM.
#!/usr/bin/env ruby
require 'socket'
test_file = ARGV[0]
socket = UNIXSocket.new('testing.sock')
socket.write(test_file)
socket.close_write
class Sheep
def initialize
@shorn = false
# Here the sheep owns the mutex. But now the
# shearing logic is muddied up by synchronization
# logic. This doesn't seem like the right place for
# this.
@mutex = Mutex.new
end
require 'benchmark'
require 'thread'
require 'disruptor'
require_relative 'atomic_linked_queue'
$thread_count = 50
$iterations = 10
Thread.abort_on_exception = true

This is a proof-of-concept of a couple of concurrent data structures written in Ruby.

The implementations are heavily commented for those interested. There are benchmarks (with results) included below. The results are interesting, but, as always, take with a grain of salt.

Data structures

AtomicLinkedQueue is a lock-free queue, built on atomic CAS operations.

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