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
validate :start_date_validate | |
def start_date_validate | |
if start_date && end_date | |
if start_date >= end_date | |
errors.add("", I18n.t("education_information.start_end_not_validate")) | |
end | |
end | |
end |
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 "active_record" | |
ActiveRecord::Base.establish_connection( | |
:adapter => "postgresql", | |
:host => "localhost", | |
:username => "map", | |
:password => "map", | |
:database => "lspf" | |
) |
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
agent = Mechanize.new | |
page = agent.get('http://....../login') | |
form = page.forms[0] | |
form["user_session[login]"] = "......" | |
form["user_session[password]"] = "......" | |
form.submit | |
#puts page.uri | |
page = agent.get('http://...../synchrons') | |
#puts page.uri | |
#puts page |
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 fetch_gps | |
$client ||= Savon.client("http://...ip.../GPSInfo/Service.asmx?WSDL") | |
data_hash, data_qty = {}, 0 | |
@equipments.each do |equ_no| | |
begin | |
response = $client.request "getGPSInfoByID" do | |
$client.http.headers["Content-Type"] = "text/xml; charset=utf-8" | |
$client.http.headers["SOAPAction"] = "http://tempuri.org/getGPSInfoByID" | |
soap.body = {:id => equ_no} |
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 dis e1, e2 | |
if (e1 == "A" and e2 == "E") || (e1 == "E" and e2 == "B") || (e1 == "B" and e2 == "F") | |
return 5 | |
end | |
10 | |
end | |
@boxes = [] |
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
<style type="text/css"> | |
td { | |
border: 1px solid #ccc; | |
height: 24px; | |
padding: 2px; | |
vertical-align: top; | |
} | |
.ie9-bug-tr td { | |
height: 0px; |
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
pid = fork { `nohup ruby GpsReader.rb 1 &` } | |
# 这种写法能得到一个子进程的PID,但不是shell命令所运行进程的PID,若shell命令启动一个服务(一直运行),那么此子进程也不会死掉(与block是个while true,子进程便不会死掉一样) | |
pid = fork { exec "`nohup ruby GpsReader.rb 1 &`" } | |
# 这种写法能得到一个子进程的PID,同样不是shell命令进程的PID,子进程马上就结束了(ps S -C ruby或ps S -p your_PID),是exec方法在起作用(Replaces the current process by running the given external _command_),所以,在ruby代码运行一个shell命令时,使用exec要比直接`少一个进程 | |
Process.detach(pid) | |
puts pid | |
while true | |
puts "i am father..." | |
sleep 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
# 给关联关系赋值,发生了什么? | |
@sme = Sme.find(params[:id]) | |
@sme.sme_inspections = @sme.build_inspections params[:inspections] | |
# @sme.sme_inspections的class是个array,@sme.build_inspections params[:inspections] 只不过构造了一个sme_inspection的数组,并且数组中sme_inspection的sme_id为空 | |
# 但接下来发生了这些 | |
#SmeInspection Load (0.7ms) SELECT "sme_inspections".* FROM "sme_inspections" WHERE "sme_inspections"."sme_id" = 29 |
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
#encoding: utf-8 | |
require "nokogiri" | |
require "open-uri" | |
domain = 'http://sample.com&page=' | |
begin | |
1.upto 1000 do |i| | |
html = open(domain + i.to_s, :proxy => "http://127.0.0.1:8087", :read_timeout => 1).read | |
html.force_encoding("gbk") |
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
#!/usr/bin/ruby | |
require 'rss' | |
p 'Downloading rss index' | |
rss_string = open('http://feeds.feedburner.com/railscasts').read | |
rss = RSS::Parser.parse(rss_string, false) | |
videos_urls = rss.items.map { |it| it.enclosure.url }.reverse | |
videos_filenames = videos_urls.map {|url| url.split('/').last } |