2009年7月24日 星期五

ruby benchmark

Benchmarking Makes it Better

2009年7月19日 星期日

X-Sendfile

mod_xsendfile
Reference : Advanced Rails p121

The X-Sendfile protocol is a very simple standard, first introduced in the Lighttpd
web server, which directs the web server to send a file from the filesystem to the client
rather than a response generated by the application server.

X-Sendfile uses the X-Sendfile HTTPheader pointing to the server’s path to the file
to send, in conjunction with the other standard HTTPheaders. A typical response
using X-Sendfile would look something like this:


From Rails, you can set the response headers by modifying the response.headers
hash:

2009年7月18日 星期六

delegate

Rails delegate method


那個 :to => :user 其實是由customer object 再去找 user 的 instance method
所以其實可以在 overwirte 掉做其他的處理

2009年7月16日 星期四

Metric Fu

Metric Fu railscast
ASCIIcast Metric Fu
About metric_fu 1.1.4
flog_file error
test_helper error

apache 設定

一些apache 設定 Etags and expire gzip compression
Speed up your Apache/Passenger Rails app in 2min

capistrano, fast_remote_cache

fast_remote_cache

37signals 用hard link 取代 copy 的方式

因為有需要一直用新的branch 更新, cache_copy 有需要一直變換其svn repository

所以需要overwrite 一下 fast_remote_cache 的一些 methods

ssh 免打密碼自動登入 memo

from here
在 自己電腦 Client 端


server 端

2009年7月15日 星期三

capistrano 指令順序

Understanding_Deployment_Strategies, deploy_via

Understanding Deployment Strategies

Deployment strategies are just ways for capistrano to get your code onto your target servers, ready to rock and roll

Deploy Strategy :checkout 就是checkout 新的

Deploy Strategy :copy 有時候 你的target server 可能因為被防火牆擋了 就是拿不到svn, 就只好用這個, 把本地的東西copy 過去


Deploy Strategy :export 就是用export 拿code, 用export 拿code 不會有svn control


Deploy Strategy :remote_cache, 把code 弄在cache copy 底下, 然後對其做svn update, 然後再把該份code 弄到新的release 去

capistrano deploy.rb 設定 註解

Capistrano deploy.rb文件的記錄

2009年7月10日 星期五

content_tag_for, div_for

content_tag_for, div_for

action cache, cahce_path, to_proc

Action Caching
Symbol#to_proc


ActionController::Caching::Actions


Action caching 內部是用 fragment caching 和 around filter 來實做
Action caching internally uses the fragment caching and an around filter to do the job. The fragment cache is named according to both the current host and the path. So a page that is accessed at http://david.somewhere.com/lists/show/1 will result in a fragment named "david.somewhere.com/lists/show/1". This allows the cacher to differentiate between "david.somewhere.com/lists/" and "jamis.somewhere.com/lists/" — which is a helpful way of assisting the subdomain-as-account-key pattern.

不同的url 就是不同的request, cache 也是不同的
Different representations of the same resource, e.g. http://david.somewhere.com/lists and http://david.somewhere.com/lists.xml are treated like separate requests and so are cached separately. Keep in mind when expiring an action cache that :action => 'lists' is not the same as :action => 'list', :format => :xml.

可以讓你自己控制cache_path, 就算是相同的request 也可以利用block 做些判斷生出不同的path, 當你用了block 你可以利用他拿到 controller instance
You can set modify the default action cache path by passing a :cache_path option. This will be passed directly to ActionCachePath.path_for. This is handy for actions with multiple possible routes that should be cached differently. If a block is given, it is called with the current controller instance.

也有 if, unless 來讓你丟block 進去做判斷
And you can also use :if (or :unless) to pass a Proc that specifies when the action should be cached.

如果你把layout 設成false, 你可以只存content, 你可以利用這樣來動態改變layout
If you pass :layout => false, it will only cache your action content. It is useful when your layout has dynamic information.

2009年7月9日 星期四

Apache , virtualhost

Host websites on your local machine using Apache websever
VirtualHost Examples


ServerName indicates the name (or alias) with which your site has to be recognised. Usually a webserver will be hosting multiple sites with different domain names on the same machine. At such times, the webserver distinguishes between different websites through the ServerName directive.
you will be giving it your domain name say like www.mysite.com or something.

The DocumentRoot option denotes which files to be served when the server name is entered in the web browser. This usually points to the place where you have stored your website files.

2009年7月3日 星期五

javascript encode, decode AND JSON in JavaScript

JSON in JavaScript
encode,decode,escape,unescape
encodeURI
decodeURI
encodeURIComponent
decodeURIComponent