**code **:
1
git config --global core.excludesfile ~/.gitignore
**code **:
1
git config --global core.excludesfile ~/.gitignore
今天需要对用户表进行整理,把几十万Web用户从user表里面迁移出来放到另外一个表。
注意字段是相同的
1
insert into table column1, column2 select column1 column2 from table2 where query
在大多数主流的语言里,操作集合都是通过循环来进行的,每次抓取一个元素然后进行处理。在Ruby中,出现这样情况,不妨考虑使用闭包来替换循环操作。
在大多数常见情况下,有好集中有用的集合闭包方法,接下去,我来列出比较常见一种,刚开始时候可能会比较不习惯:
1
2
3
4
managers = []
employees.each do |e|
managers << e if e.manager?
end
好的,接下去,我们可以替换成一下这种方式:
1
managers = employees.select{|e| e.manager?}
reject 方式会逆置过滤器测试。在这两种情况下,除非你使用破坏性的形式(select! or reject!),否则它们不会修改原来的集合。
1
2
3
4
managerOffices = []
employees.each do |e|
managerOffices << e.office if e.manager?
end
换成这样方式:
1
managerOffices = employees.select{|e| e.manager?}.collect{|e| e.office}
1
openssl req -new -newkey rsa:2048 -nodes -keyout mykey.key -out csr.certSigningRequest
1
openssl x509 -in {cer.cer} -inform DER -out #{pem.pem} -outform PEM
1
openssl pkcs12 -export -inkey mykey.key -in #{pem.pem} -out #{dev_p12}
Mechanize (http://mechanize.rubyforge.org/GUIDE_rdoc.html#label-Getting+Started+With+Mechanize)
baidu search:
1
2
3
4
5
6
require "mechanize"
agent = Mechanize.new
page = agent.get("http://www.baidu.com")
result_page = page.form_with(name: "f") do |form|
form["wd"] = "ruby"
end.submit
login cms:
1
2
3
4
5
6
7
8
9
10
11
12
agent = Mechanize.new
page = agent.get("http://cms.stage.lanshizi.com/admin/login")
login_form = page.form_with(action: "/admin/login") do |form|
form["admin_user[username]"] = "sa"
form["admin_user[password]"] = "sa"
end
cms_page = login_form.submit
if message = cms_page.at(".flash_alert")
p message.text
else
p cms_page
end
captcha 破解
code:
1
2
3
4
5
6
7
@agent.get(@captcha_url).save("captcha.jpg")
@app_list_page = @agent.get(@login_url).form_with(id: "loginForm") do |f|
f.action = "/accounts/signin/"
f["username"] = @username
f["password"] = @password
f["captcha"] = RTesseract.new("captcha.jpg").to_s.strip
end.click_button