From yesterday to this morning, we had set up two MySQL servers as master-to-master configuration.

One server is located in Tokyo, the other is in Shiga. They are replicated each other in order to get our system redundant and load-balanced. We had used OpenVPN for this purpose. It is very easy to setup by using tunnelling.

Okey, we agree with that the VPN will become the neck of a bottle if our network get heavy traffic. But fortunately or unfortunately, it is not so heavy. So we considered that a performance issue would be still no problem, against a stability issue.

posted by Png genki on Tue 26 Feb 2008 at 08:13

http://tinyurl.com/を見て気がついたのですが、paypalのほかにAmazon Honor Systemというのもあるようです。

手軽なマネタイズ方法としてつけることも検討してみよう

posted by Png satoko on Tue 26 Feb 2008 at 07:38

下記URLから入手できます。
http://svn.s21g.com/public/rails/plugins/tinyurl_helper/

仕様

URLを渡すとTinyURLに変換してリンクを作ります。

使い方

  • application_helper.rbでinclude
       1  module ApplicationHelper
       2    include TinyurlHelper
       3  end
    
  • View内で
       1  <%= link_to_tinyurl "http://www.yahoo.co.jp" %>
    

作り方

  1. 類似するプラグインを探してコーディングの検討をつける
  2. script/generateする
       1  script/generate plugin tinyurl_helper
    
  3. 上で生成されたlib/tinyurl_helper.rbを編集
       1  require 'net/http'
       2  
       3  module TinyurlHelper
       4    def link_to_tinyurl(url, html_options = nil)
       5      uri = 'http://tinyurl.com/api-create.php?url=' + url
       6      uri = URI.parse(uri)
       7      tiny_url = Net::HTTP.get_response(uri).body
       8      options = {:title => url, :alt => url}
       9      options = html_options.nil? ? options : options.merge(html_options)
      10      link_to tiny_url, tiny_url, options
      11    end
      12  end
    
  4. テストを書く(アプリテスト、プラグイン単体テスト両方通るように書くと吉)

       1  -
       2  require 'test/unit'
       3  require File.expand_path(File.dirname(__FILE__) + "/../lib/tinyurl_helper")
       4  
       5  class TinyurlHelperTest < Test::Unit::TestCase
       6    include TinyurlHelper
       7  
       8    #dummy link_to
       9    def link_to(name, options = {}, html_options = nil)
      10      [name, html_options[:title]]
      11    end
      12  
      13    def test_link_to_tinyurl
      14      url = 'http://www.yahoo.co.jp/'
      15      tiny_url, title = link_to_tinyurl(url)
      16      assert_equal 'http://tinyurl.com/910', tiny_url
      17      assert_equal url, title
      18    end
      19  
      20    def test_link_to_tinyurl_with_title
      21      url = 'http://www.yahoo.co.jp/'
      22      tiny_url, title = link_to_tinyurl(url, {:title => 'title'})
      23      assert_equal 'http://tinyurl.com/910', tiny_url
      24      assert_equal 'title', title
      25    end
      26  end
    

  5. README, MIT-LICENSEを書く

    • READMEは名前と、概要・使い方を書く
    • MIT-LICENSEは名前だけ変更
  6. 公開用リポジトリにコミット

  7. pluginディレクトリに登録する

Tips

  • プラグインはweb serverを再起動しないとリロードされない
  • helperを使えるようにする方法は2つ
    1. app/helper/application_helper.rbでinclude(上でやった方法)
    2. plugins/tinyurl_helper/init.rbでsendする
         1   ActionView::Base.send :include, TinyurlHelper
      
posted by Png satoko on Tue 26 Feb 2008 at 05:12

今年の目標に、railsのプラグインを作るというのがあるのですが、時間ができたらと言わずに「さっさと/ささっと作れ」という助言をもらったのでささっとやってみました。まずはどいういうものかという初歩的なところから。

Pluginディレクトリ

ここに多く集められています。
http://agilewebdevelopment.com/plugins

様々な種類のプラグイン

プラグインはRailsの機能拡張するものなのですが、下記のように分類できます。

  • Helper系
  • Model/Controller系
    • acts_as_なんとかという名前が多い
      ex. acts_as_taggable
  • Generator系
  • その他
    • 上記のmix
      ex. acts_as_authenticated => model/controller拡張, generator
    • rake taskを作るもの
      ex. annotate_models

作り方how-to

問題

  • プラグインのテスト、アプリのテスト両方のテストを通すようにtestを書くのが煩雑。
  • プラグインの更新を適用するのが面倒
    (gemのように簡単に最新にならないので、手動で削除、再インストールが必要)
posted by Png satoko on Mon 25 Feb 2008 at 13:31

イベントのお知らせです。

OoO(Offline meeting for Offline renderists)

いちおう今回のメインテーマはあって、それは OoO をオンラインでフォローするための、ompf のオフラインレンダラ版フォーラムを RoR で作ろうというものです.作っていただける方はいるので、それにときどき意見を出すみたいな。

まあでもその一方で、 MLT の実装とか, 論文書くとかしてても OK.

スライド作成が間に合えば、世界初、日本でしか聞けない(<- これ大事)、MUDA のプレゼンとかするかも.

ということで、僕は作る人として参加します。 Offline Renderingについて熱く語りましょう。

posted by Png genki on Sat 23 Feb 2008 at 02:57

このブログの背景画像を設定は、 以下のような感じのCSSで中寄せしているのですが、 これがなぜか、OperaとSafariでは右側に1 pixelずれてしまいます。

   1  html {
   2    background: #DCDCDC url(/images/bg.gif) top center repeat-y
   3  }

しょうがないので、サーバサイドでそのようなブラウザを検出して、 中寄せしているBlock要素の左側に、以下のように1 pixelだけ paddingを入れています。

   1  #base.center-fix {padding: 0px 0px 0px 1px}

こういう微妙な挙動の違いは、acidテストのような見た目で判断する テストではわかりにくいのかもしれないですね。

posted by Png genki on Fri 22 Feb 2008 at 03:55

少し前になりますが、このブログでHatenaStarを使えるようにしました。 記事の右下の署名のところに表示されています。

このブログシステムでは、デフォルトの挙動だと、タイトルの右側に出てしまうので、以下のようなカスタムローダを使っています。

   1  document.observe('dom:loaded', function(){
   2    Hatena.Star.EntryLoader.loadEntries = function(){
   3      return #{entries.to_json}.map(function(entry){
   4        var star = $(['article_star_', entry[2]].join(''));
   5        return {uri: entry[0], title: entry[1],
   6          star_container: star, comment_container: star};
   7      });
   8    };
   9  });

loadEntriesはElementオブジェクト含む配列のリストを返す 必要があるのですが、これはPrototype.jsの$()関数のように、 ElementでもElement IDの文字列でも両方 受け取れるようにしたら、もっと便利かも。

posted by Png genki on Fri 22 Feb 2008 at 03:42

今日、Skypeチャットルームで話されてたんだけど、「digg is really one-day fly spike」(Diggは一日だけの急上昇飛行)なんだそう。もしかしてはてぶそうなのかもですね。今まではなんとなくブックマークサービスとしてだけ見ていましたが、ユーザーの使い方がDiggぽいといえばDiggぽい。だのにブックマークサービスだから、議論とかがしにくい。

ユニークな見方をもらいました。

posted by Png satoko on Tue 19 Feb 2008 at 11:04

今回は、Railsアプリケーションに、Undo/Redo機能を追加する プラグインの紹介です。

What is RUR (Rails Undo Redo)

RUR (Rails-Undo-Redo) is a rails plugin (and soon a gem as well) to make it so easy to implement multi-level undo redo in your Rails application that you better start thinking of better excuses not to implement Undo/Redo (no, seriously, it is going to be a lot easier).

これはなかなか面白いプラグインですね。後で使ってみよう。

posted by Png genki on Tue 19 Feb 2008 at 01:27

2/13のIE7のWindows Updateの影響か、 2006年の6/12(1年半ぐらい前)に書いた記事 IE7からIE6に戻す方法 のアクセス数が増えていた。

当時は、ブラウザの互換性のためにIE7のベータ版をインストールした後に 元に戻す方法を調べて書いていたのでした。 今になって参照されるというのも面白いですね。

posted by Png genki on Mon 18 Feb 2008 at 09:23