Skip to content

Instantly share code, notes, and snippets.

View slyphon's full-sized avatar

Jonathan Simms slyphon

View GitHub Profile
@slyphon
slyphon / gist:2578260
Created May 2, 2012 17:06 — forked from jhosteny/gist:2578253
FuseFS with celluloid
require 'fusefs'
paxosdir = DCell::Paxos::PaxosDir.new(DCell.registry.globals.root)
FuseFS.set_root(paxosdir)
# Mount under a directory given on the command line.
FuseFS.mount_under "/tmp/foobar"
FuseFS.run
require 'thread'
mutex = Mutex.new
cv = ConditionVariable.new
a = Thread.new {
mutex.synchronize {
puts "A: I have critical section, but will wait for cv"
cv.wait(mutex)
puts "A: I have critical section again! I rule!"
cv.signal
typedef struct {
int a;
char *str;
} foo_t;
foo_t * foo_alloc(void) {
foo_t *rv = malloc(sizeof(foo));
if (!rv)
@slyphon
slyphon / lock_with_dead_session.rb
Created April 21, 2012 01:23
what happens to a lock waiting to acquire, and the session expires?
#!/usr/bin/env ruby
require 'rubygems'
require 'zk'
zk = ZK.new
puts "session_id: 0x%x" % zk.session_id
lock_name = 'the_big_sleep'
@slyphon
slyphon / threadpool-job-run.rb
Created April 20, 2012 23:49
how to use a basic threadpool
#!/usr/bin/env ruby
require 'rubygems'
require 'thread'
require 'zk'
require 'logger'
# make these results repeatable:
srand(42)
[9] pry(main)> a = [0,1,2,3,4,5,6,7]
=> [0, 1, 2, 3, 4, 5, 6, 7]
[10] pry(main)> a = a[3..-1] + a[0...3]
=> [3, 4, 5, 6, 7, 0, 1, 2]
[11] pry(main)> c = a.to_enum.cycle
=> #<Enumerator: ...>
[12] pry(main)> 20.times { puts c.next }
3
4
5
#!/usr/bin/env ruby
class Configuration
class BogusValue
def [](k)
return self
end
# 1.9 only
def !
@slyphon
slyphon / jruby-1.6.0-wat.out
Created April 2, 2012 19:03
i can't figure out where this is coming from
--- System
jruby 1.6.0.dev (ruby 1.8.7 patchlevel 249) (2010-09-28 a49928c) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java]
Time: Mon Apr 02 18:53:46 +0000 2012
Server: jetty/6.1.22
jruby.home: file:/var/cache/jetty/data/Jetty_0_0_0_0_8080_mother.war____qsas8g/webapp/WEB-INF/lib/jruby-stdlib-1.6.7.jar!/META-INF/jruby.home
@slyphon
slyphon / zookeeper-callback-test.rb
Created March 27, 2012 16:42
this registers a watcher, which you can manipulate in another session w/ irb
#!/usr/bin/env ruby
require 'bundler/setup'
require 'zookeeper'
require 'logger'
TEST_PATH = '/testpathfor'
Zookeeper.logger = Logger.new($stderr).tap {|l| l.level = Logger::DEBUG }
# knife ssh based on role
kssh-role() {
if [[ $# -lt 2 ]]; then
echo "Usage: kssh-role rolename 'cmd' ..." >&2
return 1
fi
local role=$1
shift
local cmd=$1