Skip to content

Instantly share code, notes, and snippets.

View jay16's full-sized avatar

俊杰.li jay16

View GitHub Profile

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@jay16
jay16 / Preferences.sublime-setttings
Last active August 29, 2015 13:57
SublimeText2 [Preferences -> Settings-User]
// Settings in here override those in "Default/Preferences.sublime-settings", and
// are overridden in turn by file type specific settings.
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"font_face": "Monaco",
"font_size": 14,
// Valid options are "no_bold", "no_italic", "no_antialias", "gray_antialias",
// "subpixel_antialias" and "no_round" (OS X only)
// 字体选项:no_bold 不显示粗体字,no_italic 不显示斜体字,no_antialias 和 no_antialias 关闭反锯齿
// subpixel_antialias 和 no_round 是 OS X 系统独有的
Alt + F11 进入宏编辑界面
========================================
' 当前宏对excel的操作与excel的事件冲突时
Application.EnableEvents = False
' Your Code'
Application.EnableEvents = True
=========================================
' 禁止删除行
Application.CommandBars("Cell").Controls(6).Enabled = False
@jay16
jay16 / lisp.rb
Created April 10, 2014 13:12 — forked from dahlia/lisp.rb
# 30 minutes Lisp in Ruby
# Hong Minhee <http://dahlia.kr/>
#
# This Lisp implementation does not provide a s-expression reader.
# Instead, it uses Ruby syntax like following code:
#
# [:def, :factorial,
# [:lambda, [:n],
# [:if, [:"=", :n, 1],
# 1,
source/_includes/custom/head.html中添加js代码:
<script>
function addBlankTargetForLinks () {
$('a[href^="http"]').each(function(){
$(this).attr('target', '_blank');
});
}
$(document).bind('DOMNodeInserted', function(event) {
[root@solife tools]# ruby method_missing.rb
method missing stack called..
define_method: title
"title"
"title"
no mater what you do, i say: hello
[root@solife tools]# cat method_missing.rb
class A
def method_missing(method_id, *args)
puts "method missing stack called.."
assert(boolean, message="") # 若boolean为真则pass
assert_equal(expected, actual, message=nil)#若expected == actual则pass
assert_not_equal(expected, actual, message="")#若expected != actual则pass
assert_instance_of(klass, object, message="")#若klass == object.class为真则pass
assert_nil(object, message="")#若object.nil?则pass
assert_not_nil(object, message="")#若!object.nil?则pass
assert_kind_of(klass, object, message="")#若object.kind_of?(klass)为真则pass
assert_respond_to(object, method, message="")#若object.respond_to?(method)为真则pass
assert_match(pattern, string, message="")#若string =~ pattern为真则pass
assert_no_match(regexp, string, message="")#若regexp !~ string为真则pass
备份:
备份整个数据库
exp 用户名/密码@连接的远程计算机 IP/ 要备份的远程数据库名称 file= 文件路径
exp hom/my_pwd@192.168.5.14/qa file=d:\aa1.dmp
备份指定数据库表
exp Intfocus/my_pwd@192.168.0.200/orcl file=d:\DOG_TOTAL_BI.DMP tables=(dog_totle_bi)
导入指定数据库表(若表结构已经存在只导入数据)
#encoding
task :default => [:base]
#eg: rake lookup[400]
desc "lookup http status explian info with status_code"
task :lookup, [:status_code] => :base do |t, args|
args.with_defaults(:status_code => "200")
status_code = args[:status_code].to_s
Rake::Task["usage"].invoke and exit unless status_code.length != 3 or (1..5).to_a.include?(status_code[0].to_i)