<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1207786302201149220</id><updated>2011-12-12T21:34:41.697-08:00</updated><category term='linux'/><category term='ruby'/><category term='ASP.NET C#'/><category term='Ubuntu'/><category term='sql'/><category term='php'/><category term='rails'/><title type='text'>小B的技術筆記</title><subtitle type='html'>解決過的問題備忘錄 (外部記憶體?)</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Bruce Li</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-hmZJ7C2eTw4/AAAAAAAAAAI/AAAAAAAAAfQ/V8oRuDyelKk/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-1458096313339041934</id><published>2011-02-02T05:22:00.001-08:00</published><updated>2011-03-10T23:52:15.137-08:00</updated><title type='text'>部落格搬家</title><content type='html'>新位置→&lt;a href="http://littlebmix.blogspot.com/"&gt;http://littlebmix.blogspot.com/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;與我的生活Blog合併&lt;br /&gt;&lt;br /&gt;本部落格會視情況關閉&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-1458096313339041934?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/1458096313339041934/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=1458096313339041934' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/1458096313339041934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/1458096313339041934'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2011/02/blog-post.html' title='部落格搬家'/><author><name>Bruce Li</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-hmZJ7C2eTw4/AAAAAAAAAAI/AAAAAAAAAfQ/V8oRuDyelKk/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-795127532628772445</id><published>2011-01-21T21:30:00.000-08:00</published><updated>2011-09-24T07:34:02.795-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>ubuntu linux用rename指令批次改檔名</title><content type='html'>&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;文章移到&lt;a href="http://littlebmix.blogspot.com/2011/01/ubuntu-linuxrename.html"&gt;小B雜Blog：ubuntu linux用rename指令批次改檔名&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-795127532628772445?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/795127532628772445/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=795127532628772445' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/795127532628772445'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/795127532628772445'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2011/01/ubuntu-linuxrename.html' title='ubuntu linux用rename指令批次改檔名'/><author><name>Bruce Li</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-hmZJ7C2eTw4/AAAAAAAAAAI/AAAAAAAAAfQ/V8oRuDyelKk/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-8010864734360184801</id><published>2010-08-07T00:09:00.000-07:00</published><updated>2010-08-07T00:34:48.484-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>kates's ruby plurk lib 'add_all_as_friends' method doesn't work?</title><content type='html'>正體中文版&lt;a href="http://railsfun.tw/viewthread.php?tid=454"&gt;在此&lt;/a&gt; (Traditional Chinese version is &lt;a href="http://railsfun.tw/viewthread.php?tid=454"&gt;here&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;&lt;a href="http://github.com/kates/plurk"&gt;kates's ruby plurk lib&lt;/a&gt;&amp;nbsp;is a nice plurk lib for ruby. But&amp;nbsp;I notice that the 'add_all_as_friends' method doesn't work and always throws an exception (API call return an error message page and JSON parse failed)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Add following code before you new a Plurk::Client&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;module Plurk&lt;br /&gt;  class Client&lt;br /&gt;    ENDPOINTS[:add_all_as_friends] = {:path=&amp;gt;"/API/Alerts/addAllAsFriends", :login_required=&amp;gt;true}&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This is because that the API path is &lt;span class="Apple-style-span" style="color: #0b5394;"&gt;/API/Alerts/addAllAsFriend&lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;s&lt;/span&gt;&lt;/b&gt; not &lt;span class="Apple-style-span" style="color: #0b5394;"&gt;/API/Alerts/addAllAsFriend&lt;/span&gt;. The &lt;a href="http://github.com/kates/plurk/blob/master/lib/plurk.rb"&gt;code&lt;/a&gt; shows that they amiss lost the ending 's'. And I will contact them to fix this.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-8010864734360184801?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/8010864734360184801/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=8010864734360184801' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/8010864734360184801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/8010864734360184801'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2010/08/katess-ruby-plurk-lib-addallasfriends.html' title='kates&apos;s ruby plurk lib &apos;add_all_as_friends&apos; method doesn&apos;t work?'/><author><name>Bruce Li</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-hmZJ7C2eTw4/AAAAAAAAAAI/AAAAAAAAAfQ/V8oRuDyelKk/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-1870786836288067730</id><published>2010-07-11T03:01:00.000-07:00</published><updated>2010-07-11T08:23:54.501-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>Ruby Multi-threading simple tutorial</title><content type='html'>正體中文版在&lt;a href="http://railsfun.tw/viewthread.php?tid=438"&gt;這裡&lt;/a&gt;。(Traditional Chinese version is &lt;a href="http://railsfun.tw/viewthread.php?tid=438"&gt;here&lt;/a&gt;.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Thread Lifecycle&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create a new thread:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;puts "main thread start"&lt;br /&gt;t1=Thread.new{&lt;br /&gt;  puts "new thread"&lt;br /&gt;}&lt;br /&gt;puts "main thread end"&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Remember, if you didn't join the thread instance. The new thread will be interrupt when the main thread ended. Try following code:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;puts "main thread start"&lt;br /&gt;t1=Thread.new{&lt;br /&gt;  sleep 5&lt;br /&gt;  puts "new thread"&lt;br /&gt;}&lt;br /&gt;# sleep 10 # uncomment this line and try again&lt;br /&gt;puts "main thread end"&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Join the thread t1:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;puts "main thread start"&lt;br /&gt;t1=Thread.new{&lt;br /&gt;  sleep 5&lt;br /&gt;  puts "new thread"&lt;br /&gt;}&lt;br /&gt;t1.join&lt;br /&gt;puts "main thread end"&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But if you want 2 or more threads run at the same time. Don't join right after new it:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;puts "main thread start"&lt;br /&gt;t1=Thread.new{&lt;br /&gt;  sleep 5&lt;br /&gt;  puts "new thread 1"&lt;br /&gt;}&lt;br /&gt;t1.join # main thread will wait here until thread t1 finished&lt;br /&gt;t2=Thread.new{&lt;br /&gt;  sleep 5&lt;br /&gt;  puts "new thread 2"&lt;br /&gt;}&lt;br /&gt;#t1.join # should place here&lt;br /&gt;t2.join&lt;br /&gt;puts "main thread end"&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Exceptions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If main thread throw an exception. The script will exit and print error message. But if exception in new threads. It exit only the thread and keep others running, by default. If you want they interrupt the script, than you can set t1.abort_on_exception to true.&lt;br /&gt;&lt;br /&gt;But if you use t1.join or t1.value, they interrupt the script by default. Because the main thread will wait at that 2 commands. (t1.value is that return value of the thread block.)&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;puts "main thread start"&lt;br /&gt;t1=Thread.new{&lt;br /&gt;  sleep 5&lt;br /&gt;  puts a # Exception: undefined&lt;br /&gt;  puts "new thread"&lt;br /&gt;}&lt;br /&gt;t1.abort_on_exception = true # Default is false，If you uncomment this line. You will find out that it doesn't run the line: puts "new thread"&lt;br /&gt;sleep 10&lt;br /&gt;puts "main thread end"&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;But if it throws exception on the first line in the thread block. It can throw before setting abort_on_exception. So we can use like this:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;puts "main thread start"&lt;br /&gt;t1=Thread.new{&lt;br /&gt;  Thread.current.abort_on_exception=true # Thread.current is the thread object itself&lt;br /&gt;  puts a # Exception: undefined&lt;br /&gt;  puts "new thread"&lt;br /&gt;}&lt;br /&gt;sleep 10&lt;br /&gt;puts "main thread end"&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Variable scope&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In new threads can get/set and shared variables at same scope. But local variables in Thread.new {} block are not shared with other threads. And there is a special usage: Use Thread instance like hash:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;outside = "DDDDD"&lt;br /&gt;t1=Thread.new{&lt;br /&gt;  puts outside # get DDDDD&lt;br /&gt;  local_var = "AAAAA"&lt;br /&gt;  Thread.current["var"] = "BBBBB"&lt;br /&gt;}&lt;br /&gt;puts t1["var"] # get BBBBB&lt;br /&gt;puts local_var # Exception: undefined&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Hope this simple ruby multi-threading tutorial have helped you :-)&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.tutorialspoint.com/ruby/ruby_multithreading.htm"&gt;Reference&lt;/a&gt; (More detail)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-1870786836288067730?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/1870786836288067730/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=1870786836288067730' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/1870786836288067730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/1870786836288067730'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2010/07/ruby-multi-threading-simple-tutoring.html' title='Ruby Multi-threading simple tutorial'/><author><name>Bruce Li</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-hmZJ7C2eTw4/AAAAAAAAAAI/AAAAAAAAAfQ/V8oRuDyelKk/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-7879914563270423124</id><published>2010-06-20T12:18:00.000-07:00</published><updated>2010-06-20T12:18:21.028-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>Gets undefined method error when calling parse method?</title><content type='html'>&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;irb(main):001:0&amp;gt;  Time.parse("16:30")&lt;br /&gt;NoMethodError: undefined method `parse' for Time:Class&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Also rfc2822(), httpdate() and xmlschema(date) raises this error.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Solution: require the time.rb:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;require 'time'&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This is not a bug. It's because they are not core (But Time class is). Some implementation may auto require for you. But if you get this error, just try to require it.&lt;br /&gt;&lt;br /&gt;&lt;a href="https://bugs.archlinux.org/task/9809"&gt;Reference 1&lt;/a&gt;,&amp;nbsp;&lt;a href="http://www.ruby-forum.com/topic/172936"&gt;2&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;==Traditional Chinese version==&lt;br /&gt;&lt;br /&gt;呼叫Time.parse時得到undefined method錯誤？&lt;br /&gt;&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;irb(main):001:0&amp;gt;  Time.parse("16:30")&lt;br /&gt;NoMethodError: undefined method `parse' for Time:Class&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;rfc2822(), httpdate() and xmlschema(date) 也會爆這個錯誤&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;解決方法： require time.rb:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;require 'time'&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;這不是bug，這是因為這些methods不是core(但Time class本身是)，有些implementation可能會自動幫你require，但如果你遇到這個error，就試試看require 'time'&lt;br /&gt;&lt;br /&gt;&lt;a href="https://bugs.archlinux.org/task/9809"&gt;參考來源 1&lt;/a&gt;,&amp;nbsp;&lt;a href="http://www.ruby-forum.com/topic/172936"&gt;2&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-7879914563270423124?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/7879914563270423124/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=7879914563270423124' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/7879914563270423124'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/7879914563270423124'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2010/06/gets-undefined-method-error-when.html' title='Gets undefined method error when calling parse method?'/><author><name>Bruce Li</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-hmZJ7C2eTw4/AAAAAAAAAAI/AAAAAAAAAfQ/V8oRuDyelKk/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-4924379532814219270</id><published>2010-06-12T23:56:00.000-07:00</published><updated>2010-06-13T00:05:58.876-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>(Ruby) Write service with daemons gem</title><content type='html'>How to make a ruby script run only one instance at a time? and with start/stop command?&lt;br /&gt;&lt;br /&gt;Actually, it's very simple, just use &lt;a href="http://daemons.rubyforge.org/"&gt;Daemons&lt;/a&gt;&amp;nbsp;gem.&lt;br /&gt;&lt;br /&gt;installation (ubuntu):&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;sudo gem install daemons&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Simplest example: test.rb&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;require 'rubygems'&lt;br /&gt;require 'daemons'&lt;br /&gt;&lt;br /&gt;Daemons.run_proc('myproc.rb') do&lt;br /&gt;  loop do&lt;br /&gt;    sleep(5)&lt;br /&gt;    puts "Hello World"&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Than you can use following commands:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;ruby test.rb [start|stop|restart|run|zap]&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;(Run 'ruby test.rb' will get command usage.)&lt;br /&gt;&lt;br /&gt;And when you try to run 'test.rb start' twice. you will get:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;ERROR: there is already one or more instance(s) of the program running&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;==Traditional Chinese version==&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;如何讓一支ruby程式一次只有一個instance？並且有start/stop等指令呢？&lt;br /&gt;&lt;br /&gt;其實，這非常簡單，只要用&lt;a href="http://daemons.rubyforge.org/"&gt;Daemons&lt;/a&gt;&amp;nbsp;gem就可以了。&lt;br /&gt;&lt;br /&gt;安裝 (ubuntu):&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;sudo gem install daemons&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;最簡單的範例: test.rb&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;require 'rubygems'&lt;br /&gt;require 'daemons'&lt;br /&gt;&lt;br /&gt;Daemons.run_proc('myproc.rb') do&lt;br /&gt;  loop do&lt;br /&gt;    sleep(5)&lt;br /&gt;    puts "Hello World"&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;然後你就可以用以下指令了：&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;ruby test.rb [start|stop|restart|run|zap]&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;(執行 'ruby test.rb' 會提示你指令用法)&lt;br /&gt;&lt;br /&gt;當你嘗試執行 'test.rb start' 兩次，你會得到以下錯誤:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;ERROR: there is already one or more instance(s) of the program running&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-4924379532814219270?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/4924379532814219270/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=4924379532814219270' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/4924379532814219270'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/4924379532814219270'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2010/06/ruby-write-service-with-daemons-gem.html' title='(Ruby) Write service with daemons gem'/><author><name>Bruce Li</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-hmZJ7C2eTw4/AAAAAAAAAAI/AAAAAAAAAfQ/V8oRuDyelKk/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-289682631381424619</id><published>2010-04-29T04:37:00.000-07:00</published><updated>2010-06-13T00:02:14.185-07:00</updated><title type='text'>Problem when add the facebook new Like Box to google Blogger?</title><content type='html'>For English reader please read&amp;nbsp;&lt;a href="http://www.arlooblog.com/2010/04/facebook-like-box-html-gadget-for.html"&gt;this post&lt;/a&gt;&amp;nbsp;instead&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;我想要新增Facebook新版的Like Box (原本的Fan Box)到google blogger，但是他的iframe一直跟我說找不到頁面。後來找到了&lt;a href="http://www.arlooblog.com/2010/04/facebook-like-box-html-gadget-for.html"&gt;這個&lt;/a&gt;(英文)，解法如下：&lt;br /&gt;&lt;br /&gt;先在Facebook給你的code裏面，找到這段(YOUR_FACEBOOK_PAGE_ID是一串數字)：&lt;br /&gt;&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;...profile_id=YOUR_FACEBOOK_PAGE_ID...&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;把他改成：&lt;br /&gt;&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;...profile=1&amp;amp;id=YOUR_FACEBOOK_PAGE_ID...&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;就搞定了。收攤！&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-289682631381424619?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/289682631381424619/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=289682631381424619' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/289682631381424619'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/289682631381424619'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2010/04/problem-when-add-facebook-new-like-box.html' title='Problem when add the facebook new Like Box to google Blogger?'/><author><name>Bruce Li</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-hmZJ7C2eTw4/AAAAAAAAAAI/AAAAAAAAAfQ/V8oRuDyelKk/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-394221347566646093</id><published>2010-03-14T21:24:00.000-07:00</published><updated>2010-03-24T05:45:00.143-07:00</updated><title type='text'>sikuli在存檔之後就失效 (問題：中文路徑)</title><content type='html'>在windows xp上試玩sikuli，但是很奇怪，明明一切都很順利，怎麼突然一個都偵測不到，出現紅色背景？&lt;br /&gt;&lt;br /&gt;得到錯誤訊息：&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;edu.mit.csail.uid.FindFailed: FindFailed: 1268625522234.png can't be found.&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;ps: 那個xxxxxx.png就是截圖的檔名&lt;br /&gt;&lt;br /&gt;如果點圖片preview，會得到以下訊息&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;0 matches found&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;ps: 但是正常情況時，會有50 matches，一次掉到0也太奇怪了&lt;br /&gt;&lt;br /&gt;經過幾次測試，我發現在存檔之後才出現失效狀況，猜測是因為存檔路徑有中文，移到別的目錄後，發現一切正常了。&lt;br /&gt;&lt;br /&gt;vgod的plurk也有討論到這個狀況（我google「sikuli 路徑 中文」時才找到的...）&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-394221347566646093?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/394221347566646093/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=394221347566646093' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/394221347566646093'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/394221347566646093'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2010/03/sikuli.html' title='sikuli在存檔之後就失效 (問題：中文路徑)'/><author><name>Bruce Li</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-hmZJ7C2eTw4/AAAAAAAAAAI/AAAAAAAAAfQ/V8oRuDyelKk/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-4981924584642289721</id><published>2010-02-23T04:56:00.000-08:00</published><updated>2010-02-23T05:06:18.600-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>Make acts_as_versioned know target model belongs_to association</title><content type='html'>acts_as_versioned is a great plug-in for Rails. It can keep track of all modifications to your target model with only a little setup. But it seems not support has_*/belongs_to&amp;nbsp;association by default. So let's see how to enable this.&lt;br /&gt;&lt;br /&gt;Assume that you are going to keep track of the 'Post' model. and this is probably your model looks like:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;class Post &amp;lt; ActiveRecord::Base&lt;br /&gt;  acts_as_versioned &lt;br /&gt;  belongs_to :user&lt;br /&gt;end&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;But version.user will not work (at least, for this version).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(1) For newer version of&amp;nbsp;acts_as_versioned, try this:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;class Post &amp;lt; ActiveRecord::Base&lt;br /&gt;  acts_as_versioned do&lt;br /&gt;    belongs_to :user&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;(2) And for older version, try this:&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;class Post &amp;lt; ActiveRecord::Base&lt;br /&gt;  acts_as_versioned &lt;br /&gt;  belongs_to :user&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;Post.versioned_class.class_eval do&lt;br /&gt;  belongs_to :user&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;solution 2 works for me! but solution 1 not (ruby 1.8.6, rails 2.3.2, acts_as_versioned 0.3.1)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', verdana, sans-serif; font-size: 13px; line-height: 22px;"&gt;==Traditional Chinese version==&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', verdana, sans-serif; font-size: 13px; line-height: 22px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', verdana, sans-serif; font-size: 13px; line-height: 22px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium; line-height: normal;"&gt;acts_as_versioned 是個好套件。只要一點設定他就可以幫你紀錄model的版本變動。可是他預設沒有支援has_*/belongs_to的資料庫關聯，所以讓我們來看看要如何打開這個功能。&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;假設你要追蹤的是Post這個model，那你的model檔大概長這樣：&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium; line-height: normal;"&gt;&lt;pre style="background-color: #eeeeee; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(153, 153, 153); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(153, 153, 153); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(153, 153, 153); border-top-style: dashed; border-top-width: 1px; color: black; font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: 12px; line-height: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 661px;"&gt;&lt;code&gt;class Post &amp;lt; ActiveRecord::Base&lt;br /&gt;  acts_as_versioned &lt;br /&gt;  belongs_to :user&lt;br /&gt;end&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;但這個時候&amp;nbsp;version.user 是會掛掉的(至少這版套件如此)&lt;/div&gt;&lt;div style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;(1) 套件版本較新者可以試試這個：&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium; line-height: normal;"&gt;&lt;pre style="background-color: #eeeeee; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(153, 153, 153); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(153, 153, 153); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(153, 153, 153); border-top-style: dashed; border-top-width: 1px; color: black; font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: 12px; line-height: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 661px;"&gt;&lt;code&gt;class Post &amp;lt; ActiveRecord::Base&lt;br /&gt;  acts_as_versioned do&lt;br /&gt;    belongs_to :user&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;(2) 舊版者，則試這個：&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium; line-height: normal;"&gt;&lt;pre style="background-color: #eeeeee; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(153, 153, 153); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(153, 153, 153); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(153, 153, 153); border-top-style: dashed; border-top-width: 1px; color: black; font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: 12px; line-height: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 661px;"&gt;&lt;code&gt;class Post &amp;lt; ActiveRecord::Base&lt;br /&gt;  acts_as_versioned &lt;br /&gt;  belongs_to :user&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;Post.versioned_class.class_eval do&lt;br /&gt;  belongs_to :user&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;我用第2個方案OK，但是第1個方案則不行...&amp;nbsp;(ruby 1.8.6, rails 2.3.2, acts_as_versioned 0.3.1)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-4981924584642289721?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/4981924584642289721/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=4981924584642289721' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/4981924584642289721'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/4981924584642289721'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2010/02/make-actsasversioned-know-target-model.html' title='Make acts_as_versioned know target model belongs_to association'/><author><name>Bruce Li</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-hmZJ7C2eTw4/AAAAAAAAAAI/AAAAAAAAAfQ/V8oRuDyelKk/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-8831641822986537002</id><published>2010-02-20T19:09:00.000-08:00</published><updated>2010-02-21T04:51:08.337-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>Rails sending emails via gmail not working in heroku server but ok in localhost</title><content type='html'>I've&amp;nbsp;encountered a problem that my rails app can send email via gmail properly in my computer but not working in heroku server (get an error: "Must issue a STARTTLS command first").&lt;br /&gt;&lt;br /&gt;Following by &lt;a href="http://groups.google.com/group/communityengine/browse_thread/thread/ff7ae0daeae8cbaf"&gt;this post&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;1. download &lt;a href="http://sites.google.com/site/knkalbum/tls_smtp.rb?attredirects=0"&gt;tls_smtp.rb&lt;/a&gt;. (found from&amp;nbsp;&lt;a href="http://www.errorhelp.com/search/details/78026/redmine-rails-must-issue-a-starttls-command-first"&gt;this post&lt;/a&gt;)&lt;br /&gt;2. put it into your app lib directory&lt;br /&gt;3. import it in&amp;nbsp;config/environment.rb&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;require 'tls_smtp'&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Then upload to heroku, it's done!&lt;br /&gt;&lt;br /&gt;I didn't add additional config in&amp;nbsp;config/environments/production.rb as&amp;nbsp;&lt;a href="http://groups.google.com/group/communityengine/browse_thread/thread/ff7ae0daeae8cbaf"&gt;this post&lt;/a&gt;&amp;nbsp;said. But it still work.&lt;br /&gt;&lt;br /&gt;This is my mailer config (I put it in config/initializers/mail.rb):&lt;br /&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;ActionMailer::Base.smtp_settings = {&lt;br /&gt;  :enable_starttls_auto =&amp;gt; true,&lt;br /&gt;  :address =&amp;gt; 'smtp.gmail.com',&lt;br /&gt;  :port =&amp;gt; 587,&lt;br /&gt;  :domain =&amp;gt; 'gmail.com',&lt;br /&gt;  :authentication =&amp;gt; :plain,&lt;br /&gt;  :user_name =&amp;gt; 'xxxxxx@gmail.com',&lt;br /&gt;  :password =&amp;gt; '******'&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Hope this helps&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;==Traditional Chinese version==&lt;br /&gt;&lt;br /&gt;我剛才遇到一個問題，我用gmail寄信，在localhost也測試OK，但是丟上heroku後卻壞掉(得到「Must issue a STARTTLS command first」錯誤)&lt;br /&gt;&lt;br /&gt;後來找到了一篇&lt;a href="http://groups.google.com/group/communityengine/browse_thread/thread/ff7ae0daeae8cbaf"&gt;文章&lt;/a&gt;，依照指示：&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;1. 下載&amp;nbsp;&lt;a href="http://sites.google.com/site/knkalbum/tls_smtp.rb?attredirects=0"&gt;tls_smtp.rb&lt;/a&gt;. (在&lt;a href="http://www.errorhelp.com/search/details/78026/redmine-rails-must-issue-a-starttls-command-first"&gt;這篇&lt;/a&gt;找到的)&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;2. 放到app的lib資料夾&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;3. 引入到 config/environment.rb&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;require 'tls_smtp'&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;然後上傳到heroku，完成了！&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;我沒有依照&lt;a href="http://groups.google.com/group/communityengine/browse_thread/thread/ff7ae0daeae8cbaf"&gt;這篇&lt;/a&gt;所說要再增加mailer設定到config/environments/production.rb，不過他還是成功。&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;這是我的mailer設定 (我放在 config/initializers/mail.rb):&lt;/div&gt;&lt;pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"&gt;&lt;code&gt;ActionMailer::Base.smtp_settings = {&lt;br /&gt;  :enable_starttls_auto =&amp;gt; true,&lt;br /&gt;  :address =&amp;gt; 'smtp.gmail.com',&lt;br /&gt;  :port =&amp;gt; 587,&lt;br /&gt;  :domain =&amp;gt; 'gmail.com',&lt;br /&gt;  :authentication =&amp;gt; :plain,&lt;br /&gt;  :user_name =&amp;gt; 'xxxxxx@gmail.com',&lt;br /&gt;  :password =&amp;gt; '******'&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;希望這篇有幫助&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-8831641822986537002?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/8831641822986537002/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=8831641822986537002' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/8831641822986537002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/8831641822986537002'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2010/02/rails-sending-emails-via-gmail-not.html' title='Rails sending emails via gmail not working in heroku server but ok in localhost'/><author><name>Bruce Li</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-hmZJ7C2eTw4/AAAAAAAAAAI/AAAAAAAAAfQ/V8oRuDyelKk/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-7519701820575521026</id><published>2010-02-17T03:27:00.001-08:00</published><updated>2011-10-12T03:11:06.865-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>php分頁功能</title><content type='html'>&lt;div style="background-color: white; color: black; counter-reset: __goog_page__ 0; font-family: Verdana; font-size: 12pt; line-height: 1.5em; margin-bottom: 6px; margin-left: 6px; margin-right: 6px; margin-top: 6px; min-height: 1100px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;h1&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;注意！&lt;/span&gt;這篇文章的方法可能存在資料隱碼(sql injection)的風險，如果您沒有設定自動排除特殊字元(&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: 16px; line-height: normal;"&gt;magic_quotes_gpc設定值)，那您必須進行防護，例如參考-&amp;gt;&lt;a href="http://www.php5.idv.tw/modules.php?mod=books&amp;amp;act=show&amp;amp;shid=2475"&gt;這篇&lt;/a&gt;&amp;lt;-&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h1&gt;&lt;h1&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h1&gt;&lt;h1&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;(整理資料時翻出來的，之前有人問我php分頁要怎麼弄時，寫給他的文章)&lt;/span&gt;&lt;/span&gt;&lt;/h1&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;= = = = =&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;沒有經過測試，請自行研究。&lt;br /&gt;&lt;br /&gt;&lt;h3 style="font-size: 12pt;"&gt;觀察SQL語法&lt;/h3&gt;&lt;blockquote style="border-bottom-color: rgb(221, 221, 221); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(221, 221, 221); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(221, 221, 221); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(221, 221, 221); border-top-style: dashed; border-top-width: 1px; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"&gt;&lt;span class="syntax Apple-style-span"&gt;&lt;span class="syntax_alpha syntax_alpha_reservedWord Apple-style-span"&gt;SELECT&lt;/span&gt;&amp;nbsp;&lt;span class="syntax_punct Apple-style-span"&gt;*&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="syntax Apple-style-span"&gt;&lt;span class="syntax_alpha syntax_alpha_reservedWord Apple-style-span"&gt;FROM&lt;/span&gt;&amp;nbsp;&lt;span class="syntax_quote syntax_quote_backtick Apple-style-span"&gt;`news`&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="syntax Apple-style-span"&gt;&lt;span class="syntax_alpha syntax_alpha_reservedWord Apple-style-span"&gt;ORDER&lt;/span&gt;&amp;nbsp;&lt;span class="syntax_alpha syntax_alpha_reservedWord Apple-style-span"&gt;BY&lt;/span&gt;&amp;nbsp;&lt;span class="syntax_quote syntax_quote_backtick Apple-style-span"&gt;`startdate`&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="syntax Apple-style-span"&gt;&lt;span class="syntax_alpha syntax_alpha_reservedWord Apple-style-span"&gt;LIMIT&lt;/span&gt;&amp;nbsp;&lt;span class="syntax_digit syntax_digit_integer Apple-style-span"&gt;5&lt;/span&gt;&amp;nbsp;&lt;span class="syntax_punct syntax_punct_listsep Apple-style-span"&gt;,&lt;/span&gt;&amp;nbsp;&lt;span class="syntax_digit syntax_digit_integer Apple-style-span"&gt;1 #代表「&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;LIMIT&lt;/span&gt;&amp;nbsp;第&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;5&lt;/span&gt;筆, 一頁&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;1&lt;/span&gt;筆」(but是0開始算喔，所以給5會傳回第6筆)&lt;br /&gt;#所以這個query會傳回單一筆、依照startdate欄位排列後的第6筆record&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;h3 style="font-size: 12pt;"&gt;&lt;span class="syntax Apple-style-span"&gt;&lt;span class="syntax_digit syntax_digit_integer Apple-style-span"&gt;實作方法構想&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style="font-size: 12pt;"&gt;&lt;/h3&gt;&lt;div style="margin-bottom: 0px; margin-left: 40px; margin-top: 0px;"&gt;1.頁面「view.php?lid=&lt;span class="Apple-style-span" style="font-family: 文鼎PL細上海宋Uni, serif;"&gt;&lt;span class="Apple-style-span" style="font-family: 文鼎PL細上海宋Uni;"&gt;χ&lt;/span&gt;&lt;/span&gt;」，用lid傳入來使用「LIMIT $lid, 1」，傳回該筆資料的內容&lt;br /&gt;2.並給予view.php?lid=&lt;span class="Apple-style-span" style="font-family: 文鼎PL細上海宋Uni, serif;"&gt;&lt;span class="Apple-style-span" style="font-family: 文鼎PL細上海宋Uni;"&gt;χ&lt;/span&gt;&lt;/span&gt;-1或+1的超連結(按下後回到第一步驟，如此循環)&lt;/div&gt;&lt;h3 style="font-size: 12pt;"&gt;構想程式碼&lt;/h3&gt;&lt;blockquote style="border-bottom-color: rgb(221, 221, 221); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(221, 221, 221); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(221, 221, 221); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(221, 221, 221); border-top-style: dashed; border-top-width: 1px; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"&gt;&amp;lt;?PHP&lt;br /&gt;$lid=$_GET['lid'];&lt;br /&gt;$sql="SELECT * FROM `news` WHERE `startdate`&amp;lt;='$today' AND `enddate`&amp;gt;='$today' ORDER BY `startdate`, `id` LIMIT&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: #ffcc99;"&gt;$lid&lt;/span&gt;, 1";&lt;br /&gt;//(見註1)&lt;br /&gt;//執行query與印出&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;a herf="自己.php?lid=&amp;lt;?PHP echo $lid-- ?&amp;gt;"&amp;gt;上一筆&amp;lt;/a&amp;gt; | &amp;lt;a herf="自己.php?lid=&amp;lt;?PHP echo $lid++ ?&amp;gt;"&amp;gt;下一筆&amp;lt;/a&amp;gt;&lt;/blockquote&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 40px; margin-top: 0px;"&gt;最頭尾的資料須加上防呆，由於指定給LIMIT第一個參數沒有對應到record的話不會傳回資料，可以藉此判斷是否到達最尾，最頭的話就簡單多了，指定負數絕對是不合法的筆數，因此在lid=0的時候便不給?lid=$lid-1的連結。&lt;br /&gt;效能最佳化：第一次查詢時先得到目前公告的總筆數(見註2)，紀錄在SESSION中，$lid==該值的時候不給?lid=$lid+1的連結即可，但須考慮即時更新時掛網的使用者可能無法看到，可以再加寫更新機制。&lt;/div&gt;&lt;br /&gt;&lt;h3 style="font-size: 12pt;"&gt;註解&lt;/h3&gt;&lt;div style="margin-bottom: 0px; margin-left: 40px; margin-top: 0px;"&gt;註1：SELECT使用*號是不良示範，請使用「SELECT `title`, `content`, `startdate`, `enddate` FROM ...」，如果無須顯示兩個時間，減少讀取的欄位會讓效能好一點點，但累積下來總是龐大的。php+mysql最佳化請見&lt;a href="http://www.dublish.com/articles/10.html" style="color: #551a8b;" title="此文"&gt;此文&lt;/a&gt;。&lt;br /&gt;&lt;br /&gt;註2：請善用SQL function，以下sql查詢將傳回一欄一列的result，該值為資料列的數量，其他常見的function還有MAX、MIN、SUM、…等等。&lt;br /&gt;&lt;blockquote style="border-bottom-color: rgb(221, 221, 221); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(221, 221, 221); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(221, 221, 221); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(221, 221, 221); border-top-style: dashed; border-top-width: 1px; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"&gt;SELECT COUNT(`id`) FROM `news` WHERE `startdate`&amp;lt;='$today' AND `enddate`&amp;gt;='$today'&lt;/blockquote&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 40px; margin-top: 0px;"&gt;註3：sql function的下法我所知道的有三種，「COUNT(`id`)」、「COUNT(1)」跟「COUNT(*)」，經過測試，「COUNT(`id`)」是效能最佳的方法，可能原因是PK具有索引性(index)，以下是兩次 [單筆1000次查詢*100回]的測試數據&lt;br /&gt;&lt;blockquote style="border-bottom-color: rgb(221, 221, 221); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(221, 221, 221); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(221, 221, 221); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(221, 221, 221); border-top-style: dashed; border-top-width: 1px; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"&gt;COUNT(*) &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; COUNT(1) &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; | &amp;nbsp;&amp;nbsp; COUNT(`id`)&lt;br /&gt;0.1283900737760&amp;nbsp; | &amp;nbsp; 0.1033070087430&amp;nbsp; | &amp;nbsp; 0.0965209007263&lt;br /&gt;0.0977160930634&amp;nbsp; | &amp;nbsp; 0.0935349464417&amp;nbsp; | &amp;nbsp; 0.0874459743500&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-7519701820575521026?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/7519701820575521026/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=7519701820575521026' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/7519701820575521026'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/7519701820575521026'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2010/02/php.html' title='php分頁功能'/><author><name>Bruce Li</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh6.googleusercontent.com/-hmZJ7C2eTw4/AAAAAAAAAAI/AAAAAAAAAfQ/V8oRuDyelKk/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-2586252132147330088</id><published>2009-12-21T19:24:00.000-08:00</published><updated>2010-02-21T16:40:27.743-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>ubuntu 9.04 9.10 設定wacom繪圖版的相對模式/絕對模式</title><content type='html'>這是我的備忘筆記，雖然不是很完美的解法...呵呵&lt;br /&gt;&lt;br /&gt;實際上，有一個GUI設定套件，叫作&lt;a href="http://linuxwacom.sourceforge.net/"&gt;linux-wacom&lt;/a&gt; ，但是我沒辦法編譯成功...有人能分享一下安裝方式嗎XD&lt;br /&gt;&lt;br /&gt;而我目前的作法如下：&lt;br /&gt;1. 確定xserver-xorg-input-wacom跟xinput套件有裝好，此時接上wacom繪圖版應該已經能控制滑鼠，但是是絕對座標模式&lt;br /&gt;2. 開一個虛擬終端機，執行&lt;br /&gt;&lt;blockquote&gt;xinput list&lt;/blockquote&gt;3. 找到一個類似「Wacom Bamboo」的項目(不同型號會不一樣名稱)，應該有一個子項目是「mode: ABSOLUTE」&lt;br /&gt;4. 想改成相對模式則用這個指令&lt;br /&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;xinput set-mode "Wacom Bamboo" RELATIVE&lt;/blockquote&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;br /&gt;ps: 可以把切換的指令設定別名(alias)在 ~/.bashrc 檔裏，就可以用縮寫切換喔！&lt;br /&gt;例如我的：&lt;br /&gt;&lt;blockquote&gt;alias xr='xinput set-mode "Wacom Bamboo" RELATIVE'&lt;br /&gt;alias xa='xinput set-mode "Wacom Bamboo" ABSOLUTE'&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-2586252132147330088?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/2586252132147330088/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=2586252132147330088' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/2586252132147330088'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/2586252132147330088'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2009/12/ubuntu-904-910-wacom.html' title='ubuntu 9.04 9.10 設定wacom繪圖版的相對模式/絕對模式'/><author><name>Bruce</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-6201814907790774659</id><published>2008-12-18T12:22:00.000-08:00</published><updated>2008-12-18T12:48:51.367-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET C#'/><title type='text'>ASP.NET C# ADO.NET的Type, Provider, Service的做法與觀念（目前還處於我猜測的階段）</title><content type='html'>Type class內宣告instance variables跟其accessors&lt;br /&gt;&lt;br /&gt;Provider class內放資料的CRUD oprations，傳入參數而非透過O/R mapping來操作的話，這些oprations應該宣告成static，也就是class method。&lt;br /&gt;&lt;br /&gt;舉例來說，假設有兩個物件，作者跟書&lt;br /&gt;Authors (id, name, gender) // 編號，姓名，性別&lt;br /&gt;Books (id, author_id, title, subtitle, published_at) //編號，作者FK，標題，副標題，出版日&lt;br /&gt;&lt;br /&gt;要更新書籍時，透過Books的provider進行以下動作：&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0); font-family: courier new;"&gt;...BooksService.Make().Update(modified_row);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;或&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;beyound_java.Update(modified_row) // beyound_java是一個books物件&lt;/span&gt;&lt;br /&gt;都是不好的，&lt;br /&gt;&lt;br /&gt;前者不符合LoD，只跟親近的朋友溝通，或稱最少知識原則。&lt;br /&gt;後者有可能產生不make sense的狀況，看看下列的語法&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;beyound_java.Update(3, 4, "better faster and lighter java", null, null) // beyound_java是一個books物件&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;竟然由beyound java這本書去更新另一本書的資料，這很詭異，正常的作法應該是所謂「上系統」去修改資料，所以我目前認為這些oprations宣告成class method會比較合理一點。&lt;br /&gt;&lt;br /&gt;至於service，其實可以不必存在，將為了跟控制項溝通的語法寫在provider裡面的各個method前即可。&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-6201814907790774659?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/6201814907790774659/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=6201814907790774659' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/6201814907790774659'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/6201814907790774659'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2008/12/aspnet-c-adonettype-provider-service.html' title='ASP.NET C# ADO.NET的Type, Provider, Service的做法與觀念（目前還處於我猜測的階段）'/><author><name>Bruce</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-2729988922628843895</id><published>2008-10-21T11:34:00.000-07:00</published><updated>2008-10-21T11:53:12.562-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>an acts_as_versioned error/bug with Rails 2.1 -在rails 2.1用acts_as_versioned插件奇怪的錯誤</title><content type='html'>&lt;span&gt;use acts_as_versioned plug-in lead to an unknown exception:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span&gt;"NoMethodError: You have a nil object when you didn't expect it!" &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;from /opt/local/lib/ruby/gems/&lt;b class="highlight"&gt;1&lt;/b&gt;.8/gems/activerecord-&lt;b class="highlight"&gt;2&lt;/b&gt;.&lt;b class="highlight"&gt;1&lt;/b&gt;.&lt;b class="highlight"&gt;0&lt;/b&gt;/lib/active_record/attribute_methods.rb:&lt;b class="highlight"&gt;211&lt;/b&gt;:in &lt;/span&gt;&lt;br /&gt;&lt;span&gt;`version=' &lt;/span&gt;&lt;br /&gt;&lt;span&gt;from /Users/toby/rorbar/olhc_website/vendor/plugins/&lt;b class="highlight"&gt;acts_as_versioned&lt;/b&gt;/lib/&lt;b class="highlight"&gt;acts_as_versioned&lt;/b&gt;.rb:431:in &lt;/span&gt;&lt;br /&gt;&lt;span&gt;`send' &lt;/span&gt;&lt;br /&gt;&lt;span&gt;from /Users/toby/rorbar/olhc_website/vendor/plugins/&lt;b class="highlight"&gt;acts_as_versioned&lt;/b&gt;/lib/&lt;b class="highlight"&gt;acts_as_versioned&lt;/b&gt;.rb:431:in &lt;/span&gt;&lt;br /&gt;&lt;span&gt;`set_new_version'&lt;/span&gt;&lt;/blockquote&gt;&lt;span&gt;&lt;br /&gt;It is maybe because of out-of-day acts_as_versioned plugin with rails 2.1 or above.&lt;br /&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span&gt;The partial updates feature in &lt;b class="highlight"&gt;2&lt;/b&gt;.&lt;b class="highlight"&gt;1&lt;/b&gt; caused a conflict with the the way &lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;b class="highlight"&gt;acts_as_versioned&lt;/b&gt; handles it's own change history. Check out the &lt;/span&gt;&lt;br /&gt;&lt;span&gt;latest master on github as this has been resolved: &lt;/span&gt;&lt;br /&gt;&lt;a href="http://github.com/technoweenie/acts_as_versioned/tree/master" target="_top" rel="nofollow"&gt;&lt;span&gt;http://github.com/technoweenie/&lt;b class="highlight"&gt;acts_as_versioned&lt;/b&gt;/tree/master&lt;/span&gt;&lt;/a&gt;&lt;/blockquote&gt;see http://www.nabble.com/acts_as_versioned-and-Rails-2.1-td17665890.html&lt;br /&gt;&lt;span&gt;&lt;br /&gt;To solve this. reinstall the acts_as_versioned gem. or download tarbal/zip package from GitHub(link above) and unzip into the rails application's vendor/plugin directory.&lt;br /&gt;(i have problem in re-installation. it always install only Docs. even give a -f augment Do anyone know how to re-install a gems plug-in?)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;==Chinese version==&lt;/span&gt;&lt;span&gt;&lt;br /&gt;使用&lt;/span&gt;&lt;span&gt;acts_as_versioned插件時導致了以下的錯誤&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span&gt;"NoMethodError: You have a nil object when you didn't expect it!"   &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;from /opt/local/lib/ruby/gems/&lt;b class="highlight"&gt;1&lt;/b&gt;.8/gems/activerecord-&lt;b class="highlight"&gt;2&lt;/b&gt;.&lt;b class="highlight"&gt;1&lt;/b&gt;.&lt;b class="highlight"&gt;0&lt;/b&gt;/lib/active_record/attribute_methods.rb:&lt;b class="highlight"&gt;211&lt;/b&gt;:in   &lt;/span&gt;&lt;br /&gt;&lt;span&gt;`version='   &lt;/span&gt;&lt;br /&gt;&lt;span&gt;from /Users/toby/rorbar/olhc_website/vendor/plugins/&lt;b class="highlight"&gt;acts_as_versioned&lt;/b&gt;/lib/&lt;b class="highlight"&gt;acts_as_versioned&lt;/b&gt;.rb:431:in   &lt;/span&gt;&lt;br /&gt;&lt;span&gt;`send'   &lt;/span&gt;&lt;br /&gt;&lt;span&gt;from /Users/toby/rorbar/olhc_website/vendor/plugins/&lt;b class="highlight"&gt;acts_as_versioned&lt;/b&gt;/lib/&lt;b class="highlight"&gt;acts_as_versioned&lt;/b&gt;.rb:431:in   &lt;/span&gt;&lt;br /&gt;&lt;span&gt;`set_new_version'&lt;/span&gt;&lt;/blockquote&gt;&lt;span&gt;這可能是因為您在rails 2.1或更新的版本中使用老舊的&lt;/span&gt;&lt;span&gt;acts_as_versioned插件&lt;/span&gt;&lt;blockquote&gt;&lt;span style="color: rgb(153, 153, 153);"&gt;&lt;br /&gt;The partial updates feature in &lt;b class="highlight"&gt;2&lt;/b&gt;.&lt;b class="highlight"&gt;1&lt;/b&gt; caused a conflict with the the way   &lt;/span&gt;&lt;br /&gt;有一部分rails 2.1的新功能導致&lt;span&gt;acts_as_versioned插件處理歷史紀錄功能壞掉&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);"&gt;&lt;b class="highlight"&gt;acts_as_versioned&lt;/b&gt; handles it's own change history. Check out the   &lt;/span&gt;&lt;br /&gt; &lt;span&gt;&lt;span style="color: rgb(153, 153, 153);"&gt;latest master on github as this has been resolved:   &lt;/span&gt;&lt;br /&gt;請從github弄出最新的程式碼，master已經修正:&lt;br /&gt;&lt;/span&gt;   &lt;a href="http://github.com/technoweenie/acts_as_versioned/tree/master" target="_top" rel="nofollow"&gt;&lt;span&gt;http://github.com/technoweenie/&lt;b class="highlight"&gt;acts_as_versioned&lt;/b&gt;/tree/master&lt;/span&gt;&lt;/a&gt;&lt;/blockquote&gt;請參考 http://www.nabble.com/acts_as_versioned-and-Rails-2.1-td17665890.html&lt;br /&gt;&lt;span&gt;&lt;br /&gt;&lt;br /&gt;要解決這個問題，重新安裝&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;acts_as_versioned插件，或直接從github網站下載tarbal/zip的壓縮檔，解壓縮到rails目錄的vendor/plugin子目錄中&lt;/span&gt;&lt;br /&gt;(但是我重新安裝有問題，即使我下了-f參數，他還是只會安裝新的文件工具，有人知道要如何確實重新安裝gems的插件嗎？)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-2729988922628843895?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/2729988922628843895/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=2729988922628843895' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/2729988922628843895'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/2729988922628843895'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2008/10/actsasversioned-errorbug-with-rails-21.html' title='an acts_as_versioned error/bug with Rails 2.1 -在rails 2.1用acts_as_versioned插件奇怪的錯誤'/><author><name>Bruce</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-7147254087265356081</id><published>2008-09-23T14:15:00.000-07:00</published><updated>2008-10-21T11:53:29.155-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>ror rails mailer with sendmail don't work? 不會寄信 寄不出去？ mailer setup設定 RESTful Authentication mailer</title><content type='html'>the main point is the augment of sendmail setting. if you did not set the augment -i -t, the sendmail server will wait rather then send immediately. it's because the usage of sendmail server. you can search the sendmail server manual if you want.&lt;br /&gt;&lt;br /&gt;by the way, if you want to use RESTful Authentication with activation. you may run into a big question about 'why did the mailer not work?'. this is one of the reason. but if it still can't work. check if you already active the observer which you can set in [config/environment.rb]. (try find those keywords: config.active_record.observers)&lt;br /&gt;&lt;br /&gt;in Chinese:&lt;br /&gt;&lt;blockquote&gt;主要的點是你必須設定sendmail的參數，如果沒有設-i -t的話，sendmail server會等待不發送，這跟sendmail server的用法有關，有興趣的話可以去vbird鳥哥網站找sendmail教學。&lt;br /&gt;另外，如果你是想用RESTful Authentication的activation功能，發現mail沒辦法寄，除了以上說的，還有一個新手可能沒注意到的地方是，observer要在[config/environment.rb]設定檔裏面打開，搜尋一行config.active_record.observers 那邊把相應的observers 的名稱打上去&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;/blockquote&gt;code:&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code&gt;config.action_mailer.raise_delivery_errors = true&lt;br /&gt;&lt;br /&gt;ActionMailer::Base.delivery_method = :sendmail&lt;br /&gt;&lt;br /&gt;ActionMailer::Base.sendmail_settings = {&lt;br /&gt;:location       =&gt; '/usr/sbin/sendmail',&lt;br /&gt;:arguments      =&gt; '-i -t'&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt;&lt;br /&gt;reference:&lt;br /&gt;&lt;a href="http://www.red91.com/2007/11/05/sending-mail-with-rails"&gt;http://www.red91.com/2007/11/05/sending-mail-with-rails&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-7147254087265356081?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/7147254087265356081/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=7147254087265356081' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/7147254087265356081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/7147254087265356081'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2008/09/ror-rails-mailer-with-sendmail-dont.html' title='ror rails mailer with sendmail don&apos;t work? 不會寄信 寄不出去？ mailer setup設定 RESTful Authentication mailer'/><author><name>Bruce</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-2646121519147146920</id><published>2008-02-25T02:25:00.000-08:00</published><updated>2010-02-23T01:29:37.676-08:00</updated><title type='text'>rails 2.0 如何把controller跟view放到子資料夾使用</title><content type='html'>(最下面有補充正解)&lt;br /&gt;&lt;br /&gt;看過「ruby on rails專業網站案例實作」這本書的話&lt;br /&gt;應該知道他們把幾個controllers放到admin資料夾底下&lt;br /&gt;/app/controllers/books_controller.rb&lt;br /&gt;移到/app/controllers/admin/　底下&lt;br /&gt;&lt;br /&gt;網址也從localhost/books&lt;br /&gt;變成了localhost/admin/books&lt;br /&gt;&lt;br /&gt;在升級到rails 2.0後卻讓我搞老半天&lt;br /&gt;經過一些人的指導&lt;br /&gt;我得到一個暫時的答案&lt;br /&gt;&lt;br /&gt;答案是：&lt;br /&gt;1.不需要用子資料夾就可以換網址&lt;br /&gt;&lt;blockquote&gt;如果有需要從localhost/books&lt;br /&gt;變成了localhost/admin/books&lt;br /&gt;只要改routing即可達到目的&lt;br /&gt;但是routing的設定在此不提&lt;/blockquote&gt;&lt;br /&gt;2.不應該把程式檔案放在子資料夾&lt;br /&gt;&lt;blockquote&gt;不應該有撞名的問題，所以不需要到把controllers分到資料夾做分類&lt;br /&gt;如果放到子資料夾了，routing路徑也改了，就會有template is missing的問題（我猜是因為rails假設不會用到子資料夾，所以樣板當然也不會去子資料夾找）&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;2010-2-23補充：正解是&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;&lt;a href="http://guides.rubyonrails.org/routing.html"&gt;使用namespace&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;(正解其實早就知道了，只是我很久沒寫rails就懶得記筆記...XD)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-2646121519147146920?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/2646121519147146920/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=2646121519147146920' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/2646121519147146920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/2646121519147146920'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2008/02/rails-20-controllerview.html' title='rails 2.0 如何把controller跟view放到子資料夾使用'/><author><name>Bruce</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-1486587415025535569</id><published>2008-02-19T03:15:00.000-08:00</published><updated>2008-10-21T11:53:51.617-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>acts as authenticated為什麼無法寫入actived_at欄位？</title><content type='html'>如果你跟我遇到一樣的狀況&lt;br /&gt;在rails的acts as authenticated套件啟用activation認證碼開通功能的時候&lt;br /&gt;發現activation_code這個欄位會被清除，但actived_at欄位卻還是NULL沒有變成寫入時間(導致登入時被擋掉)&lt;br /&gt;那麼肯定跟我中同一個標了&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Be careful !! *&lt;br /&gt;User Activation is not secured. You need to add the following line&lt;br /&gt;to your user model :   attr_protected :activated_at&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;這段取自acts as authenticated的說明網頁&lt;br /&gt;他叫你在user model加入「attr_protected :activated_at」這行&lt;br /&gt;&lt;br /&gt;如果你乖乖的加入了&lt;br /&gt;現在請把它刪除&lt;br /&gt;&lt;br /&gt;嗯...然後這部份就正常了...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;我猜可能是rails版本不同的關係&lt;br /&gt;當時用「acts as authenticated activated_at」當keywords也沒搜尋到資料&lt;br /&gt;總之&lt;br /&gt;我花了23次的try and error才發現的（一切搞定時，table users已經autoindex到23了）&lt;br /&gt;&lt;br /&gt;辛苦我自己了= ="&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-1486587415025535569?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/1486587415025535569/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=1486587415025535569' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/1486587415025535569'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/1486587415025535569'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2008/02/acts-as-authenticatedactivedat.html' title='acts as authenticated為什麼無法寫入actived_at欄位？'/><author><name>Bruce</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-8428320478500985444</id><published>2007-09-28T02:43:00.000-07:00</published><updated>2007-09-28T02:54:16.472-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>ubuntu linux提供的螢幕解析度選項太少…怎麼會這樣</title><content type='html'>昨天筆者新電腦灌好了ubuntu，發現怎麼解析度那麼少（只給到1024*768），明明顯卡螢幕都OK的，求問了一下google大神，有人建議修改/etc/X11/xorg.conf檔案，但我懶、而且也怕怕，所以我在終端機執行以下指令：&lt;br /&gt;&lt;blockquote&gt;sudo dpkg-reconfigure xserver-xorg&lt;/blockquote&gt;這指令會一步一步問答，全部重設一次（包括鍵盤…等等設定），就像一開始在安裝過程會問你的鍵盤layout等等…就照情況選擇就OK了，會有一個選擇螢幕解析度，按空白鍵把要的幾個解析度打星號即可。&lt;br /&gt;&lt;br /&gt;最後重開機 ，或Ctrl+Alt+Backspace重啟X應該就解決了&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-8428320478500985444?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/8428320478500985444/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=8428320478500985444' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/8428320478500985444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/8428320478500985444'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2007/09/ubuntu-linux.html' title='ubuntu linux提供的螢幕解析度選項太少…怎麼會這樣'/><author><name>Bruce</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-6816212721702232912</id><published>2007-09-28T02:33:00.000-07:00</published><updated>2007-09-28T02:41:19.501-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>用PHP算出兩日期差幾日 (倒數計日)</title><content type='html'>&lt;p&gt;用Date函數格式化日期的時候 (省略參數→目前時間)&lt;br /&gt;PHP從參數(或省略參數時從系統中)得到一個整數&lt;/p&gt; &lt;p&gt;這個整數是從Unix系統零時(1970年1月1日凌晨) (有人說Unix時期、總之就是設定給Unix的誕辰日) ~~到指定時間點的累積總秒數 (叫epoch day，以下用timestamp表示)&lt;br /&gt;例如：1970年1月2日下午3點半的timestamp等於142200 (39小時+30分鐘=140400+1800)&lt;br /&gt;PHP下可以用mktime來產生指定日期時間的timestamp (請自行參考函式庫)&lt;br /&gt;&lt;/p&gt;&lt;blockquote&gt;☆注意：&lt;br /&gt;Unix系統零時是在格林威治時間(GMT)下，台灣的時區是GMT+8，也就是早GMT 8小時&lt;br /&gt;時區設定在台灣的主機，使用mktime的PHP函數 產生1970.1.1　0:00:00的timestamp將小於0!!! (當時GMT還在1969.12.31　16:00:00)&lt;br /&gt;換句話說，產生1970.1.1　8:00:00的timestamp將等於0  (GMT正好到1970.1.1　0:00:00)&lt;br /&gt;這麼說...用mktime產生目前時間的timestamp都會差8小時了!!&lt;br /&gt;這時可以用gmmktime函數(將參數給的時間視為GMT時間而非該時區的時間) 直接產生GMT的timestamp&lt;br /&gt;但是gmmktime在時區為台灣的主機，仍無法產生1970.1.1　8:00:00以前的timestamp (這我就想不通為什麼了...錯誤訊息：[&lt;strong&gt;Warning&lt;/strong&gt;: gmmktime(): Windows does not support negative values for this function] 不巧手邊也沒Linux主機可以測試....)&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;/blockquote&gt; &lt;p&gt;知道timestamp是總秒數了...那如果把兩日期的timestamp相減，得到的不就是兩日期的差異總秒數了嗎!?&lt;br /&gt;要算差異的天數的話，那就是除以1天的秒數囉 (1天=86400秒)&lt;/p&gt; &lt;p&gt;筆者這支程式取得timestamp的函數用strtotime，省得時分秒的問題 (strtotime使用方法請自行參考函式庫) 但是取得的是主機的時區...不過因為不可能遇到1970.1.1前8小時的情況(除非故意的)...所以筆者就不予考慮...&lt;br /&gt;照這個想法寫的程式如下： (範例是今年的統一入學測驗日，是5月20號)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;$today = strtotime(date("Y-n-j"));&lt;br /&gt;$tdehu = strtotime("2006-5-20");&lt;br /&gt;$diff = ($tdehu - $today) / 86400;&lt;br /&gt;echo "倒數$diff天"&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-6816212721702232912?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/6816212721702232912/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=6816212721702232912' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/6816212721702232912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/6816212721702232912'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2007/09/php_28.html' title='用PHP算出兩日期差幾日 (倒數計日)'/><author><name>Bruce</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-4856548653323974786</id><published>2007-09-28T02:11:00.000-07:00</published><updated>2007-09-28T02:41:37.041-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>用PHP算出本月的第一天是星期幾</title><content type='html'>&lt;p&gt;筆者曾經用Date函數取得今日的日期跟星期，再往前推算，程式碼要寫好幾行，至少五行跑不掉。&lt;/p&gt; &lt;p&gt;最近筆者想到了一個更好的解決辦法&lt;/p&gt; &lt;p&gt;這是Date函數的語法：&lt;br /&gt;string date (string format [, int timestamp])&lt;/p&gt; &lt;p&gt;我們可以直接指定timestamp再取出格式化時間，timestamp的觀念在上一篇「倒數計日」已經講的很清楚了。&lt;/p&gt; &lt;p&gt;而取得星期的格式參數如下：&lt;br /&gt;D：取得英文簡寫(如Wed/Fri等)&lt;br /&gt;l(小L)：取得英文名稱(如：Friday/Sunday等)&lt;br /&gt;w：取得數字代表：0=星期日 2=星期二…&lt;/p&gt; &lt;p&gt;如果我們這樣寫&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;date("w");&lt;br /&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt; &lt;blockquote&gt;&lt;/blockquote&gt; &lt;p&gt;我們將會得到5 （筆者寫這篇文是在禮拜五）&lt;/p&gt; &lt;p&gt;那如果我利用指定timestamp的方式，指定到這個月的第一天不就得了？！&lt;/p&gt; &lt;p&gt;程式碼如下：&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;date("l", strtotime(date("Y-n-1")));&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt; &lt;p&gt;為了讓大家看的更清楚，筆者分解一下動作：(假設今日2006-3-17 Friday)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;date("l", strtotime(date("Y-n-1")));&lt;br /&gt;&lt;/p&gt;&lt;p&gt;date("l", strtotime(&lt;span style="font-weight: bold;"&gt;"2006-3-1"&lt;/span&gt;));&lt;/p&gt;&lt;p&gt;date("l", &lt;span style="font-weight: bold;"&gt;1141142400&lt;/span&gt;); //這串數字是timestamp，請參考&lt;a href="http://bblog-tech.blogspot.com/2007/09/php_28.html"&gt;這一篇&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;"Wednesday"&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-4856548653323974786?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/4856548653323974786/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=4856548653323974786' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/4856548653323974786'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/4856548653323974786'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2007/09/php.html' title='用PHP算出本月的第一天是星期幾'/><author><name>Bruce</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-3616908821668535549</id><published>2007-08-30T08:51:00.000-07:00</published><updated>2008-10-21T11:54:02.504-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>使用acts as authenticated plugin在if current_user判斷出錯</title><content type='html'>如果跟著「Ruby on Rails專業網站案例實作」這本書走，在第八章安全性應該教到使用acts as authenticated插件，但奇怪的是layout中下面那行總會出錯，拿書商的範例檔來run也一樣。&lt;br /&gt;&lt;blockquote&gt;&lt;% if current_user %&gt;&lt;/blockquote&gt;&lt;br /&gt;小弟花了幾天的時間才搞定(小弟不才orz)，current_user是在.../lib/authenticated_system.rb 中的一個method，在未登入狀況下會傳回:false，因此將範例原始檔中、出錯的那行改成如下，便可正確執行。&lt;br /&gt;&lt;blockquote&gt;&lt;% if current_user != :false %&gt; &lt;/blockquote&gt;另外一種做法是只將.../lib/authenticated_system.rb 中的current_user method改成如下&lt;br /&gt;&lt;blockquote&gt;def current_user&lt;br /&gt;  @current_user ||= (session[:user] &amp;amp;&amp;amp; User.find_by_id(session[:user])) || nil &lt;span style="color: rgb(0, 0, 153);"&gt;#原本最後一個是:false&lt;/span&gt;&lt;br /&gt;end&lt;/blockquote&gt;小弟使用前者。&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-3616908821668535549?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/3616908821668535549/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=3616908821668535549' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/3616908821668535549'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/3616908821668535549'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2007/08/acts-as-authenticated-pluginif.html' title='使用acts as authenticated plugin在if current_user判斷出錯'/><author><name>Bruce</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-7412299076123794680</id><published>2007-08-13T08:55:00.000-07:00</published><updated>2007-09-28T02:43:01.967-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><title type='text'>sql function最佳效能寫法</title><content type='html'>sql提供一些方便的查詢function，例如count、min、max、sum等等&lt;br /&gt;但究竟怎麼寫效能會比較好呢？&lt;br /&gt;一般常見的寫法有以下三種（假設主鍵是id）&lt;br /&gt;SELECT COUNT(*) FROM `table`&lt;br /&gt;SELECT COUNT(1) FROM `table`&lt;br /&gt;SELECT COUNT(`id`) FROM `table`&lt;br /&gt;&lt;br /&gt;小弟廢話不多說了，直接po上我自己的測試數據&lt;br /&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;___COUNT(*) ______ COUNT(1)                     ______ COUNT(`id`)____&lt;br /&gt;0.1283900737760          |   0.1033070087430         |   0.0965209007263&lt;br /&gt;0.0977160930634          |   0.0935349464417          |   0.0874459743500&lt;/blockquote&gt;&lt;br /&gt;這是一次連續查詢1000次，對三者輪流查詢100次的total&lt;br /&gt;可以發現COUNT(`id`)　的寫法明顯獲勝，感謝CFC大大提示可能是因為主鍵具有索引性(index)，所以查詢速度較快。&lt;br /&gt;&lt;br /&gt;分享給大家 :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-7412299076123794680?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/7412299076123794680/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=7412299076123794680' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/7412299076123794680'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/7412299076123794680'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2007/08/sql-function.html' title='sql function最佳效能寫法'/><author><name>Bruce</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1207786302201149220.post-2984224243843107361</id><published>2007-05-11T03:16:00.000-07:00</published><updated>2007-09-28T02:42:39.196-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>剛灌好的Ubuntu無法調整成寬螢幕解析度怎麼辦?</title><content type='html'>通常狀況下，安裝一個915resolution即可，請將下列指令複製到終端機執行：&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;sudo apt-get install 915resolution&lt;/blockquote&gt;&lt;br /&gt;其原理等我尚不清楚，不過我安裝後都有效。&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1207786302201149220-2984224243843107361?l=bblog-tech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bblog-tech.blogspot.com/feeds/2984224243843107361/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1207786302201149220&amp;postID=2984224243843107361' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/2984224243843107361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1207786302201149220/posts/default/2984224243843107361'/><link rel='alternate' type='text/html' href='http://bblog-tech.blogspot.com/2007/05/ubuntu.html' title='剛灌好的Ubuntu無法調整成寬螢幕解析度怎麼辦?'/><author><name>Bruce</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
