- 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
- 函式如果只有一個參數,就不強制打()
- 函式如果有二個以上的參數,通通都要有 ()
- (避免發生奇怪的paser bug跟保持專案一致性)
- 字串限定用雙引號包覆
- 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#从纯真IP数据库里查询 | |
def search_ip_cz(ip) | |
#IP数据文件路径 | |
#ip='202.38.64.10' | |
dat_path = "QQWry.Dat" | |
#检查IP地址 | |
# if not ip~=/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/ | |
# return 'IP Address Error' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "thor/shell" | |
say("Modifying a new Rails app ...", :yellow) | |
#---------------------------------------------------------------------------- | |
# Configure | |
#---------------------------------------------------------------------------- | |
=begin | |
unless options[:database] == 'sqlite3' | |
username = ask("What's your database username[root]") | |
username = 'root' if username.blank? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
var focus = true; | |
var count = 0; | |
var title = document.title; | |
$(window).focus(function(){ | |
focus = true; | |
count = 0; | |
setTimeout(function(){ | |
document.title = title; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tip(msg); puts; puts msg; puts "-"*100; end | |
# | |
# 30 Ruby 1.9 Tips, Tricks & Features: | |
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/ | |
# | |
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2" | |
tip "Ruby 1.9 supports named captures in regular expressions!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sphinx: &using | |
address: sphinx-server-host-ip | |
bin_path: /usr/local/bin | |
searchd_binary_name: searchd | |
indexer_binary_name: indexer | |
enable_star: 1 | |
min_prefix_len: 3 | |
prefix_fields: name | |
mem_limit: 1024M | |
morphology: 'none' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Coreseek (Sphinx) for MySQL 数据源 安装教程 | |
1. 下载源代码 | |
$ wget http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.13.tar.gz | |
$ tar xzf coreseek-3.2.13.tar.gz | |
$ cd coreseek-3.2.13 | |
2. 中文测试环境检查: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin` | |
# Be sure to have rails and thin installed. | |
require "rubygems" | |
require "rails" | |
# Let's load only action controller. If you want | |
# to use active record, just require it as well. | |
require "action_controller/railtie" | |
class MyApp < Rails::Application |
This script installs a patched version of ruby 1.9.3-p0 with patches to make ruby-debug work again (#47) and boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84).
Huge thanks to funny-falcon for the performance patches.
With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)
Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
Processing by HomeController#index as HTML
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
CACHE (0.0ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
Rendered layouts/_nav.html.erb (363.4ms)
OlderNewer