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
@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}")
@tomykaira
tomykaira / markdown-to-hiki.rb
Created March 2, 2012 08:50
Convert markdown to hiki / markdown テキストから hiki 形式に変換するスクリプト(適当)
# -*- coding: utf-8 -*-
ARGV.each do |fn|
lines = File.readlines(fn)
hiki = lines.map { |l|
l.sub(/^(#+)\s/){ '!'*($1.length) + ' ' }.
sub(/^(-+)\s/){ '*'*($1.length) + ' ' }.
gsub(/\!\[([^\]]+)\]\(([^\)]+)\)/){ $2[0..3] == 'http' ? $2 : ('http://goos-lokka.heroku.com' + $2) }. # picture
gsub(/\[([^\]]+)\]\(([^\)]+)\)/, '[[\1|\2]]'). # url
gsub(/\*\*([^*]*)\*\*/, "'''\\1'''").
sub(/^ /, ' ').
@Vaysman
Vaysman / s.rb
Created April 11, 2012 07:33 — forked from jacksonwillis/s.rb
Sentences as Ruby code
class S; def initialize *w; @s=w; end; def method_missing *w;@s<<w;self;end;def
to_ary;[@s.map{ |e| e=~/[\,\.\:\-\(\)\/\'\"]/?[e]:[" ",e] }.join.strip];end;end
def Object.const_missing(c);S.new c;end; ###### https://gist.github.com/2354740
puts This.is.a.sentence.represented.by.a.Ruby.expression(",").try.it.out! #####
[ricky@t520 breakpoint]$ echo 'function foo() return "hi" end; print(foo())' | lua -i
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> function foo() return "hi" end; print(foo())
hi
>
@sowawa
sowawa / .recipe
Created April 28, 2012 03:45
Installing rails 4.0.0 beta
thumbnail: http://pds.exblog.jp/pds/1/201101/16/02/d0055302_13383029.jpg
video: http://www.youtube.com/watch?v=UE27t_LJpx0