Skip to content

Instantly share code, notes, and snippets.

View liwh's full-sized avatar
🎯
Focusing

robie lee liwh

🎯
Focusing
View GitHub Profile
gem cleanup 用来清除旧版本的 gem
@liwh
liwh / gist:730067
Created December 6, 2010 09:36
form内只有一个输入框时,按回车会自动提交
http://blog.csdn.net/lu7kang/archive/2010/01/26/5258054.aspx
@liwh
liwh / gist:730007
Created December 6, 2010 08:09
the Authenticity Token in rails

在rails中,当我们请求页面的时候,rails会生成一个随机的authenticity_token保存在session中,当我们向服务器发出post ,put ,delete请求的时候,它就会验证session中存储的值,如果匹配,则继续流程。
这主要是为了防止Cross Site Request Forgery攻击。阻止用户进行非表单提交的操作。。具体见:rails-authenticity-token

cat log/test_oracle.log |grep "200 OK" | awk '{print $11}'|sort|uniq -c | sort -n -r
@liwh
liwh / gist:725492
Created December 2, 2010 15:07
install mongodb

ApplematoMacBook-Pro:~ Apple$ sudo brew install mongodb
Warning: It appears you have MacPorts or Fink installed.
Software installed with MacPorts and Fink are known to cause problems.
If you experience issues try uninstalling these tools.
==> Downloading http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-1.6.4.tgz

  1. 100.0%
    ==> Caveats
    If this is your first install, automatically load on login with:
    cp /usr/local/Cellar/mongodb/1.6.4-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents
    launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
@liwh
liwh / gist:724883
Created December 2, 2010 06:25
处理rails 的错误页面
我们可以通过重载rails 的rescue_action_in_public 方面,自定义,我们的异常处理,它默认情况会调用
render_optional_error_file去渲染400,500页面。
#重构:实现为类动态增加方法
module A
def self.included(target)
target.extent(ClassMethods)
end
module ClassMethods
def ..
end
end
@liwh
liwh / gist:721701
Created November 30, 2010 13:49
intall the shopqi project on mac os x
  • 首先安装rvm,这个和在linux上安装是一致的,安装完成之后,将 if [[ -s /Users/Apple/.rvm/scripts/rvm ]] ; then source /Users/Apple/.rvm/scripts/rvm ; fi 放在~/.bash_profile中。
  • rvm 1.9.2 —default
  • 参见前面安装rails 3
  • bundle install (在项目目录下执行,注意将Gemfile文件里的rb-inotify这个gem注释调,因为它还不支持os x平台)
  • 安装homebrew,具体步骤见:安装homebrew ,homebrew安装东西比macport要快很多。
  • sudo brew install ImageMagick
  • sudo brew install mongodb (具体步骤见:安装mongodb )
@liwh
liwh / gist:711422
Created November 23, 2010 07:48
定义抽象类,实现代码重构
# app/models/abstract_server.rb
class AbstractServer < ActiveRecord::Base
self.abstract_class = true
validates_presence_of :name, :address, :username, :password, :encoding
validates_length_of :name, :maximum => 20, :allow_blank => true
validates_length_of :address, :maximum => 20, :allow_blank => true
validates_length_of :username, :password, :maximum => 20, :allow_blank => true
validates_length_of :encoding, :maximum => 10, :allow_blank => true

由于,觉得用textmate还是不大习惯,所以,还是决定把macvim安装上,首先,在安装之前,我们现查看一下vim包的variants。


ApplematoMacBook-Pro:~ Apple$ port variants vim
vim has the variants:
athena: Build GUI version using Athena widgets

  • conflicts with gtk1 gtk2 motif
  • requires x11
    big: Build big feature set
  • conflicts with small tiny
    cscope: Enable source code browsing with cscope