Skip to content

Instantly share code, notes, and snippets.

@Psli
Psli / Capistrano tasks for starting unicorn.rb
Created September 27, 2011 22:02 — forked from vvalgis/Capistrano tasks for starting unicorn.rb
Capistrano tasks for starting unicorn
set :rails_env, :production
set :unicorn_binary, "/usr/bin/unicorn"
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
@Psli
Psli / sphinx.yml
Created September 20, 2011 11:49 — forked from dchentech/sphinx.yml
sphinx in chinese setup
production:
listen: 0.0.0.0:9312
address: 0.0.0.0 # 对应的安装了searchd(sphinx)的mysql服务器ip
port: 9312 # 对应的安装了searchd(sphinx)的mysql服务器端口
bin_path: '/usr/local/bin'
searchd_file_path: '/data/sphinx/production'
query_log_file: '/data/sphinx/log/searchd.query.log'
searchd_log_file: '/data/sphinx/log/searchd.log'
exceptions: '/data/sphinx/log//exception.log'
enable_star: true # 支持通配符匹配
@Psli
Psli / position-fixed.css
Created August 6, 2011 19:54 — forked from subtleGradient/position-fixed.css
Make position:fixed work in IE6
/*Make position:fixed work in IE6!*/
.fixed-top /* position fixed Top */{position:fixed;bottom:auto;top:0px;}
.fixed-bottom /* position fixed Bottom */{position:fixed;bottom:0px;top:auto;}
.fixed-left /* position fixed Left */{position:fixed;right:auto;left:0px;}
.fixed-right /* position fixed right */{position:fixed;right:0px;left:auto;}
* html,* html body /* IE6 Fixed Position Jitter Fix */{background-image:url(about:blank);background-attachment:fixed;}
* html .fixed-top /* IE6 position fixed Top */{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop));}
* html .fixed-right /* IE6 position fixed right */{position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft+document.documentElement.clientWidth-this.offsetWidth)-(parseInt(this.currentStyle.marginLeft,10)||0)-(parseInt(this.currentStyle.marginRight,10)||0));}

(a gist based on the old toolmantim article on setting up remote repos)

To collaborate in a distributed development process you’ll need to push code to remotely accessible repositories.

This is somewhat of a follow-up to the previous article setting up a new rails app with git.

For the impatient

Set up the new bare repo on the server:

@Psli
Psli / routes.rb
Created July 10, 2011 16:44 — forked from pixeltrix/routes.rb
Examples of advanced Rails 3.0 routes
Rails.application.routes.draw do
get '/(:locale)/products/(:category)/(page/:page).:extension',
:to => 'products#index',
:as => :products,
:constraints => {
:locale => /[a-z]{2}/,
:category => /.+?/,
:page => /\d+/
},
@Psli
Psli / chinesedecimal.rb
Created July 6, 2011 21:40 — forked from xiaods/chinesedecimal.rb
convert RMB currency to chinese describe
$KCODE = 'u'
# Goal: 小写金额转换为大写金额
# Limit: 金额整数位支持到亿位,小数点后支持两位并且不支持四舍五入
class ChineseFee
attr_reader :chn_numbers, :chn_units, :chn_decimals
def initialize
@chn_numbers = %w(零 壹 贰 叁 肆 伍 陆 柒 捌 玖)
@chn_units = %w(元 拾 佰 仟 万 拾万 佰万 仟万 亿)
@Psli
Psli / gist:1063501
Created July 4, 2011 15:40
The Better Way To Do Random using Scope
# before
# from http://jan.kneschke.de/projects/mysql/order-by-rand
def self.pick
return Post.find_by_sql("SELECT * FROM posts as r1 JOIN (SELECT CEIL(RAND() * (SELECT MAX(id) FROM posts)) AS gid) AS r2 WHERE r1.id >= r2.gid and r1.status = ‘published’ ORDER BY r1.id ASC LIMIT 1;").first;
end
# after
# ex. Post.rand.published.limit(5)
@Psli
Psli / god.sh
Created June 12, 2011 14:09
/etc/init.d/god
#!/bin/bash
#
# God
#
# chkconfig: - 85 15
# description: start, stop, restart God
# sudo chmod a+x /etc/init.d/god
# sudo chkconfig --add god
# sudo chkconfig --level 345 god on
@Psli
Psli / redis.conf
Created May 30, 2011 12:24
redis.conf
# Redis configuration file example
# Note on units: when memory size is needed, it is possible to specifiy
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
@Psli
Psli / ip_util.rb
Created May 20, 2011 08:43
ip_util.rb
module IpUtil
# returns the highest IP address in a given network.
# netaddr and netmask must be integers, netmask is CIDR
def IpUtil.high_ip(netaddr, netmask)
netmask = netmask.to_i
netaddr + (2 ** netmask) -1
end
#returns numeric IP address given a dotted-octet IP string