Ruby Version Manager(RVM) を使って Mac OSX Snow Leopard にRuby 1.9 をインストールする

前回の失敗を踏まえてRuby Version Manager(RVM)をつかってMacRuby 1.9の導入を試みる

RVMはgem を使ってもインストールすることが出来るようだが、いまいちやり方が分からなかったのでgitを使ってソースを取ってくる

$ git clone git://github.com/wayneeseguin/rvm.git
$ cd rvm/
$ ./install

.bashrcの最後のほうに以下を追加

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.

でターミナルを再起動

$ rvm -v
rvm 1.1.6 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]
$ rvm info
system:
  system:
    uname:       "Darwin mksc-no-mac-pro-2.local 10.5.0 Darwin Kernel Version 10.5.0: Fri Nov  5 23:20:39 PDT 2010; root:xnu-1504.9.17~1/RELEASE_I386 i386"
    bash:        "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)"
    zsh:         "/bin/zsh => zsh 4.3.9 (i386-apple-darwin10.0)"
  rvm:
    version:      "rvm 1.1.6 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]"
  homes:
    gem:          "not set"
    ruby:         "not set"
  binaries:
    ruby:         "/opt/local/bin/ruby"
    irb:          "/opt/local/bin/irb"
    gem:          "/opt/local/bin/gem"
    rake:         "/opt/local/bin/rake"
  environment:
    PATH:         "/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/shimizu/bin:/Users/shimizu/.rvm/bin:/Users/shimizu/.rvm/bin"
    GEM_HOME:     ""
    GEM_PATH:     ""
    MY_RUBY_HOME: ""
    IRBRC:        ""
    RUBYOPT:      ""
    gemset:       ""

インストールは成功している模様

サポートしている環境を一覧する

$ rvm list known_strings
ruby-head
ruby-1.9.2-rc2
ruby-1.9.2-rc1
ruby-1.9.2-preview3
ruby-1.9.2-preview1
ruby-1.9.2-p0
ruby-1.9.2-head
ruby-1.9.1-p429
ruby-1.9.1-p378
ruby-1.9.1-p243
ruby-1.9.1-head
ruby-1.8.7-p302
ruby-1.8.7-head
ruby-1.8.6-p399
ruby-1.8.6-head
ree-1.8.7-head
ree-1.8.7
ree-1.8.6-head
ree-1.8.6
rbx-head
rbx-1.1.1
rbx-1.1.0
rbx-1.0.1
maglev-head
maglev-24864
macruby-nightly
macruby-head      
macruby-0.8 
jruby-head
jruby-1.5.6
jruby-1.4.0
jruby-1.3.1
jruby-1.2.0
ironruby-head
ironruby-1.0-rc2
ironruby-0.9.3
goruby

Rubyのページの一番普通にDLできるバージョンが1.9.2-p0 なのでそれをインストールする

$ rvm install 1.9.2-p0
/Users/shimizu/.rvm/rubies/ruby-1.9.2-p0, this may take a while depending on your cpu(s)...

ruby-1.9.2-p0 - #fetching 
ruby-1.9.2-p0 - #downloading ruby-1.9.2-p0, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 8296k  100 8296k    0     0  1743k      0  0:00:04  0:00:04 --:--:-- 2036k
ruby-1.9.2-p0 - #extracting ruby-1.9.2-p0 to /Users/shimizu/.rvm/src/ruby-1.9.2-p0
ruby-1.9.2-p0 - #extracted to /Users/shimizu/.rvm/src/ruby-1.9.2-p0
ruby-1.9.2-p0 - #configuring 
ruby-1.9.2-p0 - #compiling 
ruby-1.9.2-p0 - #installing 
ruby-1.9.2-p0 - updating #rubygems for /Users/shimizu/.rvm/gems/ruby-1.9.2-p0@global
ruby-1.9.2-p0 - updating #rubygems for /Users/shimizu/.rvm/gems/ruby-1.9.2-p0
ruby-1.9.2-p0 - adjusting #shebangs for (gem).
ruby-1.9.2-p0 - #importing default gemsets (/Users/shimizu/.rvm/gemsets/)
Install of ruby-1.9.2-p0 - #complete 
$ rvm info

system:

  system:
    uname:       "Darwin mksc-no-mac-pro-2.local 10.5.0 Darwin Kernel Version 10.5.0: Fri Nov  5 23:20:39 PDT 2010; root:xnu-1504.9.17~1/RELEASE_I386 i386"
    bash:        "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)"
    zsh:         "/bin/zsh => zsh 4.3.9 (i386-apple-darwin10.0)"

  rvm:
    version:      "rvm 1.1.6 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]"

  homes:
    gem:          "not set"
    ruby:         "not set"

  binaries:
    ruby:         "/opt/local/bin/ruby"
    irb:          "/opt/local/bin/irb"
    gem:          "/opt/local/bin/gem"
    rake:         "/opt/local/bin/rake"

  environment:
    PATH:         "/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/shimizu/bin:/Users/shimizu/.rvm/bin:/Users/shimizu/.rvm/bin"
    GEM_HOME:     ""
    GEM_PATH:     ""
    MY_RUBY_HOME: ""
    IRBRC:        ""
    RUBYOPT:      ""
    gemset:       ""
$ which ruby
/opt/local/bin/ruby
$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]
$ rvm use 1.9.2
Using /Users/shimizu/.rvm/gems/ruby-1.9.2-p0$ rvm info

ruby-1.9.2-p0:

  system:
    uname:       "Darwin mksc-no-mac-pro-2.local 10.5.0 Darwin Kernel Version 10.5.0: Fri Nov  5 23:20:39 PDT 2010; root:xnu-1504.9.17~1/RELEASE_I386 i386"
    bash:        "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)"
    zsh:         "/bin/zsh => zsh 4.3.9 (i386-apple-darwin10.0)"

  rvm:
    version:      "rvm 1.1.6 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]"

  ruby:
    interpreter:  "ruby"
    version:      "1.9.2p0"
    date:         "2010-08-18"
    platform:     "x86_64-darwin10.5.0"
    patchlevel:   "2010-08-18 revision 29036"
    full_version: "ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.5.0]"

  homes:
    gem:          "/Users/shimizu/.rvm/gems/ruby-1.9.2-p0"
    ruby:         "/Users/shimizu/.rvm/rubies/ruby-1.9.2-p0"

  binaries:
    ruby:         "/Users/shimizu/.rvm/rubies/ruby-1.9.2-p0/bin/ruby"
    irb:          "/Users/shimizu/.rvm/rubies/ruby-1.9.2-p0/bin/irb"
    gem:          "/Users/shimizu/.rvm/rubies/ruby-1.9.2-p0/bin/gem"
    rake:         "/Users/shimizu/.rvm/gems/ruby-1.9.2-p0/bin/rake"

  environment:
    PATH:         "/Users/shimizu/.rvm/gems/ruby-1.9.2-p0/bin:/Users/shimizu/.rvm/gems/ruby-1.9.2-p0@global/bin:/Users/shimizu/.rvm/rubies/ruby-1.9.2-p0/bin:/Users/shimizu/.rvm/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/shimizu/bin"
    GEM_HOME:     "/Users/shimizu/.rvm/gems/ruby-1.9.2-p0"
    GEM_PATH:     "/Users/shimizu/.rvm/gems/ruby-1.9.2-p0:/Users/shimizu/.rvm/gems/ruby-1.9.2-p0@global"
    MY_RUBY_HOME: "/Users/shimizu/.rvm/rubies/ruby-1.9.2-p0"
    IRBRC:        "/Users/shimizu/.rvm/rubies/ruby-1.9.2-p0/.irbrc"
    RUBYOPT:      ""
    gemset:       ""
$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.5.0]
$ gem -v
1.3.7
$ which gem
/Users/shimizu/.rvm/rubies/ruby-1.9.2-p0/bin/gem

おお!できたっぽい。

今後メインを1.9.2-p0にしたいので .bashrcに

rvm use 1.9.2-p0 > /dev/null

を追加する。

railsのインストール。gem はユーザー配下にインストールされるので一般ユーザーでインストー

$ gem install rails
$ rails -v
Rails 3.0.3

参考にさせて頂いたサイト
http://runeleaf.wordpress.com/2010/02/07/ruby-rvm%E3%81%A7ruby%E3%81%A8%E3%81%8Bgem%E3%81%A8%E3%81%8Brake%E3%81%A8%E3%81%8B%E3%81%AE%E3%83%90%E3%83%BC%E3%82%B8%E3%83%A7%E3%83%B3%E5%88%87%E3%82%8A%E6%9B%BF%E3%81%88/

iPhone OS のPDF表示APIのバグ

iPhoneOSのPDF表示APIを触っていたところバグに遭遇した。

再現コードはこんな感じ

CFURLRef url
= CFURLCreateWithFileSystemPath(NULL,
	(CFStringRef)filePath_,
	kCFURLPOSIXPathStyle,
	0);
CGPDFDocumentRef doc = CGPDFDocumentCreateWithURL(url);
CFRelease(url);
if(!doc)return;
CGPDFPageRef page = CGPDFDocumentGetPage(doc, 1); //ここで1ページ目を取得
NSLog(@"page address:0x%x", page); //Logを出しておく
CGPDFPageRelease(page); //リリース
CGPDFPageRef page2 = CGPDFDocumentGetPage(doc, 1); //ここで1ページ目をもう一回取得

//ここで出力した内容が上のログと同じアドレス
//つまりRelease をしたにも関わらず、
//キャッシュしている同じアドレスを示す
NSLog(@"page address:0x%x", page); 

//ここでpage2を使うと落ちる 
CGRect aRect = CGPDFPageGetBoxRect (page2, kCGPDFCropBox);


下記のページ
Life is beautiful: iPadアプリ作成日誌: PDF関連APIのバグについて
http://satoshi.blogs.com/life/2010/05/ipad%E3%82%A2%E3%83%97%E3%83%AA%E4%BD%9C%E6%88%90%E6%97%A5%E8%AA%8C-pdf%E9%96%A2%E9%80%A3api%E3%81%AE%E3%83%90%E3%82%B0%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6.html

でCGPDFPageRef をキャッシュしているみたいという事なので恐らく同じバグと思われる。
対策方法はやはり、CGPDFDocumentRefを毎回開放するという事みたい。

はてなダイアリー使いづらい→づらくない

ブログにRetweet 機能が無い事に気づいたので実装しようと思ったのだが駄目だった。

Retweetボタンの実装自体は簡単で、

<a href="http://twitter.com?status=書き込みたいコメントUTF8をBASE64エンコードした文字列">Retweet</a>

を記事に埋め込むだけで良いのだが、

実装しようとした所

各記事のフッダーHTMLを編集して<a> を書き込む

はてなダイアリーでは各記事のスタイルを編集することはできず、HTMLを直接編集できるのはヘッダーとフッダーのみ

じゃあJQueryとかを使って、クライアントサイドで記事のフッダーに動的に<a> を追加する

Javascriptは使えない

うぜー

毎回手作業で、Retweetボタンをタグ直打ちで書き込むと言う方法もあるが、同じコードは二度書かないというプログラミングの原則から外れているので却下。
というわけで方法は

せっかく調べたのでRetweetリンクでも貼っておく
この記事をRetweet

2011/2/27
追伸
いつの間にか対応してくれたみたい。
ヨカッタヨカッタ

ニコニコ動画に自動ログインする Greasemonkey スクリプト

ニコニコ動画の動画がWebサイト等で紹介されているときに、ログイン画面がいちいち出てきてうざいので、自動でログインするGreasemonkeyスクリプトを探していたら、
marvelous.zip さんのブログでちょうどそれっぽいのを発見した。
http://blog.livedoor.jp/marvelous_zip/archives/1159269.html

marvelous.zip さんのスクリプトだと、一回だけクリックしないといけないのでそこを改造して以下のスクリプトを作った

// ==UserScript==
// @name           niconico autologin
// @namespace      niconico_autologin
// @description    ニコニコ動画に自動でログインします。
// @include        http://www.nicovideo.jp/watch/*
// @include        https://secure.nicovideo.jp/secure/login_form*
// ==/UserScript==
var email = "メールアドレス";
var pass = "パスワード";
if(document.getElementById("login") && ! document.getElementById("login").innerHTML.match("ログイン情報が間違っています")){
  document.getElementById("mail").value = email;
  document.getElementById("password").value = pass;
  document.getElementById("login").submit();
}
else{
  if(document.URL.match(/^https\:\/\/secure\.nicovideo\.jp\/secure\/login_form\?/)){
    document.getElementByID("mail").value = email;
    document.getElementByID("password").value = pass;
    document.getElementByID("login_submit").submit();
  }
  else{
    var as = document.getElementsByTagName("a");
    for(i=0;i<as.length;i++){
      if(as[i].href.match(/^https\:\/\/secure\.nicovideo\.jp\/secure\/login_form\?/)){
        location.href = as[i].href;
        break;
      }
    }
  }
}

便利!!

下に直接DLできるようにしておく(リンクが死んでたので直しました)
https://github.com/katsusuke/niconico-autologin/raw/master/niconico-autologin.user.js

Ruby1.9をMac Portsで入れる

Rails3 もリリースされた事なので Ruby1.9xをMac Portでインストールしてみる。
前回何らかの理由でRuby 1.9Mac Portで入れるのは断念したのだが、理由が何故だったか忘れたので再び入れることにする(gem周りだった気がするが、忘れた)

$ sudo port selfupdate
$ sudo port upgrade installed
$ sudo port install ruby19
--->  Computing dependencies for ruby19
--->  Dependencies to be installed: libyaml
--->  Fetching libyaml
--->  Attempting to fetch yaml-0.1.3.tar.gz from http://distfiles.macports.org/libyaml
--->  Verifying checksum(s) for libyaml
--->  Extracting libyaml
--->  Configuring libyaml
--->  Building libyaml
--->  Staging libyaml into destroot
--->  Installing libyaml @0.1.3_0
--->  Activating libyaml @0.1.3_0
--->  Cleaning libyaml
--->  Fetching ruby19
--->  Attempting to fetch ruby-1.9.2-p0.tar.bz2 from ftp://ftp.iij.ad.jp/pub/lang/ruby/1.9
--->  Verifying checksum(s) for ruby19
--->  Extracting ruby19
--->  Applying patches to ruby19
--->  Configuring ruby19
--->  Building ruby19
--->  Staging ruby19 into destroot
--->  Installing ruby19 @1.9.2-p0_2
--->  Activating ruby19 @1.9.2-p0_2
--->  Cleaning ruby19
$ ruby1.9 -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10]
$ gem1.9 -v
1.3.7

ついでにGemでRailsも入れてみる。
どうなるんだろう・・・・ドキドキ

$ gem1.9 list

*** LOCAL GEMS ***

minitest (1.6.0)
rake (0.8.7)
rdoc (2.5.8)

ちなみにgem1.9 のリストは gem のリストと違った結果を返しているので、インストール先は別と思われる。

$ sudo gem1.9 install rails
Password:
Successfully installed activesupport-3.0.0
Successfully installed builder-2.1.2
Successfully installed i18n-0.4.1
Successfully installed activemodel-3.0.0
Successfully installed rack-1.2.1
Successfully installed rack-test-0.5.4
Successfully installed rack-mount-0.6.13
Successfully installed tzinfo-0.3.23
Successfully installed abstract-1.0.0
Successfully installed erubis-2.6.6
Successfully installed actionpack-3.0.0
Successfully installed arel-1.0.1
Successfully installed activerecord-3.0.0
Successfully installed activeresource-3.0.0
Successfully installed mime-types-1.16
Successfully installed polyglot-0.3.1
Successfully installed treetop-1.4.8
Successfully installed mail-2.2.5
Successfully installed actionmailer-3.0.0
Successfully installed thor-0.14.0
Successfully installed railties-3.0.0
Successfully installed bundler-1.0.0
Successfully installed rails-3.0.0
23 gems installed
Installing ri documentation for activesupport-3.0.0...
Installing ri documentation for builder-2.1.2...
Installing ri documentation for i18n-0.4.1...
Installing ri documentation for activemodel-3.0.0...
Installing ri documentation for rack-1.2.1...
Installing ri documentation for rack-test-0.5.4...
Installing ri documentation for rack-mount-0.6.13...
Installing ri documentation for tzinfo-0.3.23...
Installing ri documentation for abstract-1.0.0...
Installing ri documentation for erubis-2.6.6...
Installing ri documentation for actionpack-3.0.0...
Installing ri documentation for arel-1.0.1...
Installing ri documentation for activerecord-3.0.0...
Installing ri documentation for activeresource-3.0.0...
Installing ri documentation for mime-types-1.16...
Installing ri documentation for polyglot-0.3.1...
Installing ri documentation for treetop-1.4.8...
Installing ri documentation for mail-2.2.5...
Installing ri documentation for actionmailer-3.0.0...
Installing ri documentation for thor-0.14.0...
Installing ri documentation for railties-3.0.0...
Installing ri documentation for bundler-1.0.0...
Installing ri documentation for rails-3.0.0...
Installing RDoc documentation for activesupport-3.0.0...
Installing RDoc documentation for builder-2.1.2...
Installing RDoc documentation for i18n-0.4.1...
Installing RDoc documentation for activemodel-3.0.0...
Installing RDoc documentation for rack-1.2.1...
Installing RDoc documentation for rack-test-0.5.4...
Installing RDoc documentation for rack-mount-0.6.13...
Installing RDoc documentation for tzinfo-0.3.23...
Installing RDoc documentation for abstract-1.0.0...
Installing RDoc documentation for erubis-2.6.6...
Installing RDoc documentation for actionpack-3.0.0...
Installing RDoc documentation for arel-1.0.1...
Installing RDoc documentation for activerecord-3.0.0...
Installing RDoc documentation for activeresource-3.0.0...
Installing RDoc documentation for mime-types-1.16...
Installing RDoc documentation for polyglot-0.3.1...
Installing RDoc documentation for treetop-1.4.8...
Installing RDoc documentation for mail-2.2.5...
Installing RDoc documentation for actionmailer-3.0.0...
Installing RDoc documentation for thor-0.14.0...
Installing RDoc documentation for railties-3.0.0...
Installing RDoc documentation for bundler-1.0.0...
Installing RDoc documentation for rails-3.0.0...

$ which -a rails
/opt/local/bin/rails
$ rails -v
Rails 3.0.0

ありゃ??Ruby1.8.7 のgem でインストールしたrails はどこいった??
これは困った

$ find /opt/local/ -name rails
/opt/local/bin/rails
/opt/local/lib/ruby/gems/1.8/gems/rails-2.3.8/bin/rails
/opt/local/lib/ruby/gems/1.8/gems/rails-2.3.8/builtin/rails_info/rails
/opt/local/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails
/opt/local/lib/ruby1.9/gems/1.9.1/doc/actionmailer-3.0.0/rdoc/lib/rails
/opt/local/lib/ruby1.9/gems/1.9.1/doc/activerecord-3.0.0/rdoc/lib/rails
/opt/local/lib/ruby1.9/gems/1.9.1/gems/actionmailer-3.0.0/lib/rails
/opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.0.0/lib/rails
/opt/local/lib/ruby1.9/gems/1.9.1/gems/rails-3.0.0/bin/rails
/opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.0.0/lib/rails
/opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.0.0/lib/rails/generators/rails
/opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.0.0/lib/rails/generators/rails/app/templates/script/rails

gem は見つけたが...
どうしよう...

とりあえずgem1.9 のgems を全てアンインストールして、Mac Port のruby19 もuninstall
その後 rails3 だけをruby1.8.7 環境にインストールした。

なんじゃそりゃ

教訓:前回駄目だったことは理由に関わらず今回もダメ

追記
RVM(Ruby Version Manager)をインストールすれば行けそう。
再トライ予定

はてなに登録したらブログを作らされた。

ついでなのでブログを書いていこうかと思う。

以下はてな記法のテスト

  • リスト
  • リスト2
  1. 番号付きリスト
  2. 番号付きリスト
テーブルってこうか? 2列目
1-2 2-2