網頁

顯示具有 Ruby on Rails 標籤的文章。 顯示所有文章
顯示具有 Ruby on Rails 標籤的文章。 顯示所有文章

2016年7月14日 星期四

Test transaction page performance

Usually we test web page performance. Maybe test 1000 with 5 concorrent.
If we test a transaction page performance. Will left many ugly transaction data.
So we can desgin a dryrun mode. below is ruby on rails sample.


  class PurchasesController < ApplicationController
    def create

      ActiveRecord::Base.transaction do
        # This do purchase
        raise ActiveRecord::Rollback if params[:dryrun] # when dryrun then rollback.
      end

    end
  end

2015年5月4日 星期一

ffmpeg create thumbnail from local or remote video. with Ruby on Rails example.

ffmpeg create thumbnail from local or remote video.
Important point is -ss is before input file. If you place after input file And remote video. create thumbnail will very slow.

local video

$ ffmpeg -ss 5.3 -i "/home/ubuntu/video.mpg" -vframes 1 -f image2 "/home/ubuntu/thumbnail.jpg"

remote video

$ ffmpeg -ss 5.3 -i "http://example.com/video.mpg" -vframes 1 -f image2 "/home/ubuntu/thumbnail.jpg"

Ruby on Rails example

hr = %x[ffmpeg -loglevel error -ss #{m[:time_of]} -i \"#{input_file}\" -y -vframes 1 -vf scale='min(#{size}\\, iw):-1' -f image2 \"#{output_file}\" 2>&1]
  • -loglevel error: when error show message.
  • -ss: time offset. need before input file
  • -i: input file
  • -y: force overwrite output file
  • -vframe: Set the number of video frames to output. This is an alias for -frames:v
  • -vf scale='min(#{size}\\, iw):-1': set thumbnail output size.
  • -f image2: For extracting images from a video
  • "output_file": thumbnail output file
  • 2>&1: return error message

2011年1月15日 星期六

Passenger-top 0.3 released

passenger-top is like unix top command for passenger.

Ruby on Rails passenger has passenger-status can view instance status. but I wanted it similar to top command, so I created this project.

Download
checkout or download “passenger-top.rb“

How to use?

2010年3月26日 星期五

Ruby on Rails case when on View

竟然無法正常的parase case when syntax語法,必需寫成以下的樣子...
(測試的Rails版本為2.3.4)
<% case 1
when 1
%>...1 <%
when 2
%>...2 <%
when 3
%>...3 <%
end %>

2009年3月7日 星期六

HTML原始檔中js及css後面加了"?數字"是什麼用途?

在Ruby on Rails產生的網頁原始碼中總看到assets的後面會多一段數字,像是:
<script src="/javascripts/cache/bundle.js?1236331223" type="text/javascript"></script>
現在才知道這是為了讓確保使用者能夠拿到最新的javascript或css檔案。

看到一個Plugins - Asset timestamping,會把最後修改的timestamp加到URL中,但是plugin的comment中就有人回應「Looks like assets are timestamped in Rails automatically now (v 1.1+)」,可能這是很舊的plugin了吧!

做了測試用Live HTTP Headers去看:
1.先隨便試一個js檔,如:http://wadevelop.blogspot.com/xxx.js?12345
Cotent-Length:9999
2.再開新的tab,一樣連到http://wadevelop.blogspot.com/xxx.js?12345
Cotent-Length:0
3.然後換連到http://wadevelop.blogspot.com/xxx.js?abcde
Cotent-Length:9999
證明了?後面更新timestamp,使用者就不會使用cache,而會重新載入js或css檔案。

2008年12月24日 星期三

ROR Production mode改code不想restart,code寫在view中

Ruby on Rails在Production的模式中,有時偷懶不想在controller中寫action,因為controller中的修改需restart server, view則不需要,打算把code寫在view裏面,然後呼叫/controller/action,結果一點反應也沒有。

要記住!!剛新增的view還是要先restart server一次,server才會知道有view的action可以呼叫,之後修改code就比較方便做測試。