初期設定色々
iMacが来たので色々設定する
ログイン画面の[その他のユーザー]を消す
ログイン画面で[その他のユーザー]ってのが出てくるのが気になるけど。。。どうやって消すんだっけ??
[システム環境設定] - [アカウント] - [ログインオプション] で [ログイン時の表示] を [名前とパスワード] にすれば、とりあえず消えるっちゃー消えるね。
そもそも root にパスワードを付けてると出るっぽい。
なので本当に消すには [ログインオプション] - [接続] で [ディレクトリユーティリティを開く]
メニュー [編集] - [ルートユーザを無効にする]
が正解
デスクトップにMacintosh HDを表示
使わないんだけど、なんかコレがないと落ち着かない。。。
Finderで [ファイル] - [環境設定]
[デスクトップに表示する項目]で[ハードディスク]にチェック入れればOK
Dockに「Recent Applications」を表示させる
まずはTerminalを開いて
$ defaults write com.apple.dock persistent-others -array-add '{ "tile-data" = { "list-type" = 1; }; "tile-type" = "recents-tile"; }'
入力後に、
$ killall Dock
です。
2つくらい作って右クリックで Recent Documents も作る。
コンピュータ名の変更
インストール時に入れた自分の名前がコンピュータ名になっちゃってて気持悪いので変更する。
[システム環境設定] - [共有] - [コンピュータ名]
ファンクションキーを使う
標準だと機能キー(意味一緒じゃん)というか、割り当てられている機能が起動するのでファンクションキーとして動作するように変更する
[システム環境設定] - [キーボード] - [F1、F2などすべてのキーを標準....] にチェックを入れる
デスクトップのアイコンサイズを変更する
デスクトップで右クリックして[表示オプションを表示]
デフォルトは64x64になってたので 40x40 くらいかな。
で[並び順序]を[グリッドに沿う]とか。
TweedDeckで4行越えのツイートを読む
TweedDeckって4行までしかpostが表示されない。
TweetDeck 長文postの読み方 - タイトルが決まりません というのが紹介されてるけど、微妙にクリックしにくい。
あと当り判定がキビシイようでスクロールできたり、できなかったり。。。
と、いうかオイラは普通に文章をドラッグしてスクロールさせてたんだけど。。。
まぁどっちにしろ操作性はイマイチですね。。
まぁでもドラッグの方がコンテキストメニューで開かないし、上下どっちにでもスクロールできるからドラッグの方がいいかな。
describeとitのスコープ
せっせせっせとspecファイルを書いていたら、describeとitのスコープが気になりだしてきた。
ちょちょいとググってみたら同じ事が気になった人がいらっしゃいました
- 宇宙, GRUBでRAIDなWindowsXPとUbuntuをデュアルブートする, Hiki XHTML化キット0.21.3を公開しました, describeとitのスコープ - 忘れたときに備えた記録(2008-01-12)
自分でもやってみる。
とりあえず、こんなspecを書いてみました
puts "Outside: " puts " self # => #{self}" puts " self.class # => #{self.class}" describe "Fruit" do puts " => describe Fruit: " puts " self # => #{self}" puts " self.class # => #{self.class}" puts " superclass # => #{superclass}" it "Apple" do puts " => it Example 1 of Fruit:" puts " self # => #{self}" puts " self.class # => #{self.class}" end it "Orange "do puts " => it Example 2 of Fruit:" puts " self # => #{self}" puts " self.class # => #{self.class}" end describe "Banana" do puts " => describe Fruit::Banana " puts " self # => #{self}" puts " self.class # => #{self.class}" puts " superclass # => #{superclass}" it "Yellow" do puts " => it Example 1 of Fruit::Banana" puts " self # => #{self}" puts " self.class # => #{self.class}" end end end describe "Vegetable" do puts " => describe Vegetable: " puts " self # => #{self}" puts " self.class # => #{self.class}" puts " superclass # => #{superclass}" it "Tomato" do puts " => it Example 1 of Vegetable:" puts " self # => #{self}" puts " self.class # => #{self.class}" end it "Potato" do puts " => it Example 2 of Vegetable:" puts " self # => #{self}" puts " self.class # => #{self.class}" end end
やってる事は、ほぼ一緒。descibeの入れ子も入れてみた。
で、こいつを2つ用意して、specにかけてみる。
Outside: self # => main self.class # => Object => describe Fruit: self # => Spec::Example::ExampleGroup::Subclass_1 self.class # => Class superclass # => Spec::Example::ExampleGroup => describe Fruit::Banana self # => Spec::Example::ExampleGroup::Subclass_1::Subclass_1 self.class # => Class superclass # => Spec::Example::ExampleGroup::Subclass_1 => describe Vegetable: self # => Spec::Example::ExampleGroup::Subclass_2 self.class # => Class superclass # => Spec::Example::ExampleGroup Outside: self # => main self.class # => Object => describe Fruit: self # => Spec::Example::ExampleGroup::Subclass_3 self.class # => Class superclass # => Spec::Example::ExampleGroup => describe Fruit::Banana self # => Spec::Example::ExampleGroup::Subclass_3::Subclass_1 self.class # => Class superclass # => Spec::Example::ExampleGroup::Subclass_3 => describe Vegetable: self # => Spec::Example::ExampleGroup::Subclass_4 self.class # => Class superclass # => Spec::Example::ExampleGroup => it Example 1 of Fruit: self # => #<Spec::Example::ExampleGroup::Subclass_1:0xb79798cc> self.class # => Spec::Example::ExampleGroup::Subclass_1 . => it Example 2 of Fruit: self # => #<Spec::Example::ExampleGroup::Subclass_1:0xb7979368> self.class # => Spec::Example::ExampleGroup::Subclass_1 . => it Example 1 of Fruit::Banana self # => #<Spec::Example::ExampleGroup::Subclass_1::Subclass_1:0xb7978a80> self.class # => Spec::Example::ExampleGroup::Subclass_1::Subclass_1 . => it Example 1 of Vegetable: self # => #<Spec::Example::ExampleGroup::Subclass_2:0xb79781c0> self.class # => Spec::Example::ExampleGroup::Subclass_2 . => it Example 2 of Vegetable: self # => #<Spec::Example::ExampleGroup::Subclass_2:0xb7977cac> self.class # => Spec::Example::ExampleGroup::Subclass_2 . => it Example 1 of Fruit: self # => #<Spec::Example::ExampleGroup::Subclass_3:0xb79774a0> self.class # => Spec::Example::ExampleGroup::Subclass_3 . => it Example 2 of Fruit: self # => #<Spec::Example::ExampleGroup::Subclass_3:0xb7976f8c> self.class # => Spec::Example::ExampleGroup::Subclass_3 . => it Example 1 of Fruit::Banana self # => #<Spec::Example::ExampleGroup::Subclass_3::Subclass_1:0xb79766b8> self.class # => Spec::Example::ExampleGroup::Subclass_3::Subclass_1 . => it Example 1 of Vegetable: self # => #<Spec::Example::ExampleGroup::Subclass_4:0xb7975df8> self.class # => Spec::Example::ExampleGroup::Subclass_4 . => it Example 2 of Vegetable: self # => #<Spec::Example::ExampleGroup::Subclass_4:0xb79758e4> self.class # => Spec::Example::ExampleGroup::Subclass_4 . Finished in 0.02293 seconds 10 examples, 0 failures
ちょっとわかりやすくしてみる
putsを削ると
describe "Fruit" do it "Apple" it "Orange" describe "Banana" it "Yellow" end end describe "Vegetable" do it "Tomato" it "Potato" end
こんな感じですね。
実行結果を表にまとめてみた
Class名のSpec::Example::は省略してます。
describe
ファイル | describe | self | class | superclass |
---|---|---|---|---|
test_1 | Fruit | ExampleGroup::Subclass_1 | Class | ExampleGroup |
test_1 | Fruit::Banana | ExampleGroup::Subclass_1::Subclass_1 | Class | ExampleGroup::Subclass_1 |
test_1 | Vegetable | ExampleGroup::Subclass_2 | Class | ExampleGroup |
test_2 | Fruit | ExampleGroup::Subclass_3 | Class | ExampleGroup |
test_2 | Fruit::Banana | ExampleGroup::Subclass_3::Subclass_1 | Class | ExampleGroup::Subclass_3 |
test_2 | Vegetable | ExampleGroup::Subclass_4 | Class | ExampleGroup |
it(example)
ファイル | describe | it | class |
---|---|---|---|
test_1 | Fruit | Apple | ExampleGroup::Subclass_1 |
test_1 | Fruit | Orange | ExampleGroup::Subclass_1 |
test_1 | Fruit::Banana | Yellow | ExampleGroup::Subclass_1::Subclass_1 |
test_1 | Vegetable | Tomato | ExampleGroup::Subclass_2 |
test_1 | Vegetable | Potato | ExampleGroup::Subclass_2 |
test_2 | Fruit | Apple | ExampleGroup::Subclass_1 |
test_2 | Fruit | Orange | ExampleGroup::Subclass_1 |
test_2 | Fruit::Banana | Yellow | ExampleGroup::Subclass_1::Subclass_1 |
test_2 | Vegetable | Tomato | ExampleGroup::Subclass_2 |
test_2 | Vegetable | Potato | ExampleGroup::Subclass_2 |
つまりは?
- 実行結果を見てもわかるように、まずはそれぞれのファイルのdescribe部分がClassとして生成される。
- describeの中にあるitはdescribeのClassのオブジェクトとして生成される。
という事ですね。
ちなみにdescribeを入れ子にした Fruit::Banana の Spec::Example::ExampleGroup::Subclass_2::Subclass_1 は Spec::Example::ExampleGroup::Subclass_2 を継承しているようです。
次回は?
今回は人がやった事をそのままやっただけなので次回は
- ところでbeforeとafterは?
- 変数のスコープは?
の2本でお送りいたします。
File.foreachのスタブ
先日 モックとスタブ - 日々此妄想 の悩み
File.foreachみたいなブロック付きメソッドのスタブってどうやって書くのかなぁ。。。。
Young risk taker.: [RSpec] Mock API を見ていて、たぶん and_yield だというところまでは目をつけていた。
yield
わかってるつもりだったけど、ちょっと甘かったっぽい。
def foo yield(1,2) end foo {|a,b| p [a, b] } # => [1, 2] (要するに p [1, 2] を実行した)
これは理解できてたんですよ。はい。
じゃー Array#each みたいなのはどうするのか理解できてなかったっぽい。*1
で、and_yieldを知るには、まずyieldだと思ってRubyのリファレンスを見ました。すると目から
def bar yield 10 yield 20 yield 30 end # barに「1引数手続き、その働きは引数に3を足してpで印字する」というものを渡して実行させる bar {|v| p v + 3 } # 13 # 23 # 33 (同じブロックが3つのyieldで3回起動された。 # 具体的には p 10 + 3; p 20 + 3; p 30 + 3 を実行した)
鱗!!!!!!!!
へー、そうなんだ。そうだったんだ。しらなんだ。yieldってそうやって使うのね(恥)
と、いう事で and_yield
さて、では File.foreach のスタブはどう書くか。。。
こうしてみた。
File.stub!(:foreach).and_yield('1| one') File.foreach('text_file') do |line| line.split[1] # => 'one' end
まぁ、これは悩む前もできてた、問題は複数行の時
こうしてみた。
File.stub!(:foreach).and_yield('1| one').and_yield('2| two').and_yield('3| tree') File.foreach('text_file') do |line| line.split[1] # => 'one', 'two', 'tree' end
やったー。できたー。
yieldってそうやってつかうのねー。なるほどなるほど。
という事で、もうちょっとスマートに
text_file = %w(1| one 2| two 3| tree) foreach_stub = File.stub!(:foreach) text_file.each do |line| foreach_stub.and_yield(line) end
とか、しとくんですかね?
モックとスタブ
やっぱりモックとスタブの違いがわからんとです。
使いわけもわからんとです。
とりあえず http://d.hatena.ne.jp/takihiro/20081023/1224762895 これが一番しっくり来てるんだけど、実際自分で書こうとすると、やっぱり使いわけできないというか。。。モックっていつ使うの?
たとえば。。。
- Gameクラス*1
- セーブするとセーブデータが保存される
- Game#saved? でセーブデータがあるかどうか確認できる
てな仕様があったとして Game#saved? の spec は
describe Game, "セーブデータが存在する時" do before do @game = Game.new end it "trueを返す" do File.stub!(:exists?).with('save_data').and_return(true) @game.saved?.should be_true end end
これがスタブだよね。*2
実際 'save_data' というファイルがあろうが、なかろうが、あった事にできる。みたいな。
これがというか Fileクラスに対してスタブを設定してるんだよね?*3
って、ここまでは理解できた。*4
最初 http://d.hatena.ne.jp/takihiro/20081023/1224762895 を読んだ時「stub! を使うとスタブで should_receive を使うとモック」という風に理解してしまったんだけど、自分で書いてみると、どうもそうじゃないっぽい。どっちもスタブじゃないのかという疑問が湧いて「じゃぁモックって何さ」という事にグルグルルグルグル。。。
ブレイクスルー
モックが何なのか、なんとなくはわかっている。
さっきのスタブの例ではメソッド(と、その戻り値)を、でっちあげたがクラス(オブジェクト)は既存のFileクラスのままだった。
じゃぁモックはというとクラス(オブジェクト)も、でっちあげるという事ではないかと。
と、 Young risk taker.: [RSpec] Mock API を読んでブレイクスルー
オブジェクトのモックつくってでっちあげー、そいつにスタブでメソッドもでっちあげー☆
ってことかと。
最近の悩み
File.foreach('data') do |line| data = line.split hoge_method data.first end
File.foreachみたいなブロック付きメソッドのスタブってどうやって書くのかなぁ。。。。
LinuxにTime Machineでbackupをとりたいよ
NASを買ったよ
家にNASが届きました。BUFFALO 40Mb/s DTCP-IP対応 NAS Link Station LS-WXシリーズ 1.5TB x2 で 4万円 RAID0/1対応。
これをミラー箱にして写真とかのバックアップに使おうとおもっちょります。
買って梱包を解いてNASを出そうと持ち上げると。。。。
カラカララ。。。。
へ。。。?
内部で何かが転がってる。
なんかネジっぽい音。
で、フロントを開けてHDDを抜いて逆さまにして振ってみると。
コロコロ。。。。
ネジが出てきた。しかも3本wwww
なんじゃこりゃ。
翌日サポートに電話して状況を伝えると、ちょっと待たされた後、「明らかに初期不良なので、交換させていただきます。」との事。そりゃどうみてもそうだろwwww
先出ししてよと、軽くゴネてみたけど応じてもらえず、センドバック。
2週間ほど待たされ、「大丈夫かよ。。。忘れてない?」と思ったころに代替品が到着。
早速昨日から遊んでます。
で、最初は共有フォルダをつくって写真をぶっこみゃいいかと思ってたんだけど、だんだん欲がでてきてTimeMachineを受けさせてみたくなった。
設定とかは簡単にできて、「ほうほうこりゃいいぜ」と思ってたんだけど、MacBookは会社にいる時間の方が長いので会社でTimeMachineできないかと思いだした。
会社のLinux + netatalk で TimeMachine
会社の作業用マシンは VineLinux 4(笑)
ググってみると TimeMachine 受け*1 は netatalk + avahi でできるっぽい。
avahi は使ってないけど入ってるので問題なす。
netatalkをとりあえず入れる
$ sudo apt-get install avahi
さくっと終了
すると /etc/avahi/services/afpd.service も入った。
$ cat /etc/avahi/services/afpd.service <?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_afpovertcp._tcp</type> <port>548</port> </service> </service-group>
よろしいんではなかろうか。
netatalkの設定と起動
TimeMachine用のディレクトリを掘ってそこを共有するように設定しnetatalkを起動。avahi-daemonも再起動
$ mkdir ~/TimeMachine $ sudo vi /etc/netatalk/AppleVolumes.default ~/TimeMachine "Time Machine" <- 追加 $ sudo /sbin/service atalk start Starting AppleTalk services: Starting atalkd: [ OK ] Registering kikyo:Workstation: [ OK ] Registering kikyo:netatalk: [ OK ] Starting papd: [ OK ] Starting cnid_metad: [ OK ] Starting afpd: [ OK ] $ sudo /sbin/service avahi-daemon restart Shutting down avahi-daemon: [ OK ] Starting avahi-daemon: [ OK ]
Mac側の設定(おまじない)
なんか今回入れたnetatalkバイナリは TimeMachine に対応しているわけではないっぽい。
入れたのはコレ
$ rpm -qi netatalk Name : netatalk Relocations: (not relocatable) Version : 2.0.3 Vendor: Project Vine Release : 7vl4 Build Date: 2009年03月08日 23時28分39秒 Install Date: 2009年12月11日 11時34分17秒 Build Host: natsume Group : System Environment/Daemons Source RPM: netatalk-2.0.3-7vl4.src.rpm Size : 1988778 License: GPL Signature : DSA/SHA1, 2009年03月08日 23時28分40秒, Key ID 08b035142d34e5db Packager : Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> URL : http://netatalk.sourceforge.net/ Summary : Linux 用 AppleTalk, AppleShare/IP サービス Description : このパッケージを使うことで, Linux 上で AppleTalk プロトコルを 扱うことができ, Macintosh と通信が可能になります. Linux 上で EtherTalk や AppleTalk over IP の Mac 向けファイルサーバを 稼働させることができるデーモンプログラムが収められています. NOTE: 本パッケージには HAT さん作の CJK パッチが適用されています。 パッチの詳細は http://www003.upp.so-net.ne.jp/hat/netatalk/cjk.html をご覧下さい
と、いう事でLinuxマシンを使ってネットワーク越しのTime Machineバックアップ環境を構築する手順まとめ - yanbe.logを参考に
$ defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
という呪文を入れておかないとTimeMachineから見えないっぽい。netatalk 2.0.5rc1 以降なら TimeMachine に対応してるっぽく、いらないっぽい。試してないからわからないけど。
スパースバンドルがつくれない
で、MacでTimeMachineの「バックアップディスクを選択」をクリックすると見えないwww
Finderで対象のマシンをクリックすると、受けのディレクトリに何かいっぱいファイルやらができる。
で、さらにフォルダを開くとマウントされる。
この状態だと「バックアップディスクを選択」で見えるようになる。
ためしにアウンマウント(取り出し)すると見えなくなる。
見えるようになったところで、バックアップ先を選択して「バックアップに使用」をクリックし認証を通すとカウントダウンがはじまるので待つ*2
すると「バックアップを準備中」になる。
で、失敗するw
どうやらバックアップ先のファイル => スパースバンドル がちゃんと作れないっぽい。
スパースバンドルを手動でつくる
という事で手動でつくってあげます。
ディスクユーティリティでもつくれるらしいけど、男はターミナルから
suzuran:~ hana-da$ hdiutil create -size 1G -type SPARSEBUNDLE -fs HFS+ <hostname>_<en0のmac addressから:を消したもの>.sparsebundle created: /User/hana-da/<hostname>_<en0のmac addressから:を消したもの>.sparsebundle
で、できます。とりあえずサイズは1Gにしてみた。
こいつをバックアップ先にぶっこんでやる。普通にドラッグ&ドロップでOK
TimeMachineはいったん「なし」にしておきましょう。
TimeMachineふたたび
で再度「バックアップディスクを選択」してやります。。。。。
キター
バックアップがはじまりましたー!!!
メデタシシメタダ。
で、おこられる。
とりあえず1Gが原因です。
NASを買うくらいだから、そもそもディスクがパンパンなんですよ。
まぁここはバックアップの除外設定をして容量を減らす方向で。。。。
といいたいところだが1Gじゃおさまらんよなぁ。。。10Gくらいにしたい。
スパースバンドルのサイズ変更
- こわいのでTimeMachineはいったん「切」
- ディスクユーティリティを起動
- Finderで受けマシンのスパースバンドルをダブルクリックしてマウント
- ディスクユーティリティにスパースバンドルが表われる(untitledが子)
- スパースバンドル本体を選択し「取り出す」
- 「イメージのサイズを変更」をクリック
- お好みの容量を設定
- ▼をクリックして「イメージのサイズだけを変更」
- 「サイズ変更」
- 「イメージのサイズを変更」をクリック
- お好みの容量を設定
- ▼をクリックして「パーティションのサイズだけを変更」
- 「サイズ変更」
ってやるらしんだけど、パーティションのサイズが変更できない。。。
なんでだろ。。
しょうがないのでパーティションをつくりなおしたら、うまくいった。まっいっか。
てか10Gくらいじゃぜんぜん収まらんね。/Usersを除外しても 23.5GB必要だってさ。まったく最近の(ry
[Ruby][shell] **/ と */ の違い。
そうそう先日RSpec + RCov でテストしたい。 その2 - 日々此妄想を書いててちょっとハマったのでメモしとく
最近よく見掛ける **/ なんだこれ?
- lib/**/*.rb とか
- app/**/*.rb とか
何か再起的に下りてってくれる気がするんだけど。。。
$ ls ~/work/**/*.rb |wc -l 54 $ ls ~/work/*/*.rb |wc -l 54
結果は一緒。
しかも。
$ ls doc/*/* /bin/ls: doc/*/*: No such file or directory $ ls doc/**/* /bin/ls: doc/**/*: No such file or directory
なんか期待してるのと違うんだよなぁ。。。
こんな動きだっけ???
しかも * とか ** って google とかで検索しにくい。
さんざん調べた(つもり)だけどやっぱりわからん。
で、ひょっとして。。。。 と思ってみたものは Ruby の Dir.glob のリファレス
あう。shellの機能じゃなかったのか。。。Rubyの機能か。。。どうりで最近よくみるわけだ。。。
一応確認
$ irb irb(main):001:0> Dir.glob('doc/*/*') => [] irb(main):002:0> Dir.glob('doc/**/*') => ["doc/README_FOR_APP"] irb(main):003:0>
満足した。