どうもこの辺のエラーが出ていて困り中。

err

VC++2008 Expressで開発しているのだけれど、 ActiveScriptRubyをBuildしてる環境とバージョンが違うようだ。 もう少し様子を見ようかな。

posted by Png genki on Fri 29 Feb 2008 at 18:29

基本的にはnetstatコマンドを使えばいいのですが、 linux系とはオプションがちょっと違います。

   1  > netstat -a -o | grep 12345

上記のコマンドを実行すると、一番右端のカラムにPIDが出力されます。

posted by Png genki on Fri 29 Feb 2008 at 13:50

cmd.exeから以下のようにコマンドを実行することで、 WindowsのプロセスをIDでKillすることができます。

   1  > taskkill /PID 12345

強制終了する場合は、/Fオプションを追加します。

posted by Png genki on Fri 29 Feb 2008 at 13:47

In prototype.js, Event.observe method is very useful. But it is a bit inconvenient if you want to handle events only once such as an initialization. I have often encountered such situation, so I wrote a small utility function being as follows.

   1  Event.observeOnce = function(element, event, observer){
   2    var handler = function(){
   3      Event.stopObserving(element, event, handler);
   4      return observer.apply(null, $A(arguments));
   5    };
   6    Event.observe(element, event, handler);
   7  };

The usage is same to Event.observe.

   1  Event.observeOnce(document, 'dom:loaded', function(){
   2    /* some code goes here */
   3  });

It may be useful if you copy this into public/javascripts/application.js for Rails applications.

posted by Png takiuchi on Thu 28 Feb 2008 at 17:23

prototype.jsのEvent.observeは非常に便利なのですが、 初期化処理など、一度だけイベントの処理したい場合にはちょっと不便です。 度々そのような処理を行う機会があったので、以下のような 一度だけイベントをハンドルする関数を作ってみました。

   1  Event.observeOnce = function(element, event, observer){
   2    var handler = function(){
   3      Event.stopObserving(element, event, handler);
   4      return observer.apply(null, $A(arguments));
   5    };
   6    Event.observe(element, event, handler);
   7  };

使い方は、通常のEvent.observeと同様です。

   1  Event.observeOnce(document, 'dom:loaded', function(){
   2    /* some code goes here */
   3  });

Railsアプリケーションであれば、public/javascripts/application.js あたりに置いておくと便利かもしれません。

posted by Png genki on Thu 28 Feb 2008 at 17:04

以前は、Railsのhelperメソッドのオプションや細かい挙動を調べるために、 secondlifeさんの http://api.rails2u.com/ や、 :::ruby.search::: のお世話になることが多かったのですが、 近頃ではRailsのドキュメントを参照する機会が減ってきました。

細かい理由はいろいろあるのですが、一番大きいのは、 以前紹介したRak を使って直接Railsのソースを確認するのが便利な事です。

使い方はこんな感じです。

  • vendor/rails以下にRailsをfreezeさせます。
  • GNU screenでcd vendor/railsしたスクリーンを用意しておきます。
  • 何か調べたいときは、rak def\ method_nameを実行して、出てきたファイルをvimで読む。
  • Rtags(rails.vimの機能)でジャンプもできる。

さらに、細かい挙動やメソッドに渡ってきた値を調べたい時などは、 vendor/railsのソースにdebuggerと書き込んで、 script/server -uでデバッグモードを起動します (「Rails 2.0でデバッグをする新しいやり方」参照)

posted by Png genki on Thu 28 Feb 2008 at 13:20

apt-get install git-coreですんなり終わるかと思っていたら、 GNU Interactive Toolsというのと競合してるらしく、 以下のようなメッセージが出てきます。

   1  git, the filemanager with GNU Interactive Tools, is now called gitfm.
   2  
   3  If you are looking for git, Linus Torvald's content tracker, install
   4  the cogito and git-core packages and see README.Debian and git(7).
   5  
   6  This transition script will be removed in the debian stable
   7  release after etch.
   8  
   9  If you wish to complete the transition early, install git-core
  10  and use (as root):
  11   update-alternatives --config git
  12  
  13  Press RETURN to run gitfm

指示の通り、update-alternatives --config gitを実行すると、 今度はこんな感じのメッセージが出るので、

   1  # update-alternatives --config git
   2  
   3  There are 2 alternatives which provide `git'.
   4  
   5    Selection    Alternative
   6  -----------------------------------------------
   7  *+        1    /usr/bin/git.transition
   8            2    /usr/bin/git-scm
   9  
  10  Press enter to keep the default[*], or type selection number: 

2の/usr/bin/git-scmを選択します。

これでGitを使えるようになりました。

posted by Png genki on Thu 28 Feb 2008 at 10:13

技術評論社さま、献本ありがとうございます。

WEB+DB PRESS Vol.43
WEB+DB PRESS Vol.43
posted with amazlet on 08.02.28
WEB+DB PRESS編集部
技術評論社 (2008/02/23)
売り上げランキング: 122

今号は連載の最終回が多いですね。季節を感じる一冊です。

個人的に面白かったのは、

  • 弾さんの「Alpha Geekに逢いたい」(TwitterのEvan Williams氏)
  • masuidriveさんの「Amazon EC2&S3」(素晴らしい内容)
  • ひろせさんの「見逃さない通知の極意」

ですね。参考にさせていただきます。

posted by Png genki on Thu 28 Feb 2008 at 06:18

OpenIdAuthenticationはruby-openid1.1.4にしか対応していません。ですが、gem1.0.1では1.1.4が正しく動作しないため、プラグインにパッチをあてて使うことにしました。

  1. ruby-openidをインストール(2.0.4)

       1  gem install ruby-openid
    

  2. pluginのインストール

       1  $ ./script/plugin install http://svn.rubyonrails.org/rails/plugins/open_id_authentication/
    

  3. パッチをあてる

    • パッチを入手ticket10604.diffとして保存
      http://dev.rubyonrails.org/ticket/10604

    • プラグインのところに移動させておく

         1   #{RAILS_ROOT}/vendor/plugins/open_id_authentication/ticket10604.diff
      

    • プラグインのルートに移動して、patchを当てる

         1  $ patch -p1 < ticket10604.diff
         2  patching file init.rb
         3  Hunk #1 FAILED at 1.
         4  1 out of 1 hunk FAILED -- saving rejects to file init.rb.rej
         5  patching file lib/generators/open_id_authentication_tables/open_id_authentication_tables_generator.rb
         6  patching file lib/generators/open_id_authentication_tables/templates/migration.rb
         7  patching file lib/open_id_authentication.rb
         8  Hunk #5 succeeded at 69 with fuzz 1 (offset -2 lines).
         9  Hunk #6 succeeded at 88 (offset -2 lines).
        10  Hunk #7 succeeded at 152 (offset -2 lines).
        11  patching file lib/open_id_authentication/association.rb
        12  patching file lib/open_id_authentication/db_store.rb
        13  patching file lib/open_id_authentication/nonce.rb
        14  patching file lib/open_id_authentication/setting.rb
        15  patching file tasks/open_id_authentication_tasks.rake
        16  patching file test/normalize_test.rb
        17  patching file test/open_id_authentication_test.rb
        18  patching file test/status_test.rb
      

  4. READMEにあるExampleの作業

    • テーブル作成

         1   rake open_id_authentication:db:create 
      

    • routesに下記を加える

         1    map.open_id_complete 'session', :controller => "sessions", :action => "create", :requirements => { :method => :get }
         2    map.resource :session
      

    • SessionsController、vews/sessions/new.html.erbの作成
      ここでmatakeさんと同じようにはまったのですが、SessionConroller#open_id_authenticationをREADMEにあるresult.successful?のほうを使うとプラグインに手を入れずに使うことができます。(agilewebdevelopment.comのExampleを使うとNG)

         1      def open_id_authentication
         2        authenticate_with_open_id do |result, identity_url|
         3          if result.successful? && @current_user = @account.users.find_by_identity_url(identity_url)
         4            successful_login
         5          else
         6            failed_login(result.message || "Sorry, no user by that identity URL exists (#{identity_url})")
         7          end
         8        end
         9      end
      

  5. ruby-openidのバージョン指定をはずす

       1  #open_id_authentication/init.rb
       2  begin
       3  #  gem 'ruby-openid', '=1.1.4'
       4    gem 'ruby-openid'
    

参考

posted by Png satoko on Wed 27 Feb 2008 at 16:40

OpenIdAuthentication is depend on gem ruby-openid 1.1.4. In addition, ruby-openid 1.1.4 is broken with 1.0.1 gem :(
So, I applied patch(Ticket#10604) and they works well.

  1. Install gem ruby-openid(2.0.4)

       1  gem install ruby-openid
    

  2. Install plugin

       1  $ ./script/plugin install http://svn.rubyonrails.org/rails/plugins/open_id_authentication/
    

  3. Apply patch

    • Get a patch and save as ticket10604.diff
      http://dev.rubyonrails.org/ticket/10604

    • Move diff file to plugin root

         1   #{RAILS_ROOT}/vendor/plugins/open_id_authentication/ticket10604.diff
      

    • Move to plugin root and do patch command

         1  $ patch -p1 < ticket10604.diff
         2  patching file init.rb
         3  Hunk #1 FAILED at 1.
         4  1 out of 1 hunk FAILED -- saving rejects to file init.rb.rej
         5  patching file lib/generators/open_id_authentication_tables/open_id_authentication_tables_generator.rb
         6  patching file lib/generators/open_id_authentication_tables/templates/migration.rb
         7  patching file lib/open_id_authentication.rb
         8  Hunk #5 succeeded at 69 with fuzz 1 (offset -2 lines).
         9  Hunk #6 succeeded at 88 (offset -2 lines).
        10  Hunk #7 succeeded at 152 (offset -2 lines).
        11  patching file lib/open_id_authentication/association.rb
        12  patching file lib/open_id_authentication/db_store.rb
        13  patching file lib/open_id_authentication/nonce.rb
        14  patching file lib/open_id_authentication/setting.rb
        15  patching file tasks/open_id_authentication_tasks.rake
        16  patching file test/normalize_test.rb
        17  patching file test/open_id_authentication_test.rb
        18  patching file test/status_test.rb
      

  4. Do some work in README

    • Creating tables

         1   rake open_id_authentication:db:create 
      

    • Add some routes

         1  #config/routes.rb
         2    map.open_id_complete 'session', :controller => "sessions", :action => "create", :requirements => { :method => :get }
         3    map.resource :session
      

    • Generate SessionsController, and create vews/sessions/new.html.erb
      Tip:NOT to use sample code in agilewebdevelopment.com. Use sample code in README.

         1      def open_id_authentication
         2        authenticate_with_open_id do |result, identity_url|
         3          if result.successful? && @current_user = @account.users.find_by_identity_url(identity_url)
         4            successful_login
         5          else
         6            failed_login(result.message || "Sorry, no user by that identity URL exists (#{identity_url})")
         7          end
         8        end
         9      end
      

  5. Ommit version of ruby-openid

       1  #open_id_authentication/init.rb
       2  begin
       3  #  gem 'ruby-openid', '=1.1.4'
       4    gem 'ruby-openid'
    

posted by Png hibi on Wed 27 Feb 2008 at 16:23 with 2 comments