Skip to content

Instantly share code, notes, and snippets.

@jinzhu
jinzhu / github.rb
Created March 19, 2012 06:50
Get hot vim scripts
require 'rubygems'
require 'rest_client'
require 'json'
watcher_threshold = 50
user = "vim-scripts"
results = []
url = "http://github.com/api/v2/json/repos/search/vim"
# url = "http://github.com/api/v2/json/repos/show/#{user}"
@jinzhu
jinzhu / 0001-support-pass-variables-from-routes-to-handler.patch
Created February 26, 2012 15:42
[PATCH form Gorilla] support pass variables from routes to handler
From a948c13b7073af9a0af4e3615cf4a245056a42f2 Mon Sep 17 00:00:00 2001
From: Jinzhu <wosmvp@gmail.com>
Date: Sun, 26 Feb 2012 23:34:58 +0800
Subject: [PATCH] support pass variables from routes to handler
---
route.go | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/route.go b/route.go
@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)
#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: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.
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 / ArchLinux VPN
Created March 27, 2011 07:12
a script to quick setup vpn server in archlinux
#!/bin/bash
# wosmvp@gmail.com
# thanks sushiyant (me@sushiyant.org)
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
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" : "#",
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"
#
# 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)