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 '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 |
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 '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 |
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
typedef struct { | |
int a; | |
char *str; | |
} foo_t; | |
foo_t * foo_alloc(void) { | |
foo_t *rv = malloc(sizeof(foo)); | |
if (!rv) |
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 | |
require 'rubygems' | |
require 'zk' | |
zk = ZK.new | |
puts "session_id: 0x%x" % zk.session_id | |
lock_name = 'the_big_sleep' |
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 | |
require 'rubygems' | |
require 'thread' | |
require 'zk' | |
require 'logger' | |
# make these results repeatable: | |
srand(42) |
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
[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 |
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 | |
class Configuration | |
class BogusValue | |
def [](k) | |
return self | |
end | |
# 1.9 only | |
def ! |
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
--- 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 |
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 | |
require 'bundler/setup' | |
require 'zookeeper' | |
require 'logger' | |
TEST_PATH = '/testpathfor' | |
Zookeeper.logger = Logger.new($stderr).tap {|l| l.level = Logger::DEBUG } |
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
# 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 |