sou's blog

落ち着いた華やかさがあり、上品に明るく陽気なさまを表す。

Windows環境でのRedmine構築手順

ここの記事を参考にさせて頂き、バージョンを指定しながら構築する手順

構築する環境

Ruby

Rails

  • rails2.3.11

Redmine

  • redmine1.2.0

DB

  • sqlite3

RubyGems

Rubyのインストール

ここから1.8.7系をダウンロードし、インストールする。
(途中で、環境変数にパスを通すか、拡張子を紐付けるかといったチェックボックスが出てくるのでどちらもチェックしておく)
コマンドプロンプトで正しくインストールされていることを確認。

$ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]

$gem -v
1.5.2

Railsのインストール

$gem install rails -v 2.3.11
Fetching: rake-0.9.2.gem (100%)
Fetching: activesupport-2.3.11.gem (100%)
Fetching: activerecord-2.3.11.gem (100%)
Fetching: rack-1.1.2.gem (100%)
Fetching: actionpack-2.3.11.gem (100%)
Fetching: actionmailer-2.3.11.gem (100%)
Fetching: activeresource-2.3.11.gem (100%)
Fetching: rails-2.3.11.gem (100%)
Successfully installed rake-0.9.2
Successfully installed activesupport-2.3.11
Successfully installed activerecord-2.3.11
Successfully installed rack-1.1.2
Successfully installed actionpack-2.3.11
Successfully installed actionmailer-2.3.11
Successfully installed activeresource-2.3.11
Successfully installed rails-2.3.11
8 gems installed
Installing ri documentation for rake-0.9.2...
Installing ri documentation for activesupport-2.3.11...
Installing ri documentation for activerecord-2.3.11...
Installing ri documentation for rack-1.1.2...
Installing ri documentation for actionpack-2.3.11...
Installing ri documentation for actionmailer-2.3.11...
Installing ri documentation for activeresource-2.3.11...
Installing ri documentation for rails-2.3.11...
Installing RDoc documentation for rake-0.9.2...
Installing RDoc documentation for activesupport-2.3.11...
Installing RDoc documentation for activerecord-2.3.11...
Installing RDoc documentation for rack-1.1.2...
Installing RDoc documentation for actionpack-2.3.11...
Installing RDoc documentation for actionmailer-2.3.11...
Installing RDoc documentation for activeresource-2.3.11...
Installing RDoc documentation for rails-2.3.11...

$rails -v
Rails 2.3.11

rakeのダウングレード

$gem uninstall rake
Remove executables:
        rake

in addition to the gem? [Yn]  y
Removing rake

You have requested to uninstall the gem:
        rake-0.9.2
rails-2.3.11 depends on [rake (>= 0.8.3)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn]  y
Successfully uninstalled rake-0.9.2

$gem install rake -v 0.8.7
Fetching: rake-0.8.7.gem (100%)
Successfully installed rake-0.8.7
1 gem installed
Installing ri documentation for rake-0.8.7...
Installing RDoc documentation for rake-0.8.7...

DevKitのインストール

ここから
DevKit-tdm-32-4.5.2-20110712-1620-sfx.exe をRubyのディレクトリにdevkitとかのディレクトリ作ってそこにでも展開しておく。
環境変数に(例)C:\Ruby\devkit\binのPATHを通しておく。

RedClothのインストール

$gem install RedCloth
Fetching: RedCloth-4.2.7-x86-mingw32.gem (100%)
Successfully installed RedCloth-4.2.7-x86-mingw32
1 gem installed
Installing ri documentation for RedCloth-4.2.7-x86-mingw32...
Installing RDoc documentation for RedCloth-4.2.7-x86-mingw32...

sqlite3-rubyのインストール

$gem install sqlite3-ruby
Fetching: sqlite3-1.3.3-x86-mingw32.gem (100%)

=============================================================================

  You've installed the binary version of sqlite3.
  It was built using SQLite3 version 3.7.3.
  It's recommended to use the exact same version to avoid potential issues.

  At the time of building this gem, the necessary DLL files where available
  in the following download:

  http://www.sqlite.org/sqlitedll-3_7_3.zip

  You can put the sqlite3.dll available in this package in your Ruby bin
  directory, for example C:\Ruby\bin

=============================================================================

Fetching: sqlite3-ruby-1.3.3.gem (100%)

#######################################################

Hello! The sqlite3-ruby gem has changed it's name to just sqlite3.  Rather than
installing `sqlite3-ruby`, you should install `sqlite3`.  Please update your
dependencies accordingly.

Thanks from the Ruby sqlite3 team!

<3 <3 <3 <3

#######################################################

Successfully installed sqlite3-1.3.3-x86-mingw32
Successfully installed sqlite3-ruby-1.3.3
2 gems installed
Installing ri documentation for sqlite3-1.3.3-x86-mingw32...

No definition for libversion

Enclosing class/module 'mSqlite3' for class Statement not known
Installing ri documentation for sqlite3-ruby-1.3.3...
Installing RDoc documentation for sqlite3-1.3.3-x86-mingw32...

No definition for libversion

Enclosing class/module 'mSqlite3' for class Statement not known
Installing RDoc documentation for sqlite3-ruby-1.3.3...

mongrel_serviceのインストール

$gem install mongrel_service
Fetching: gem_plugin-0.2.3.gem (100%)
Fetching: cgi_multipart_eof_fix-2.5.0.gem (100%)
Fetching: mongrel-1.1.5-x86-mingw32.gem (100%)
Fetching: mongrel_service-0.4.0.gem (100%)
Successfully installed gem_plugin-0.2.3
Successfully installed cgi_multipart_eof_fix-2.5.0
Successfully installed mongrel-1.1.5-x86-mingw32
Successfully installed mongrel_service-0.4.0
4 gems installed
Installing ri documentation for gem_plugin-0.2.3...
Installing ri documentation for cgi_multipart_eof_fix-2.5.0...
Installing ri documentation for mongrel-1.1.5-x86-mingw32...
Installing ri documentation for mongrel_service-0.4.0...
Installing RDoc documentation for gem_plugin-0.2.3...
Installing RDoc documentation for cgi_multipart_eof_fix-2.5.0...
Installing RDoc documentation for mongrel-1.1.5-x86-mingw32...
Installing RDoc documentation for mongrel_service-0.4.0...

i18nのインストール

$gem install i18n -v 0.4.2
Fetching: i18n-0.4.2.gem (100%)
Successfully installed i18n-0.4.2
1 gem installed
Installing ri documentation for i18n-0.4.2...
Installing RDoc documentation for i18n-0.4.2...

sqlite3のダウンロードと配置

  1. ここから「sqlite-shell-win32-x86-3070701.zip」と「sqlite-dll-win32-x86-3070701.zip」をダウンロード
  2. 解凍してできた「sqlite3.exe」、「sqlite3.dll」、「sqlite3.def」をC:\Windowsディレクトリ配下(PATHが通っているところ)に配置する。

Redmineのダウンロードと配置と設定

  1. ここから「redmine-1.2.0.zip」をダウンロード
  2. 解凍してできた「redmine-1.2.0」ディレクトリを「redmine」にリネーム
  3. 「C:\redmine\config\database.yml.example」を「database.yml」にリネーム
  4. database.ymlのproductionの以下の項目を修正する
production:
  adapter: sqlite3
  database: db/redmine.db

秘密鍵の生成

$cd C:\redmine
$rake config/initializers/session_store.rb
(in C:/redmine)

DBの移行

$cd C:\redmine
$rake db:migrate RAILS_ENV=production

サービスの登録

$mongrel_rails service::install -N "Redmine" -c C:\Redmine -p 80 -e production
** Copying native mongrel_service executable...
Redmine service created.
  1. サービスの一覧から「Redmine」を選択しプロパティを編集する
    • スタートアップの種類
      • 手動→自動
  2. サービスを開始する

エラーが出る場合の回避方法

adminでログインできない場合
vendor/rails/actionpack/lib/action_controller/request.rb 449行目を以下に修正

session.destroy if session and session.respond_to?(:destroy)

You are being redirected.から進まない
ここを参考にC:\redmine\config\initializers\mongrel.rbを作成

完成

あとは、ここを参考に初期設定して完成。

watirでjavascriptの実行結果として返されるhtmlを取得する

最近、html解析作業にもっぱら心を奪われています。
特にwatirとhpricotは使いやすくていいなと思ってます。

指定したurlのhtmlを取得する。(javascriptでも可)

#! ruby

require 'rubygems'
require 'watir'

class Foo

  attr_reader:html

  def initialize(url)
    browser = Watir::Browser.new
    browser.go(url)
    browser.wait # ブラウザの読込が終わるまで待つ
    @html = browser.html
  end

end

f = Foo.new(ここにurl)
f.html

iphoneから投稿なので、間違ってるかも。

gitコマンドまとめ

gitを覚えるのに二つのサイトを見ればいい。わかりやすかった。

ピックアップ(引用)

リポジトリの作成およびメンテナンスに利用するコマンド:

コマンド 説明
git init リポジトリを作成する
git clone 既存のリポジトリの複製を作る
git fsck リポジトリの正当性チェックを行う
git gc リポジトリ内の不要なオブジェクトを削除し、最適化を行う

作業ツリーやブランチを操作・管理するコマンド:

コマンド 説明
git status 変更が加えられたファイルを表示する
git diff ファイルに加えられた変更点をdiff形式で表示する
git add コミットするファイルを指定する
git commit 変更点をコミットする
git log コミットログを閲覧する
git reset 直前のコミットを取り消す
git revert 作業ツリーを指定したコミット時点の状態にまで戻す
git branch ブランチ情報の表示およびブランチの作成
git checkout ブランチの切り替え
git show-branch ブランチの作成/変更/マージ履歴を表示
git merge ローカルブランチのマージを行う
git tag コミットにタグを付ける
git stash 現在の作業ツリーの状態を一時的に保管する
git rebase ブランチの派生元(上流)を変更する

ほかのリポジトリとの連携を行うコマンド:

コマンド 説明
git pull ほかのリポジトリの変更点をローカルリポジトリにマージする
git push 公開リポジトリに自分のリポジトリの内容を送信する

オンラインIDEのCloud9がすごくいい

Rubyを使い始めて、Webアプリケーションを作りたいと思い、Ruby onRailsというフレームワークがあることを知り使ってみると実際作りたいものはこんな大きなフレームワークにも載せる必要は無いなと感じる。
そして、sinatraというもっと軽量なフレームワークにたどり着き、開発を始めるとオンラインでソース管理してどんな環境でもいじれるようになりたいと思ってgithubに手を出した。
すると、ソースがオンラインなら開発環境もオンラインにできればと思うようになったところでChromeのウェブストアが日本語化されオープンしたのをきっかけにオンラインIDEについて調べてみた。
そうして辿り着いたのがCloud9というIDE。

前置きが長くなったけど、ようはいつでもどこでもブラウザがあれば開発できる環境が整った。

githubアカウントがあれば、インスタントログインでSSHの公開鍵を登録すればgithubのリポジトリにIDE上のコンソールからpushすることまでできる。

ただ、herokuへのpushは出来るともっといいなぁなんて思ってる。

英語のWebページをずるして乗り切る方法見つけた。

Webページの英語の文献を読むことがたまーにあるけど、英語あんまり得意じゃないのでいちいち辞書で調べてとか翻訳ページ行ってとかめんどくさいなぁ、英語できるようになりたいなぁなんて思ってたけど、いい方法見つけた。

ずるっこ!

これはずるいっ!Webページにルビふってくれる。便利。
ちょっと前に人気になって知ってはいたけど、ここ毎回開いていたら翻訳ページ行くのと変わらないしなーって思った。
ただ、もっと良い方法があって、URLのホスト部分の最後に「.zurukko.jp」と追加するだけでページを切り替えてくれる。
大抵のブラウザは多分Ctrl(Command)+LとかAlt+Dとかのショートカットキーでアドレスボックスにフォーカスできると思うのでより楽して(マウスレスで)英語のページのストレスが軽減される。

覚えた単語を消していけるのもイイ。

引用

「ずるっこ!」により快適に Web サイトを読める機能を追加しました。
以下のように、「http://」で始まる URL の 3 個目の「/」文字 (ホスト部の最後の部分) の直前
に「zurukko.jp」と入力してページを再読み込みするだけで、そのページを「ずるっこ!」で読めます。

Duck Typingについて

参考の記事を見て、おっPrototypeパターン*1かってことで興味を引いた。
というのも個人的にすごくタイムリーな内容で、ちょうどまつもとさん*2の「コードの世界」を拝読してたところでおんなじ様にDuck Typingだよねっていう記事があった。
そして、この機会にDuck Typingについて考察してみようと考えた。

Duck Typing

“If it walks like a duck and quacks like a duck, it must be a duck”
(もしもそれがアヒルのように歩き、アヒルのように鳴くのなら、それはアヒルである)

静的型言語と動的型言語

データ型*3で定義された変数のみの範囲で処理をする言語が静的型言語で、変数にデータが割り当てられた時点で初めて型が決まる言語が動的言語という簡単な解釈。
Duck Typingはこのデータ型ではなく、振る舞い*4でそのインスタンスは何者かを判断する。

コンピュータに優しい人間

あくまでも型の宣言というのは、コンピュータにとって都合の良いものであるため出来るだけ現実世界や人間に都合の良いように設計されている言語のほうが本来イイはず。
でも、みんながみんなコンピュータに優しいプログラミングに慣れてしまっているので気付かないし、概念も少し難しいかもしれないから違和感はあんまりない。というか、言語なんてあくまでツールなんだからそんなことはどうでもよくて実装がいかにスムーズに出来るかということのほうが重要かもしれない。とは言っても言語設計とかに興味を持ち出したりするとこちらもほっとけなくなってくる。

*1:Gofの生成に関するパターンのうちのひとつ

*2:rubyのパパ

*3:数字、文字列、配列、連想配列等々

*4:メソッドやプロパティ

TDDについて

テスト駆動開発ってなんで現場で取り入れられないのだろう。ウォーターフォールである意味が見出せなくなってきた。いや、もちろん意味はわかってますが…。
ぼくが変えるしかない!