Skip to content

Instantly share code, notes, and snippets.

View huobazi's full-sized avatar
🎯
Focusing

Marble Wu huobazi

🎯
Focusing
View GitHub Profile
@romannurik
romannurik / background-page.html
Created September 24, 2009 05:15
A workaround for Cross-domain XHR's not working in Chrome Extensions' content scripts. See http://groups.google.com/group/chromium-extensions/browse_thread/thread/43ec4d383cf8d01d
<!DOCTYPE html>
<html>
<head>
<script src="xhrproxy.js"></script>
<script>
setupXHRProxy();
</script>
</head>
var assembly = Assembly.GetCallingAssembly();
var actionMethods = assembly.GetTypes()
// Find all non abstract classes of type Controller and whose names end with "Controller"
.Where(x => x.IsClass && !x.IsAbstract && x.IsSubclassOf(typeof(TwilioController)) && x.Name.EndsWith("Controller"))
// Find all public methods from those controller classes
.SelectMany(x => x.GetMethods().Where(m => m.DeclaringType.Name == x.Name), (x, y) => new { Controller = x.Name.Substring(0, x.Name.Length - 10), Method = y.Name });
foreach (var action in actionMethods) {
routes.MapRoute(action.Method, action.Method, new { controller = action.Controller, action = action.Method });
}
@napcs
napcs / README.md
Created May 6, 2011 04:10
Deploying Rails to Linode

Deploying Rails to Linode

Installing Ruby Enterprise Edition, Apache, MySQL, and Passenger for deploying Rails 3.0 applications.

Get a Linode, and set it up with Ubuntu 10.04 LTS so that you have till April 2013 to get updates. Once the Linode is formatted, boot it and continue on.

Set up an 'A' record in your DNS, pointing to the IP of your Linode. I'm using demo.napcs.com here.

Initial setup

推荐几个个人必看的:
1. http://perfectionkills.com/
2. http://davidwalsh.name/
3. http://ejohn.org/
4. http://www.nczonline.net/
他们分别是 prototype, mootools, jquery, yui 的团队核心成员,文章质量都很高,并且比较活跃。
@huobazi
huobazi / gist:997385
Created May 29, 2011 01:45
NERDTree Keys
111 o.......在已有窗口中打开文件、目录或书签,并跳到该窗口 .....|NERDTree-o|
112 go......在已有窗口中打开文件、目录或书签,但不跳到该窗口 .....|NERDTree-go|
113 t.......在新Tab中打开选中文件/书签,并跳到新Tab .....|NERDTree-t|
114 T.......在新Tab中打开选中文件/书签,但不跳到新Tab .....|NERDTree-T|
115 i.......split一个新窗口打开选中文件,并跳到该窗口 .....|NERDTree-i|
116 gi......split一个新窗口打开选中文件,但不跳到该窗口 .....|NERDTree-gi|
117 s.......vsp一个新窗口打开选中文件,并跳到该窗口 .....|NERDTree-s|
118 gs......vsp一个新窗口打开选中文件,但不跳到该窗口 .....|NERDTree-gs|
119 !.......执行当前文件 .....|NERDTree-!|
120 O.......递归打开选中结点下的所有目录 .....|NERDTree-O|
@huobazi
huobazi / ubuntu-setup.sh
Created May 29, 2011 05:15 — forked from addamh/ubuntu-setup.sh
NORMES Ubuntu Development System Bootstrap Script
#!/bin/bash
echo "Updating Packages..."
apt-get -qq -y update
echo "Installing Vim..."
apt-get -qq -y install vim-gnome
echo "Installing Utilities..."
apt-get -qq -y install curl bison build-essential zlib1g-dev libssl-dev libreadline5-dev libxml2-dev
@chrisbloom7
chrisbloom7 / README.md
Created June 6, 2011 07:16
A cheap knock off of the default validates_length_of validator, but checks the filesize of a Carrierwave attachment

Note that this validation runs both after the file is uploaded and after CarrierWave has processed the image. If your base uploader includes a filter to resize the image then the validation will be run against the resized image, not the original one that was uploaded. If this causes a problem for you, then you should avoid using a resizing filter on the base uploader and put any specific size requirements in a version instead.

So instead of this:

require 'carrierwave/processing/mini_magick'

@huobazi
huobazi / init_d_nginx
Created June 15, 2011 06:26
Nginx initialization script. Place in /etc/init.d/nginx
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@andyvanee
andyvanee / Rakefile
Created September 21, 2011 16:19
Rake migrate without rails
require 'active_record'
require 'yaml'
require 'mysql'
require 'logger'
task :default => :migrate
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
task :migrate => :environment do
ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else