Skip to content

Instantly share code, notes, and snippets.

schema = File.read('/home/jinzhu/GIT/joblet/db/schema.rb')
schema.scan(/(^\s*create_table.*?)(?=\n\s*create_table)/m).map do |x|
content = x[0]
content =~ /create_table\s+"(.*?)"/
filename = Time.now.utc.strftime("%Y%m%d%H%M%S") + '_create_' + $1 + '.rb'
filename = File.join('/home/jinzhu/GIT/joblet/db/migrate',filename)
content = "class Create" + $1.capitalize.gsub(/_(\w)/) { $1.to_s.upcase } + " < ActiveRecord::Migration\n def self.up\n" + content.sub(/\A\s*\n/,'') + "\n end\n\n def self.down\n end\nend"
@jinzhu
jinzhu / _README.md
Created November 23, 2009 03:05 — forked from kneath/_README.md

GitHub Javascript Strategy

Unless otherwise necessary (such as mobile development), the GitHub javascript codebase is based off jQuery. You can safely assume it will be included on every page.

File naming

  • All jquery plugins should be prefixed with jquery, such as jquery.facebox
  • All github-specific jquery plugins should be prefixed with jquery.github. Like jquery.github.repo_list.js
  • All page-specific files (that only run on ONE page) should be prefixed with page. page.billing.js
# See also http://github.com/simonjefford/rack_firebug_logger
# for this middleware + tests + a rails plugin
class FirebugLogger
def initialize(app, options = {})
@app = app
@options = options
end
def call(env)
dup._call(env)
require 'geoip'
module Rack
# Rack::GeoIPCountry uses the geoip gem and the GeoIP database to lookup the country of a request by its IP address
# The database can be downloaded from:
# http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
#
# Usage:
# use Rack::GeoIPCountry, :db => "path/to/GeoIP.dat"
#
keyBindings = (function(){
var keyId = {
"U+0008" : "BackSpace",
"U+0009" : "Tab",
"U+0018" : "Cancel",
"U+001B" : "Esc",
"U+0020" : "Space",
"U+0021" : "!",
"U+0022" : "\"",
"U+0023" : "#",
@jinzhu
jinzhu / ArchLinux VPN
Created March 27, 2011 07:12
a script to quick setup vpn server in archlinux
#!/bin/bash
# [email protected]
# thanks sushiyant ([email protected])
pacman -S iptables pptpd
echo "iptables -A INPUT -i ppp+ -j ACCEPT" >> /etc/rc.local
echo "iptables -A OUTPUT -o ppp+ -j ACCEPT" >> /etc/rc.local
echo "iptables -A INPUT -p tcp --dport 1723 -j ACCEPT" >> /etc/rc.local
echo "iptables -A INPUT -p 47 -j ACCEPT" >> /etc/rc.local
while true
do
sleep 0.5
if [ -f /dev/sdj ]; then
echo `date` > SdjMountedAt
sudo mount /dev/sdj /mnt/DATA
sudo /etc/init.d/httpd start
sudo /etc/init.d/mysqld start
cd /mnt/DATA/mysql-server-tritonn; sudo ./bin/mysqld_safe &
sudo su postgres -c '/usr/local/pgsql/bin/pg_ctl -D /mnt/DATA/pgsql -l /mnt/DATA/pgsql/log start'
@jinzhu
jinzhu / gist:956813
Created May 5, 2011 09:53
gzip script (used for nginx)
#!/bin/sh
cp $1 $1.tmp
## Remove the old gz if there is one
rm -rf $1.gz
## Compress the tmp HTML copy. Use the highest level 9
## compression and do not store dates or file names
## in the gzip header. BTW, if the compressed gz is
## larger then the original file a gzip will NOT be made.
#Tasks have been added to fully maintain nginx, unicorn, redis, memcached, start resque workers and run any command on any server in the farm.
#<pre>
#cap nginx:restart # Restart Nginx.
#cap nginx:start # Start Nginx.
#cap nginx:status # Status of Nginx.
#cap nginx:stop # Stop Nginx.
#cap nginx:tail_error # Tail the Nginx error logs.
#cap unicorn:reload # reload your unicorn servers.
#cap unicorn:restart # restart your unicorn servers.
#cap unicorn:start # start your unicorn servers.
@jinzhu
jinzhu / gist:1381658
Created November 21, 2011 04:49
Ruby Mail for ISO-2022-JP / SHIFT_JIS
require 'rubygems'
gem 'mail', '=2.2.19'
require 'mail'
require 'nkf'
module Mail
module Encodings
class SevenBit
def self.decode(str)