王筝的博客
ruby学习
http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTP.html#method-i-head
head(path, initheader = nil)click to toggle source

Gets only the header from path on the connected-to host. header is a Hash like { ‘Accept’ => ‘/’, … }.

This method returns a Net::HTTPResponse object.

This method never raises an exception.

response = nil
Net::HTTP.start('some.www.server', 80) {|http|
  response = http.head('/index.html')
}
p response['content-type']

于是就有了这样的奇葩方法,欢迎拍砖
def self.get_the_package_size origin_url
 if origin_url.present?
 if origin_url.index(".com")
 array = origin_url.split(".com").reverse
 url_end = array[0]
 url_begin = array[1].split("//")[1]
 url_begin = "#{url_begin}.com"
 elsif origin_url.index(".net")
 array = origin_url.split(".net").reverse
 url_end = array[0]
 url_begin = array[1].split("//")[1]
 url_begin = "#{url_begin}.net"
 else
 return ""
 end 
 response = nil 
 Net::HTTP.start(url_begin, 80, "10.103.11.54", 81) {|http|
 response = http.head(url_end)
 } 
 return response['Content-Length']
 end 
 end 

其实还可以直接用命令看一下哦
curl -v -XHEAD http://dl.g.youku.com/20150317/1426557582_XXXX-20150312.apk






delayed_job_active_record

https://github.com/collectiveidea/delayed_job_active_record

Installation

(1)Add the gem to your Gemfile:

gem 'delayed_job_active_record'

Run bundle install.

(2)If you’re using Rails, run the generator to create the migration for the delayed_job table.

rails g delayed_job:active_record
bundle exec rake db:migrate

要是觉得不喜欢这个表名,可以在migrate修改表名。

(3)Running Jobs

script/delayed_job can be used to manage a background process which will start working off jobs.

To do so, add gem "daemons" to your Gemfile and make sure you’ve run rails generate delayed_job.

You can then do the following:

RAILS_ENV=production script/delayed_job start
RAILS_ENV=production script/delayed_job stop

# Runs two workers in separate processes.
RAILS_ENV=production script/delayed_job -n 2 start
RAILS_ENV=production script/delayed_job stop

# Set the --queue or --queues option to work from a particular queue.
RAILS_ENV=production script/delayed_job --queue=tracking start
RAILS_ENV=production script/delayed_job --queues=mailers,tasks start

# Use the --pool option to specify a worker pool. You can use this option multiple times to start different numbers of workers for different queues.
# The following command will start 1 worker for the tracking queue,
# 2 workers for the mailers and tasks queues, and 2 workers for any jobs:
RAILS_ENV=production script/delayed_job --pool=tracking --pool=mailers,tasks:2 --pool=*:2 start

# Runs all available jobs and then exits
RAILS_ENV=production script/delayed_job start --exit-on-complete
# or to run in the foreground
RAILS_ENV=production script/delayed_job run --exit-on-complete
(4)insert and delete
 def set_push_at
 @video.update_attributes(:will_push_at => params[:cibn_video_broadcast_list][:will_push_at],
 :push_user => current_user_name)
 @video.delay(:run_at => @video.will_push_at).
 send( method_to_perform(@video), {:user_name => current_user_name})
 redirect_to :back, :notice => '操作成功'
 end 

 def cancel_push_at
 @video.update_attributes(:will_push_at => nil)
 job = CibnPushDelayedJob.where('handler like ?' ,
 ["", "CibnVideoBroadcastList", "id: #{@video.id}", ""].join('%') ).last
 CibnPushDelayedJob.delete job.try(:id)
 redirect_to :back, :notice => '操作成功'

 

$ bundle exec rake db:migrate
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.

(See full trace by running task with –trace)

推荐下面的网址

https://github.com/joyent/node/wiki/installing-node.js-via-package-manager

$curl -sL https://rpm.nodesource.com/setup | bash –

$yum install -y nodejs

 

可以轻松解决post请求的调试问题

reload 方法,该方法强迫浏览器刷新当前页面。
语法:location.reload([bForceGet])
参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里取当前页。true, 则以 GET 方式,从服务端取最新的页面, 相当于客户端点击 F5(“刷新”)

96 @switch_state = (entity_class, entity_id, state_attribute_name) ->
97 $.ajax({
98 url: ‘<%= switch_state_commons_path %>’,
99 type: ‘put’,
100 data: {‘entity_class': entity_class, ‘entity_id': entity_id, ‘state_attribute_name': state_attribute_name}
101 }).done( ->
102 $().toastmessage(‘showSuccessToast’, ‘操作成功’);
103 location.reload();
104 )