すんなり完了すると思ったらちょっと引っかかったのでメモ。

debian (etch) をほぼデフォルト設定で入れていたので、こんな感じに486系のkernelが入っていた。

/boot/grub/menu.lst

title           Debian GNU/Linux, kernel 2.6.18-5-486
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.18-5-486 root=/dev/sda1 ro
initrd          /boot/initrd.img-2.6.18-5-486
savedefault

これが実は曲者で、cat /proc/meminfo すると

HighTotal: 0 kB
HighFree: 0 kB

HighMemを認識してくれていない。 今回はメモリを1Gから2Gに増設したのだが、1G分しか認識してくれなかった。

そこで、686系のkernelにする事にした。

# apt-get update
# apt-get install kernel-image-2.6-686

これで再起動すると…

/proc/meminfo

HighTotal:     1114048 kB
HighFree:       692068 kB

無事に認識。ほ。

posted by Png genki on Tue 13 Nov 2007 at 06:27

RailsでWebサービスの開発を行っていると、Webサーバとfcgiプロセスをまとめて停止させたくなる事が度々あります。そんな時のために、次のようなスクリプトを書いて使っています。

script/kill

./script/process/reaper -a kill
PID=`cat tmp/pids/lighttpd.pid`
kill -9 $PID

fcgiプロセスだけ再起動させたい場合は、Rails謹製の script/process/reaper -a graceful でOKですね。

posted by Png genki on Tue 13 Nov 2007 at 01:17

地味に欲しかった機能がいつの間にか実装されていた。

takiuchi% rake -T db:create                                  [~/test]
(in /home/takiuchi/test)
rake db:create      # Create the local database defined in config/database.yml for the current RAILS_ENV
rake db:create:all  # Create all the local databases defined in config/database.yml

これで rake db:create:all と打てばdatabase.ymlに記述されているデータベースが作成されるわけですね。

posted by Png genki on Mon 12 Nov 2007 at 15:56

topコマンドは、通常CPUの使用率が高い順にプロセスを表示しますが、topコマンドを実行した状態で「Shift+M」を押すと、メモリの使用率が高い順に表示するようになります。メモリ消費量が多いプロセスを特定したい時に便利ですね。

元に戻したい場合は、「Shift+T」を押せばOK。ほかにも以下のような機能があります(topコマンド実行時に「h」キーを押せば表示されます)

  Z,B       Global: 'Z' change color mappings; 'B' disable/enable bold
  l,t,m     Toggle Summaries: 'l' load avg; 't' task/cpu stats; 'm' mem info
  1,I       Toggle SMP view: '1' single/separate states; 'I' Irix/Solaris mode

  f,o     . Fields/Columns: 'f' add or remove; 'o' change display order
  F or O  . Select sort field
  <,>     . Move sort field: '<' next col left; '>' next col right
  R,H     . Toggle: 'R' normal/reverse sort; 'H' show threads
  c,i,S   . Toggle: 'c' cmd name/line; 'i' idle tasks; 'S' cumulative time
  x,y     . Toggle highlights: 'x' sort field; 'y' running tasks
  z,b     . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')
  u       . Show specific user only
  n or #  . Set maximum tasks displayed

  k,r       Manipulate tasks: 'k' kill; 'r' renice
  d or s    Set update interval
  W         Write configuration file
  q         Quit
          ( commands shown with '.' require a visible task display window )
posted by Png genki on Mon 12 Nov 2007 at 00:56
11th Sun

Multiple-try MH

MH (Metropolis Hastings) アルゴリズムの拡張。

The Multiple-Try Method and Local Optimization in Metropolis Sampling

Jun S. Liu, Faming Liang, Wing Hung Wong Journal of the American Statistical Association, Vol. 95, No. 449 (Mar., 2000), pp. 121-134 doi:10.2307/2669532

なかなか楽しそう。

posted by Png genki on Sun 11 Nov 2007 at 07:46

Rails 2.0: Release Candidate 1

We’ve been taking our sweet time, but now it really is almost there. We’ve just pushed new beta gems to gems.rubyonrails.org and created the rel_2-0-0_RC1 tag. So this is shaping up to be the last chance to raise concerns for Rails 2.0 before we go final in oh-so-shortly.

早速このblogをRails-2.0 RC1 (r.8125)仕様にしてみましたが、もともとEdge Rails (r.7357) で動いていたので、特になにも修正をしなくても移行できました。

詳しい情報は、諸橋さんが こちら にまとめてくださっています。

posted by Png genki on Sat 10 Nov 2007 at 10:03

友人の藤田さんが主催しているレンダリング・アルゴリズムのイベント、 「SBR 2007 観覧会」が本日恵比寿にて開催されるので、参加してきます。

今年も様々な論文が出ていますが、個人的に気になっているのは、Benjamin Segoviaによる2つ

Eric VeachのMLTに感銘を受けたクチなので、Multiple-Try MHに興味があります。

cmlt

posted by Png genki on Sat 10 Nov 2007 at 09:02

だいぶ前に少し試したきり放置していたのだけれど、このところ知人の間で急速に広まっている気がします。

この勢いは、Twitterが出始めた時に似たものを感じますね。

ちなみに僕のページはこちらです。

日比さんが会社のページも作ってくれた。

posted by Png genki on Thu 8 Nov 2007 at 23:57

acts_as_taggable_on_steroids はacts_as_taggableを強化したRailsプラグインで、非常に便利なので愛用しています。

しかし、find_tagged_withメソッドで OR を含む :conditions を指定すると、SQLの演算順序の問題で挙動がおかしくなります。 この問題を修正するには、以下のようにpluginコードを書き換えればOKです。

acts_as_taggable_on_steroids/lib/acts_as_taggable.rb

    def find_options_for_find_tagged_with(tags, options = {})
      tags = tags.is_a?(Array) ? TagList.new(tags.map(&:to_s)) : TagList.from(tags)
      options = options.dup

      return {} if tags.empty?

      conditions = []
      #conditions << sanitize_sql(options.delete(:conditions)) if options[:conditions]
      if options[:conditions]
        conditions << "(#{sanitize_sql(options.delete(:conditions))})"
      end

要は、オリジナルの :conditions を括弧で括って演算順序の問題が起きないようにしているわけですね。

posted by Png genki on Mon 5 Nov 2007 at 17:02

Railsの設定は、config/environment.rbのなかで、

Rails::Initializer.run do |config|
  # Settings in config/environments/* take precedence over those specified here
  config.log_level = :debug

というような感じに記述します。

アプリケーション側からここで設定した値を参照したいという場合に、その方法が提供されている気がしたので、Rails::Initializerのソースを探してみたのですが、そのような手段は用意されていないようでした。

Railsのコアを書き換えるプラグインを書こうかと思ったのですが、ふと以下のように書けば問題が解決することに気がつきました。

Rails::Initializer.run do |config| $rails_config = config

あとはどこからでも、グローバル変数の$rails_configを介して、Railsの設定情報にアクセスすることが出来ます。

posted by Png genki on Mon 5 Nov 2007 at 16:27