Path to Quality Code

Here are some thoughts of mine.

FedoraでUSB HDDをマウント

ホームサーバーとしてFedoraを使っているのですが、サーバーとしてインストールするとデフォルトでは自動でマウントしてくれないので、自分でマウントする必要があります。

1
2
3
4
5
#mountしたいデバイスがどこに繋がっているかを確認するため、syslog daemonが出力しているログを参照します
tail -f /var/log/messages

#sdb1と表示されていたら、
mount /media/usb-hdd /dev/sdb1

dmesg と/var/log/messages の違いは ハードディスク増設方法を教えて下さい


powとpowderのインストール

Powが便利らしいので、導入してみました。

Powとは

公式によると、

PowはMac OS Xのための設定不要のRackサーバーです。Rails/Rackのアプリケーションの開発を可能な限りスムーズにします。 (Pow is a zero-configuration Rack server for Mac OS X. It makes developing Rails and Rack applications as frictionless as possible.)

Pow User’s Manual

ということなのですが、

簡単に言えば、 普段ローカルでlocalhost:3000のようにしてアクセスし開発しているのを、hogehoge.dev のようにアクセスできるようにしてくれます。

Powのインストール

通常であればこれでインストールできます。

1
  curl get.pow.cx | sh

tmuxを使っている場合

tmuxからインストールしようとすると、こんな感じに怒られてしまいます。

1
2
3
4
5
6
7
  *** Installing Pow 0.4.0...
  *** Installing local configuration files...
  /Users/sjun/Library/LaunchAgents/cx.pow.powd.plist
  *** Installing system configuration files as root...
  /Library/LaunchDaemons/cx.pow.firewall.plist
  *** Starting the Pow server...
  !!! Couldn't find a running Pow server on port 20559

なので一度、tmuxを抜けてインストールしましょう。 githubのissueにも載っていました。

https://github.com/imathis/octopress/issues/117

Powを使う

これも公式に載っていることですが、

1
2
  cd ~/.pow
  ln -s /path/to/myapp

とだけすれば、大丈夫です。

Powをもっと便利に(Powder)

Powだけでも十分便利ですが、Powderと呼ばれるpowの管理ツールを使うともっと簡単に、powを扱うことができます。

Powderのインストール

1
 gem install powder

powder@github

Powderを使う

1
2
3
4
5
6
7
8
#現在のディレクトリのアプリケーションとpowをつなぐ
powder link
Your application is now available at http://ur_app.dev/
#現在のディレクトリのアプリケーションとpowを切断する
powder unlink
Successfully removed ur_app
#アプリケーションのログを出力
powder applog

とこんな感じに便利に使うことができるようになりました。 複数のアプリケーションを同時に開発してる時などに、localhost:4321みたいなのを手入力したり、補完しなくてもよいのはいいですね。


Rubyの正規表現において、URLでマッチさせる

以下のようなURLがあって、

1
 url = http://google.com/foo/bar.html

それに対して、以下のURLでマッチさせたい時、 べた書きの正規表現であれば、エスケープを使って書くことができるが、

1
2
3
4
5
6
7
 #マッチさせたいURL
  http://google.com/
  #べた書き正規表現
  url.match(/http:\/\/google\.com\//)

  #このように書くことができる
  Regexp.new(Regexp.quote('http://google.com/'))

公式ドキュメントによれば、

正規表現において特別な意味を持つ文字の直前にエスケープ文字(バックスラッシュ)を挿入した文字列を返します。

とのことなので、引き渡した文字列を自動的にエスケープしてくれるようだ。

これを使うと、変数に入ったURLを正規表現のマッチャーとして使うときに、非常に便利になる。具体的には、

1
2
3
4
5
6
 urls = ["http://yahoo.com/", "http://google.com/"]
  urls.each do |url|
      if long_url.match(Regexp.new(Regexp.quote(url)))
          do_something
      end
  end

のようにリストを渡して、沢山処理する必要があるときに使うと、 とても便利に使うことができる。

参考文献



Octpressのインストール失敗と成功

Mac OSX 10.7.5の環境です。 散々失敗した記録なので、決してまねしないでね。

1
2
ruby --version
# => ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]

1.9.3以上であることを確認。パッチのバージョンは、まあ大丈夫からと思って放置。

1
git clone git://github.com/imathis/octopress.git octopress

最後に設定した”octpress”の部分は、myblogとか好きな名前で大丈夫。

1
2
3
4
5
cd octopress/
Do you wish to trust this .rvmrc file? (/Users/sjun/octopress/.rvmrc)
y[es], n[o], v[iew], c[ancel]> y
ruby-1.9.3-p286 is not installed.
To install do: 'rvm install ruby-1.9.3-p286'

あれ、怒られた。

1
2
ruby -v
# => ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]

??? どうやら、rvmのrubyじゃなくて、はじめからインストールされてるやつにPATHが通ってる。 とりあえず、rvmでちゃんとインストールされてるかだけ確認。

1
2
3
4
5
6
7
$ rvm list

=* ruby-1.9.3-p194 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

あきらかによろしくないけど、無理矢理進める。

1
2
3
4
5
6
7
8
9
10
11
12
13
$ bundle install
error loading "/Users/sjun/.rvm/gems/ruby-1.9.3-p194@global/gems/rubygems-bundler-0.9.2/lib/rubygems_plugin.rb":

Older rubygems-bundler found, please uninstall it with:

    GEM_HOME="/Users/sjun/.rvm/gems/ruby-1.9.3-p194@global" gem uninstall -ax rubygems-bundler -v 0.9.2

     (RuntimeError)
     Fetching gem metadata from http://rubygems.org/.
     Error Bundler::HTTPError during request to dependency API
     Fetching full source index from http://rubygems.org/
     ^C
     Quitting...

なんか怒られたw

1
2
3
4
5
6
7
8
9
10
$ GEM_HOME="/Users/sjun/.rvm/gems/ruby-1.9.3-p194@global" gem uninstall -ax rubygems-bundler -v 0.9.2
error loading "/Users/sjun/.rvm/gems/ruby-1.9.3-p194@global/gems/rubygems-bundler-0.9.2/lib/rubygems_plugin.rb":

Older rubygems-bundler found, please uninstall it with:

    gem uninstall -ax rubygems-bundler -v 0.9.2

     (RuntimeError)
     Removing noexec
     Successfully uninstalled rubygems-bundler-0.9.2

とりあえず、怒られてるgemを削除 気をとりなおして、bundlerをインストール。

1
2
3
4
5
6
$ gem install bundler

Successfully installed bundler-1.2.1
1 gem installed
ERROR:  While executing gem ... (ArgumentError)
    undefined class/module Encoding

なんかもう諦めたくなってきた。

1
2
3
4
5
6
7
8
9
10
$ gem update
Updating installed gems
Updating gorillib
Successfully installed configliere-0.4.17
Successfully installed gorillib-0.4.2
Updating net-ssh
Successfully installed net-ssh-2.6.1
Gems updated: configliere, gorillib, net-ssh
ERROR:  While executing gem ... (ArgumentError)
    undefined class/module Encoding

エラー、それでも無理矢理すすめる。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$ bundle install
Fetching gem metadata from http://rubygems.org/.
Error Bundler::HTTPError during request to dependency API
Fetching full source index from http://rubygems.org/
Using rake (0.9.2.2)
Installing RedCloth (4.2.9) with native extensions
Installing posix-spawn (0.3.6) with native extensions
Installing albino (1.3.3)
Installing blankslate (2.1.2.4)
Installing chunky_png (1.2.5)
Installing fast-stemmer (1.0.1) with native extensions
Installing classifier (1.3.3)
Installing fssm (0.2.9)
Installing sass (3.1.20)
Installing compass (0.12.2)
Installing directory_watcher (1.4.1)
Installing ffi (1.0.11) with native extensions
Installing haml (3.1.6)
Installing kramdown (0.13.7)
Installing liquid (2.3.0)
Gem::InstallError: liquid requires RubyGems version >= 1.3.7. Try 'gem update --system' to update RubyGems itself.
An error occurred while installing liquid (2.3.0), and Bundler cannot continue.
Make sure that `gem install liquid -v '2.3.0'` succeeds before bundling.

この辺りで、gemとかrvmを全くアップデートしてないことに気づく。

1
2
3
4
5
6
7
8
gem update --system
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.8.24
Updating RubyGems to 1.8.24
Installing RubyGems 1.8.24
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied - /Library/Ruby/Site/1.8/gauntlet_rubygems.rb

このあたりで、sudoしてないせいかもしれないと思いはじめる。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sudo gem update --system
Password:
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.8.24
Updating RubyGems to 1.8.24
Installing RubyGems 1.8.24
RubyGems 1.8.24 installed

== 1.8.24 / 2012-04-27

* 1 bug fix:

  * Install the .pem files properly. Fixes #320
    * Remove OpenSSL dependency from the http code path


    ------------------------------------------------------------------------------

    RubyGems installed the following executables:
         /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/gem

お。通った。

1
2
3
4
5
6
7
8
9
10
11
bundle install
Fetching gem metadata from http://rubygems.org/.
Error Bundler::HTTPError during request to dependency API
Fetching full source index from http://rubygems.org/
.
.
(略)
.
.

Using bundler (1.2.1)Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
1
2
3
4
5
6
$ gem update
.
.
.
ERROR:  While executing gem ... (ArgumentError)
    undefined class/module Encoding

まだダメか。

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo gem update
Updating installed gems
Updating actionmailer
Fetching: activesupport-3.2.8.gem (100%)
.
.
(以下大量のパッケージがインストールされる)
.
.
Building native extensions.  This could take a while…
(時間かかり過ぎ)
.
.

パッケージとRDocが大量にインストールされて驚いたけど、 無事終わった!!

しかし、心配になってもう一度やる。

1
2
3
4
$ sudo gem update
Password:
Updating installed gems
Nothing to update

これは期待 :3 :3 :3

1
2
3
4
5
$ bundle install
.
.
.
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

よし :)

1
2
3
4
5
6
7
8
9
$ rake install
## Copying classic theme into ./source and ./sass
mkdir -p source
cp -r .themes/classic/source/. source
mkdir -p sass
cp -r .themes/classic/sass/. sass
mkdir -p source/_posts
mkdir -p public
23:05:37 ~/octopress

完了した! が、このあとちゃんと動かない… 諦めて、rubyを更新、rm -rfして、再度git cloneしてくる。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
rake generate
## Generating Site with Jekyll
directory source/stylesheets/
   create source/stylesheets/screen.css
   Configuration from /Users/sjun/octopress/_config.yml
   /Users/sjun/octopress/plugins/category_generator.rb:109: warning: regexp has invalid interval
   /Users/sjun/octopress/plugins/category_generator.rb:109: warning: regexp has `' without escape
   /Users/sjun/octopress/plugins/category_generator.rb:146: warning: regexp has invalid interval
   /Users/sjun/octopress/plugins/category_generator.rb:146: warning: regexp has `' without escape
   /Users/sjun/.rvm/gems/ruby-1.9.3-p194/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:76:in `require': /Users/sjun/octopress/plugins/image_tag.rb:27: undefined (?...) sequence: /(?<class>\S.*\s+)?(?<src>(?:https?:\/\/|\/|\S+\/)\S+)(?:\s+(?<width>\d+))?(?:\s+(?<height>\d+))?(?<title>\s+.+)?/ (SyntaxError)
   /Users/sjun/octopress/plugins/image_tag.rb:29: undefined (?...) sequence: /(?:"|''")(?<title>[^"''"]+)?(?:"|''")\s+(?:"|''")(?<alt>[^"''"]+)?(?:"|''")/
        from /Users/sjun/.rvm/gems/ruby-1.9.3-p194/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:76:in `setup'
             from /Users/sjun/.rvm/gems/ruby-1.9.3-p194/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:75:in `each'
                  from /Users/sjun/.rvm/gems/ruby-1.9.3-p194/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:75:in `setup'
                       from /Users/sjun/.rvm/gems/ruby-1.9.3-p194/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:30:in `initialize'
                            from /Users/sjun/.rvm/gems/ruby-1.9.3-p194/gems/jekyll-0.11.2/bin/jekyll:224:in `new'
                                 from /Users/sjun/.rvm/gems/ruby-1.9.3-p194/gems/jekyll-0.11.2/bin/jekyll:224
                                      from /Users/sjun/.rvm/gems/ruby-1.9.3-p194/bin/jekyll:23:in `load'
                                           from /Users/sjun/.rvm/gems/ruby-1.9.3-p194/bin/jekyll:23

あれ?やばいかも…

1
2
3
$ sudo rake generate
Could not find RedCloth-4.2.9 in any of the sources
Run `bundle install` to install missing gems.

んん?

1
2
3
4
5
6
7
sudo gem install RedCloth
Fetching: RedCloth-4.2.9.gem (100%)
Building native extensions.  This could take a while...
Successfully installed RedCloth-4.2.9
1 gem installed
Installing ri documentation for RedCloth-4.2.9...
Installing RDoc documentation for RedCloth-4.2.9...
1
2
3
sudo rake generate
Could not find posix-spawn-0.3.6 in any of the sources
Run `bundle install` to install missing gems.

こいつもインストールした。

1
2
3
$ rake generate
rake aborted!
### You haven't set anything up yet. First run `rake install` to set up an Octopress theme.
1
2
3
4
5
6
rake install
rake generate
rake deploy
rake setup_github_pages
add .
git push origin source

多少記憶と記録があやふや。

とりあえず、versionはあわせることとupdateを先にすることを身にしみて理解した。


参考にしたもの



the first post

heading 1

the other heading 1

heading 2

the other heading 2

“this is not an actual quote but i just wanted to put this in the article…”


1
rm -rf /
1
2
3
4
5
6
7
8
var func = (function(){
  fucntion ILOVEJS(){
      this.meth = funciton(){
          // do nothing lol
      }        
  }
  return new IlOVEJS()
})(this);