Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
set -u
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:
APP_ROOT=/home/deploy/public_html/rm/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
ENV=production
@mxcl
mxcl / fixnum+base62.rb
Created February 6, 2010 16:17
Readable Base 62 encoder
# Use this for your URL shortening needs
# Base 62 is as good as you can easily get for URL shortening
# And it's effective: 1_000_000 => '4c92'
# Challenge: fork and speed up the implementation!
class Fixnum
TOKENS = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a
# NOTE returns nil for 0
def to_62_s
@cookbooks
cookbooks / gist:731502
Created December 7, 2010 05:24
Grit clone example
# Since Git is well structured, Grit uses a method missing (Grit::Git#method_missing) to 'systematically' execute Git commands:
require 'grit'
include Grit
gritty = Grit::Git.new('/tmp/filling-in')
gritty.clone({:quiet => false, :verbose => true, :progress => true, :branch => '37s'}, "git://github.com/cookbooks/cc-aws.git", "/tmp/cc-aws2")
# => "Initialized empty Git repository in /tmp/cc-aws2/.git/\n"
Dir.entries('/tmp/cc-aws2').size
# => 10
@telamon
telamon / rdhcpd.rb
Created May 20, 2011 23:58
Pure ruby DHCP server
' Copyright (c) 2007, Tony Ivanov
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
@ninetwentyfour
ninetwentyfour / gist_helper.rb
Created May 30, 2011 02:42
Will create a gist and return the embed code with ruby
require 'net/http'
require 'uri'
require 'json'
def get_gist(fileName,content)
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/json/new'),
{ 'files[#{fileName}]' => content,
'login' => 'USER NAME HERE',
'token' => 'API TOKEN HERE',
'description' => 'This is a test description'
@matsuu
matsuu / net
Created July 15, 2011 17:22
gentoo 6rd setting for sakura VPS (/etc/conf.d/net)
config_eth0="aaa.bbb.ccc.ddd/23"
routes_eth0="default via aaa.bbb.ccc.1"
dns_servers_eth0="210.224.163.4 210.224.163.3"
iptunnel_6rd="mode sit local aaa.bbb.ccc.ddd ttl 64"
config_6rd="2001:e41:xxxx:xxxx::1/32" # printf "2001:e41:%02x%02x:%02x%02x::1\n" aaa bbb ccc ddd
routes_6rd="::/0 via ::61.211.224.125 dev 6rd"
mtu_6rd="1280"
postup() {
@prisoner
prisoner / consistent_hashr.rb
Created July 28, 2011 18:05
A Consistent Hashing implementation for Ruby
require 'zlib'
module ConsistentHashr
@circle = {}
@number_of_replicas = 20
##
# Computes a key
def self.hash_key(key)
Zlib.crc32("#{key}")
@thekindofme
thekindofme / start_delayed_job.sh
Created November 27, 2011 15:04
Upstart conf file for starting up delayed job
#!/bin/bash
logger "Trying to start delayed_job"
date >> /home/deployer/scripts/log/start_delayed_job.txt
rvm_path=/home/deployer/.rvm
source "/home/deployer/.rvm/scripts/rvm"
cd /home/deployer/inoty
/usr/bin/env RAILS_ENV=production /home/deployer/.rvm/rubies/ruby-1.9.2-p0/bin/ruby /home/deployer/inoty/script/delayed_job restart &>> /home/deployer/scripts/log/start_delayed_job.txt
@v1nc3ntlaw
v1nc3ntlaw / rbenv-install-system-wide.sh
Last active July 26, 2022 01:08
rbenv install ruby 1.9.3-p448 on Debian 6 Squeeze
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential git-core curl libssl-dev \
libreadline5 libreadline5-dev \
zlib1g zlib1g-dev \
libmysqlclient-dev \
libcurl4-openssl-dev \
libxslt-dev libxml2-dev