Skip to content

Instantly share code, notes, and snippets.

View liwh's full-sized avatar
🎯
Focusing

robie lee liwh

🎯
Focusing
View GitHub Profile
#重构:实现为类动态增加方法
module A
def self.included(target)
target.extent(ClassMethods)
end
module ClassMethods
def ..
end
end
@liwh
liwh / gist:724883
Created December 2, 2010 06:25
处理rails 的错误页面
我们可以通过重载rails 的rescue_action_in_public 方面,自定义,我们的异常处理,它默认情况会调用
render_optional_error_file去渲染400,500页面。
@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
cat log/test_oracle.log |grep "200 OK" | awk '{print $11}'|sort|uniq -c | sort -n -r
@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

@liwh
liwh / gist:730067
Created December 6, 2010 09:36
form内只有一个输入框时,按回车会自动提交
http://blog.csdn.net/lu7kang/archive/2010/01/26/5258054.aspx
gem cleanup 用来清除旧版本的 gem
@liwh
liwh / gist:734522
Created December 9, 2010 09:20
linux vim replace command
:6,35 s/s/S/g 替换6到35行
http://www.ibm.com/developerworks/cn/java/j-cb08016/
#!/bin/sh
d=`date +%Y-%m-%d`
echo $d
vim ./_posts/${d}-$1.textile