Skip to content

Instantly share code, notes, and snippets.

View adamwiggins's full-sized avatar

Adam Wiggins adamwiggins

View GitHub Profile
$ 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 -----
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}")
module Semaphore
extend self
def lock(lock_number)
hold(lock_number)
yield
ensure
release(lock_number)
end
bigstring = ""
for (var i = 0; i < 1000; i++)
bigstring += " " + i
require('sys').puts(bigstring);
# 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
require 'sinatra'
require 'json'
class Pgdump
attr_reader :name
def initialize
@name = "dump-#{rand(99999)}"
@step = 0
end
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')
require "sinatra"
get "/" do
erb :index
end
require 'restclient'
require 'json'
hash = JSON.parse RestClient.get('http://json-test.heroku.com/', :accept => :json)
if hash['hello'] != 'world'
puts "Failed"
exit 1
end
config = URI.parse(ENV['MONGO_URL'] || 'mongodb://localhost:27017/thedb')
MongoMapper.connection = Mongo::Connection.new(config.host, config.port)
MongoMapper.database = config.path.gsub(/^\//, '')
MongoMapper.database.authenticate(config.user, config.password) if config.user