Sketches 是個很有趣的工具,它讓你可以在 irb 中打開你最愛的文字編輯器直接編輯,然後無需重開 irb 環境就可以使用。

首先是安裝:

sudo gem install sketches

然後編輯你的 ~/.irbrc 檔案,加上:

require ’sketches’
Sketches.config :editor => ‘mate’

接著在 irb 裡面就可以:

sketch 就會打開你的編輯器,存檔之後就可以使用。
sketches 會列出曾經編輯過的記錄
name_sketch 可以命名這些記錄
save_sketch 則可以存成檔案

不過有個缺點是 local variable 區域變數是讀不到的,不過我想最常用的方式是打開編輯器寫一些類別跟函式定義 :)

如果你還是不知道這是怎麼回事,可以看看 RubyPulse 的示範。

突然想到,上課用來 live demo 似乎非常適合 :p

Update(2010/2/10): 這場的投影片和 Distributed Ruby and Rails 那場一樣 :)

Ruby Tuesday 今年的第一場聚會,由 godfat 和我帶來 EventMachine 和 Distributed Ruby&Background-Processing in Rails 兩場演講。

EventMachine 是一套使用 Reactor pattern 的 event-driven I/O 函式庫,你可以在許多 Ruby networking 工具發現它的蹤跡,像是 Thinstarlingamqpcramp

我的部份則是將上次在中研院的題目 Distributed Ruby and Rails 中的 Distributed Ruby 和 Background-Processing in Rails 這兩個準備比較完整的部分拿出來分享。

時間: 2010/2/9(週二)晚上七點到九點。

地點: 台北市 果子咖啡

報名網頁: http://registrano.com/events/ruby-tuesday-201002

中研院OSSF工作坊邀請,這次很有野心的挑戰這個題目,試圖涵蓋 Ruby 生態圈中,有關分散式 Ruby 程式設計和 Ruby on Rails 架構的相關內容:

  • Distributed Ruby
    • DRb
    • Rinda
    • Starfish
    • MapReduce
    • MagLev VM
  • Distributed Message Queues
    • Starling
    • AMQP/RabbitMQ
    • Stomp/ActiveMQ
    • beanstalkd
  • Background-processing in Rails
    • script/runner
    • rake
    • cron
    • daemon
    • run_later plugin
    • spawn plugin
  • Message Queues for Rails
    • ar_mailer
    • BackgroundDRb
    • workling
    • delayed_job
    • resque
  • SOA for Rails
    • What’s SOA
    • Why SOA
    • Considerations
    • The tool set
  • Distributed Filesystem
  • Distributed database

訂出這麼大的 Agenda 範圍,自己也嚇了一跳,簡直就是差點準備不完。像是 RabbitMQ、MagLev VM、XMPP、MapReduce、SOA 等我還希望可以準備些實際的程式範例。本來預定一個小時的演講,最後也膨脹到快兩個小時才講的完。

Anyway,這是最後的投影片了,相信你也可以獲得這個領域的大局觀。之後有機會我會繼續分享更多實作經驗。

不像 Apache 預設已經設定好了,會定期整理成 access.log.1, access.log.2.gz, access.log.3.gz 等,如果你沒特別處理,Rails 底下的 log 檔案可是越長越肥。

這個系統工具是 logrotate,它的設定檔在 /etc/logrotate.conf,設定的方式還真是簡單 (參考自 Rotating Rails Log Files):


# Rotate Rails application logs
/path/to/your/rails/current/log/*.log {
  daily
  missingok
  rotate 7
  compress
  delaycompress
  notifempty
  copytruncate
}

其中 daily 表示每天整理,也可以改成 weekly 或 monthly
missingok 表示如果找不到 log 檔也沒關係
rotate 7 表示保留七份
compress 表示壓縮起來,預設用 gzip
delaycompress 表示延後壓縮直到下一次 rotate
notifempty 表示如果 log 檔是空的,就不 rotate
copytruncate 先複製 log 檔的內容後,在清空的作法,因為有些程式一定 log 在本來的檔名,例如 rails。另一種方法是 create。

設定好之後,可以等明天,或是執行 /usr/sbin/logrotate -f /etc/logrotate.conf 看看。