Skip to content

Instantly share code, notes, and snippets.

Lambda: standard

# Creating a lambda
l = lambda { |name| "Hi #{name}!" }

# Executing the lambda
l.call("foo") # => Hi foo!
require 'io/console'
# Reads keypresses from the user including 2 and 3 escape character sequences.
def read_char
STDIN.echo = false
STDIN.raw!
input = STDIN.getc.chr
if input == "\e" then
input << STDIN.read_nonblock(3) rescue nil
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO
# Most instructions for using Capistrano tell you how to make it restart Phusion
# Passenger by 'touch'ing the restart.txt file, but this doesn't immediately
# restart the app - instead the first person to try to use the application will
# cause it to be restarted, so they will see a delay of at least a few seconds.
# This shows how to add a post-deploy task to 'ping' the server, to cause it to
# restart immediately.
# First, (optionally) add a '/ping' route to config/routes.rb that immediately
# returns a blank page. This prevents any non-essential work being done, such as
@AfonsoTsukamoto
AfonsoTsukamoto / em.rb
Last active August 29, 2015 14:11 — forked from khash/em.rb
@pid_full = '/tmp/my_daemon.pid'
def run
EM.run{
Signal.trap('INT') { stop }
Signal.trap('TERM'){ stop }
# your daemon code runs here. This will not exit since it is running in EM
}
end
@AfonsoTsukamoto
AfonsoTsukamoto / unicorn
Last active August 29, 2015 14:06 — forked from shapeshed/unicorn
#!/bin/sh
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/path/to/your/app/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
ENVIRONMENT=production