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 "sinatra" | |
get "/" do | |
erb :index | |
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
UnitTest.begin("Buffer") | |
UnitTest.test("text", function() { | |
var input = "1\n2\n3\n" | |
buf = new Buffer(input) | |
assertEqual(input, buf.text()) | |
}) | |
UnitTest.test("insert", function() { | |
buf = new Buffer('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
require 'sinatra' | |
require 'json' | |
class Pgdump | |
attr_reader :name | |
def initialize | |
@name = "dump-#{rand(99999)}" | |
@step = 0 | |
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
# Using PTY instead of IO.popen, see answer: | |
# http://stackoverflow.com/questions/1154846/continuously-read-from-stdout-of-external-process-in-ruby | |
def spawn_command(command) | |
begin | |
PTY.spawn(command) do |stdin, stdout, pid| | |
Process.wait(pid) | |
begin | |
stdin.each { |line| message " #{line}" } | |
rescue Errno::EIO | |
# child process stopped giving input |
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
bigstring = "" | |
for (var i = 0; i < 1000; i++) | |
bigstring += " " + i | |
require('sys').puts(bigstring); |
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
module Semaphore | |
extend self | |
def lock(lock_number) | |
hold(lock_number) | |
yield | |
ensure | |
release(lock_number) | |
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 'memcache' | |
CACHE = Memcache.new(:servers => [ 'localhost:11211' ], :namespace => 'test') | |
def lock(name, secs=60, &block) | |
return !! CACHE.add("lock:#{name}", '1', secs) | |
end | |
def unlock(name) | |
CACHE.delete("lock:#{name}") |
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
$ bin/foreman export myapp example/Procfile inittab | |
# ----- foreman myapp processes ----- | |
R1:4:respawn:/bin/su - myapp -c './never_die >> log/neverdie.log 2>&1' | |
R2:4:respawn:/bin/su - myapp -c './die_alot >> log/diealot.log 2>&1' | |
R3:4:respawn:/bin/su - myapp -c './error >> log/error.log 2>&1' | |
# ----- end foreman myapp processes ----- |
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 'aws/s3' | |
usage = "#{$0} <file> <bucket> [<access>]" | |
abort(usage) unless fname = ARGV.shift | |
abort(usage) unless bucket = ARGV.shift | |
access = ARGV.shift || 'private' | |
include AWS::S3 |
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
foreman run [PSTYPE] [--screen,-s] [--procfile,-p FILENAME] | |
foreman export FORMAT(inittab,upstart) [--app,-a APP] [--output,-o FILE_OR_PATH] [--procfile,-p FILENAME] [PSTYPE=CONCURRENCY,...] |