Skip to content

Instantly share code, notes, and snippets.

View adamwiggins's full-sized avatar

Adam Wiggins adamwiggins

View GitHub Profile
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,...]
#!/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
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}")
$ 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 -----
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