2008年12月30日 星期二

ruby memo

ruby memo

2008年12月24日 星期三

rails default mode

一般如果只有用
bin/count_ad_render_num.rb 就是在 development mode
要在production 就要特別指定
bin/count_ad_render_num.rb -e production

rails default mode

一般如果只有用
bin/count_ad_render_num.rb 就是在 development mode
要在production 就要特別指定
bin/count_ad_render_num.rb -e production

2008年12月23日 星期二

deploy

設定dns

設定haproxy

# restart apache server
/etc/init.d/httpd restart

#apache log 在這
tail -f /var/log/httpd/error_log

#看ip
/sbin/ifconfig





deploy

設定dns

設定haproxy

# restart apache server
/etc/init.d/httpd restart

#apache log 在這
tail -f /var/log/httpd/error_log

#看ip
/sbin/ifconfig





2008年12月19日 星期五

Gem dependencies

Gem dependencies
What is new :Gem Dependencies
把application 需要的gem 可以直接寫在設定檔裡, 綁在app 上
不過我在2.2 想用, 卻爆了看起來應該是這個問題 Handle missing dependencies in gem loading

不過現在有點懶之後再用 orz

Gem dependencies

Gem dependencies
What is new :Gem Dependencies
把application 需要的gem 可以直接寫在設定檔裡, 綁在app 上
不過我在2.2 想用, 卻爆了看起來應該是這個問題 Handle missing dependencies in gem loading

不過現在有點懶之後再用 orz

liquid,dynamic content

railscast liquid
liquid
liquid wiki
如果想要動態去編輯網頁上的 content 傳些變數進去, 就是需要這個, 什麼意思勒
就是例如我是admin, 我想要編輯公告時, 傳些人名的參數進去, 可是不想要改 code, 想要直接改db的內容就好, 就可以用這個,

liquid,dynamic content

railscast liquid
liquid
liquid wiki
如果想要動態去編輯網頁上的 content 傳些變數進去, 就是需要這個, 什麼意思勒
就是例如我是admin, 我想要編輯公告時, 傳些人名的參數進去, 可是不想要改 code, 想要直接改db的內容就好, 就可以用這個,

All About Layouts

railscast All About Layouts
layout 幾個常用的用法

All About Layouts

railscast All About Layouts
layout 幾個常用的用法

2008年12月18日 星期四

rails 2.2 extra, delegate,gem

9.3. Delegates With Prefixes

還有一堆玩具
#

past?, today? and future? for Date and Time classes to facilitate date/time comparisons.
#

Array#second through Array#tenth as aliases for Array#[1] through Array#[9]
#

Enumerable#many? to encapsulate collection.size > 1
#

Inflector#parameterize produces a URL-ready version of its input, for use in to_param.
#

Time#advance recognizes fractional days and weeks, so you can do 1.7.weeks.ago, 1.5.hours.since, and so on.


10.1. config.gems

To avoid deployment issues and make Rails applications more self-contained, it's possible to place copies of all of the gems that your Rails application requires in /vendor/gems

*

config.gem gem_name in your config/environment.rb file
*

rake gems to list all configured gems, as well as whether they (and their dependencies) are installed or frozen
*

rake gems:install to install missing gems to the computer
*

rake gems:unpack to place a copy of the required gems into /vendor/gems
*

rake gems:unpack:dependencies to get copies of the required gems and their dependencies into /vendor/gems
*

rake gems:build to build any missing native extensions
*

rake gems:refresh_specs to bring vendored gems created with Rails 2.1 into alignment with the Rails 2.2 way of storing them

You can unpack or install a single gem by specifying GEM=gem_name

rails 2.2 extra, delegate,gem

9.3. Delegates With Prefixes

還有一堆玩具
#

past?, today? and future? for Date and Time classes to facilitate date/time comparisons.
#

Array#second through Array#tenth as aliases for Array#[1] through Array#[9]
#

Enumerable#many? to encapsulate collection.size > 1
#

Inflector#parameterize produces a URL-ready version of its input, for use in to_param.
#

Time#advance recognizes fractional days and weeks, so you can do 1.7.weeks.ago, 1.5.hours.since, and so on.


10.1. config.gems

To avoid deployment issues and make Rails applications more self-contained, it's possible to place copies of all of the gems that your Rails application requires in /vendor/gems

*

config.gem gem_name in your config/environment.rb file
*

rake gems to list all configured gems, as well as whether they (and their dependencies) are installed or frozen
*

rake gems:install to install missing gems to the computer
*

rake gems:unpack to place a copy of the required gems into /vendor/gems
*

rake gems:unpack:dependencies to get copies of the required gems and their dependencies into /vendor/gems
*

rake gems:build to build any missing native extensions
*

rake gems:refresh_specs to bring vendored gems created with Rails 2.1 into alignment with the Rails 2.2 way of storing them

You can unpack or install a single gem by specifying GEM=gem_name

each_with_object,inject

注意inject 和 each_with_object , hash 和 str 的參數位置是相反的,
而且inject 傳回去的是上次的結果, 所以要把那個 hsh 傳回去

each_with_object,inject

注意inject 和 each_with_object , hash 和 str 的參數位置是相反的,
而且inject 傳回去的是上次的結果, 所以要把那個 hsh 傳回去

header, redirect_to , render js, polymorphic_path

6.4. Other Action Controller Changes

HTTP Accept header 現在default 是 disable 啦, 想要打開要自己開
不然就是自己在生時後面要有type啦 像 url /customers/1.xml



redirect_to now fully supports URI schemes (so, for example, you can redirect to a svn+ssh: URI).



有js 參數可以用不用在自己設response.headers['Content-Type']='text/javascript'
render now supports a :js option to render plain vanilla javascript with the right mime type.



Polymorphic URLs behave more sensibly if a passed parameter is nil. For example, calling polymorphic_path([@project, @date, @area]) with a nil date will give you project_area_path

header, redirect_to , render js, polymorphic_path

6.4. Other Action Controller Changes

HTTP Accept header 現在default 是 disable 啦, 想要打開要自己開
不然就是自己在生時後面要有type啦 像 url /customers/1.xml



redirect_to now fully supports URI schemes (so, for example, you can redirect to a svn+ssh: URI).



有js 參數可以用不用在自己設response.headers['Content-Type']='text/javascript'
render now supports a :js option to render plain vanilla javascript with the right mime type.



Polymorphic URLs behave more sensibly if a passed parameter is nil. For example, calling polymorphic_path([@project, @date, @area]) with a nil date will give you project_area_path

Rescue from dispatching, layout mailer

Rescue from dispatching
人家這個sample 太好 不知道要講啥 XD

Mailer Layouts
default 他會找 layout 裡 加上 _mailer的, 像這邊就是會去找layouts/user_mailer.html.erb
當然也可以自己指定 layou

Rescue from dispatching, layout mailer

Rescue from dispatching
人家這個sample 太好 不知道要講啥 XD

Mailer Layouts
default 他會找 layout 裡 加上 _mailer的, 像這邊就是會去找layouts/user_mailer.html.erb
當然也可以自己指定 layou

Shallow Routes, Resources With Specific Actions

Shallow Routes

不過books_path 還是不能叫的

6.3 Resources With Specific Actions
現在你可以指定你想要生哪個 action 的 path, 要route哪些, 因為Rails 生這些東西也是要耗memory的, 而這些設定會被nested resource 繼承

Shallow Routes, Resources With Specific Actions

Shallow Routes

不過books_path 還是不能叫的

6.3 Resources With Specific Actions
現在你可以指定你想要生哪個 action 的 path, 要route哪些, 因為Rails 生這些東西也是要耗memory的, 而這些設定會被nested resource 繼承

etag,last_modified,Get

Even Better Conditional GET Support
rails 2.2 release note


至於 browser什麼時候會發etag, last_modified, 讓你看見 304勒
就是看browser啦, 如果是reload大部分就是不發 etag, last_modified 就是要你server一定要吐view了, 直接連才會, 而且post 是不發etag, last_modified的

應該吧...

etag,last_modified,Get

Even Better Conditional GET Support
rails 2.2 release note


至於 browser什麼時候會發etag, last_modified, 讓你看見 304勒
就是看browser啦, 如果是reload大部分就是不發 etag, last_modified 就是要你server一定要吐view了, 直接連才會, 而且post 是不發etag, last_modified的

應該吧...

rails, thread-safe

Q/A: What Thread-safe Rails Means
Thread safety for your Rails

rails, thread-safe

Q/A: What Thread-safe Rails Means
Thread safety for your Rails

alias_method_chain

alias_method_chain

alias_method A, B 有點就是 B 把function copy 一份到B

Encapsulates the common pattern of:
這就像是foo 沒改feature之前 copy 一份 所以叫做 foo_without_feature
然後弄了個function 叫做foo_with_feature 然後蓋掉 foo
之後叫foo 就是有feature的 foo_with_feature

With this, you simply do:
And both aliases are set up for you.

Query and bang methods (foo?, foo!) keep the same punctuation:
is equivalent to
so you can safely chain foo, foo?, and foo! with the same feature.

alias_method_chain

alias_method_chain

alias_method A, B 有點就是 B 把function copy 一份到B

Encapsulates the common pattern of:
這就像是foo 沒改feature之前 copy 一份 所以叫做 foo_without_feature
然後弄了個function 叫做foo_with_feature 然後蓋掉 foo
之後叫foo 就是有feature的 foo_with_feature

With this, you simply do:
And both aliases are set up for you.

Query and bang methods (foo?, foo!) keep the same punctuation:
is equivalent to
so you can safely chain foo, foo?, and foo! with the same feature.

2008年12月17日 星期三

rails2.2 extra, dynamic finder

Rails2.2 release note
railscast rails2.2 extra
javaeye rails 2.2 release note

5.4 New Dynamic Finders

rails2.2 extra, dynamic finder

Rails2.2 release note
railscast rails2.2 extra
javaeye rails 2.2 release note

5.4 New Dynamic Finders

join,include

mysql, 是沒有include 這種東西的
在rails 下join 如

rails 用join 就是用inner join 弄成一整個大的object, association 就沒了
用include 有的時候因為條件裡直接需要用到另個table 的條件, 是用left join 但仍維持 association 的關係


另外rails 2.2 可以把 join 寫的high 一點了
Easy Join Table Conditions

join,include

mysql, 是沒有include 這種東西的
在rails 下join 如

rails 用join 就是用inner join 弄成一整個大的object, association 就沒了
用include 有的時候因為條件裡直接需要用到另個table 的條件, 是用left join 但仍維持 association 的關係


另外rails 2.2 可以把 join 寫的high 一點了
Easy Join Table Conditions

sql,DATE,group by

想要計算某些column 每天的總數時, 可以用sql 的DATE
結果出來是 OrderedHash 所以要用
hash["2008-12-16"] 去取值, 當然hash 的相關method 也可以用

sql,DATE,group by

想要計算某些column 每天的總數時, 可以用sql 的DATE
結果出來是 OrderedHash 所以要用
hash["2008-12-16"] 去取值, 當然hash 的相關method 也可以用

Block in views, concat, capture, content_for,yield,content_tag

rails 2.2 block in view
block in view before

concat source code



其他學到的 concat, capture, yield,content_tag

concat
capture
yield, content_for
content_tag

Block in views, concat, capture, content_for,yield,content_tag

rails 2.2 block in view
block in view before

concat source code



其他學到的 concat, capture, yield,content_tag

concat
capture
yield, content_for
content_tag

2008年12月16日 星期二

memoizable,rails2.2

railscast memorizable
Easy Memoization
A Guide to Memoization

memoizable,rails2.2

railscast memorizable
Easy Memoization
A Guide to Memoization

overwrite attr_writer,=

overwrite attr_writer,=

rails I18n sample

railscast i18n
Rails 2.2.0 I18n 的使用筆記

一般的預設訊息可以到
http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale
下載

超簡單的步驟有
1. 把翻譯的那些yml檔放到, 想放的地方去, 教學都是放在 config/locales 下
2. 在application 做個 before_filter 設定

3. 重啟server, 讓他load 一下, 設定檔



model 本身和column name 也可以用這樣的方式去做i18n

rails I18n sample

railscast i18n
Rails 2.2.0 I18n 的使用筆記

一般的預設訊息可以到
http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale
下載

超簡單的步驟有
1. 把翻譯的那些yml檔放到, 想放的地方去, 教學都是放在 config/locales 下
2. 在application 做個 before_filter 設定

3. 重啟server, 讓他load 一下, 設定檔



model 本身和column name 也可以用這樣的方式去做i18n

2008年12月15日 星期一

rails execute sql

HowtoQueryTheDatabaseDirectly

rails execute sql

HowtoQueryTheDatabaseDirectly

jquery parse xml

jquery makes parsing xml easy

jquery parse xml

jquery makes parsing xml easy

google ajax library api

google ajax library api
some sample

google ajax library api

google ajax library api
some sample

2008年12月14日 星期日

using jquery in rails,jquery, rails,form,reset,escape,fn,plugin

jquery railscast
The jSkinny on jQuery
Myth #3: Rails forces you to use Prototype
jquery post


ajaxSetup

escape_javascript
form reset

jquery fn

using jquery in rails,jquery, rails,form,reset,escape,fn,plugin

jquery railscast
The jSkinny on jQuery
Myth #3: Rails forces you to use Prototype
jquery post


ajaxSetup

escape_javascript
form reset

jquery fn

2008年12月12日 星期五

swfobject,flash,swf

google code swfobject
Flash object attr
swfobject sample



update: 2009042
廣告追蹤常在用的clickTag 在flash7, 8 要換成clickTAG 才work

iconv,big5,utf8

iconv big5 to utf-8

using helpers in a controller

Using helpers in a controller: with_helpers
Rails: Using Helpers in Your Controller.

看不懂等級的mysql random

http://blog.gslin.org/archives/2008/07/02/1535/
http://blog.xdite.net/?p=598
http://jan.kneschke.de/projects/mysql/order-by-rand

2008年12月11日 星期四

iframe

淺入淺出 iframe (1)
淺入淺出 iframe (2)
iframe語法
html ifram tag
iframe wiki

2008年12月10日 星期三

wbr,scan,regexp,$',$&,format

scan
wbr

2008年12月9日 星期二

form_for, form_tag,multipart,polymorphic

form_for api
form_tag versus form_for with :multipart => true

default,time,format

Set the default date format for your Rails application
修改 Ruby 預設的 Time 顯示格式

2008年12月8日 星期一

How to hide .rar files within picture files

How to hide .rar files within picture files

upload multi file


2008年12月7日 星期日

rails2.2.2 default error message

“ActiveRecord::Errors.default_error_messages”沒啦, 換成“I18n.translate(activerecord.errors.messages)”

2008年12月4日 星期四

validates_uniqueness_of, scope

validates_uniqueness_of api


[JavaScript] Firefox 在 DHTML 解析上的問題

[JavaScript] Firefox 在 DHTML 解析上的問題

2008年12月3日 星期三

js, getMonth, getDate, getDay, date

JavaScript Date Object Reference

2008年12月2日 星期二

merb, Hostname not supplied

merb, console, install webrat

webrat is required for merb-core app running in console
merb console require webrat

do_mysql error,and how to track

Adding a Directory to the Path, export, command

Adding a Directory to the Path

form_for support namespace route

form_for api

authenticate_or_request_with_http_basic

authenticate_or_request_with_http_basic

auto_discovery_link_tag, rss ,atom

auto_discovery_link_tag

div_for

div_for api

What's New in Edge Rails: No More Formatted Routes

No More Formatted Routes

2008年11月27日 星期四

A quick way to get memcached status

http://www.mysqlperformanceblog.com/2008/11/26/a-quick-way-to-get-memcached-status/

echo stats | nc 127.0.0.1 11211

watch "echo stats | nc 127.0.0.1 11211"

超簡單 very simple merb upload file

http://blog.vixiom.com/2007/06/29/merb-on-air-drag-and-drop-multiple-file-upload/
http://iceskysl.1sters.com/?action=show&id=368&page=1
http://www.mikeperham.com/2007/10/02/file-uploads-in-merb-versus-rails/


幹 竟然這樣寫

How to reset a lost mysql root password

http://www.simplehelp.net/2008/11/26/how-to-reset-a-lost-mysql-root-password/

2008年11月26日 星期三

upload file in rails

http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm
http://manuals.rubyonrails.com/read/chapter/79
http://manuals.rubyonrails.com/read/chapter/78
http://manuals.rubyonrails.com/read/chapter/77
http://www.practicalecommerce.com/blogs/post/432-Multiple-Attachments-in-Rails
http://izumi.plan99.net/blog/index.php/2007/04/07/ruby-on-railss-handling-of-uploaded-files/


About the uploaded file object

While the uploaded file is a special beast,it is not difficult to use. The object
rails receives are processed by a CGI object. The object that CGI returns to Rails
isn’t actually a file object, but it’s close enough for our purposes.
Details from the CGI class documentation

... the value is not a string, but an IO object, either an IOString for small files,
or a Tempfile for larger ones.
This object also has the additional singleton methods:
local_path(): the path of the uploaded file on the local filesystem
original_filename(): the name of the file on the client computer
content_type()
: the content type of the file



2008年11月25日 星期二

yaml,load_file

http://ithelp.ithome.com.tw/question/10012281