2015年3月31日火曜日

mixi iOS Training 第6回に参加してきました

先週の話ですが、mixiのiOS Training 第6回に参加してきました。
これまでとは形式が変わって、TODOアプリを作りながら必要なものを学んでいく形になりました。
http://app-training.connpass.com/event/13059/

教材はこれで、
https://github.com/mixi-inc/iOSTraining-TODO-App
テキストはこれでした。
uitableview

今回はTODOリストを一覧表示するだけの機能だったのですが、
最初の課題のところではまってしまい、あまりメモが取れませんでした。
原因は結局コピペしたところが間違ってたわけですが、
言語の理解が浅いから気づかないのでだめなんだなと反省しています。。。


そんな中メモった内容を載せておきます。
・ショートカット
行を選択してCommand + / でコメントアウト
・pixel指定の話
pixelが少数になった場合は切り捨てられる
・UITableViewのSeparatorは1pxですよ
ここに詳しく載ってます
http://335g.hatenablog.jp/entry/2013/12/25/135219

2015年3月23日月曜日

macにwiresharkをhomebrewで入れる

homebrew便利です。wiresharkも簡単に入れられました。
MacのバージョンはMavericksです。

$ brew install wireshark --with-qt
==> Installing dependencies for wireshark: gettext, libffi, glib, libtasn1, gmp, nettle, gnutls, libgpg-error, libgcrypt, d-bus, geoip, c-ares, qt
==> Installing wireshark dependency: gettext
==> Downloading https://homebrew.bintray.com/bottles/gettext-0.19.4.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring gettext-0.19.4.mavericks.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.
 
Mac OS X provides similar software, and installing this software in
parallel can cause all kinds of trouble.
 
OS X provides the BSD gettext library and some software gets confused if both are in the library path.
 
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
 
    LDFLAGS:  -L/usr/local/opt/gettext/lib
    CPPFLAGS: -I/usr/local/opt/gettext/include
 
==> Summary
🍺  /usr/local/Cellar/gettext/0.19.4: 1920 files,  21M
==> Installing wireshark dependency: libffi
==> Downloading https://homebrew.bintray.com/bottles/libffi-3.0.13.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libffi-3.0.13.mavericks.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.
 
Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.
 
Some formulae require a newer version of libffi.
 
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
 
    LDFLAGS:  -L/usr/local/opt/libffi/lib
 
==> Summary
🍺  /usr/local/Cellar/libffi/3.0.13: 13 files, 388K
==> Installing wireshark dependency: glib
==> Downloading https://homebrew.bintray.com/bottles/glib-2.42.2.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring glib-2.42.2.mavericks.bottle.tar.gz
🍺  /usr/local/Cellar/glib/2.42.2: 410 files,  17M
==> Installing wireshark dependency: libtasn1
==> Downloading https://homebrew.bintray.com/bottles/libtasn1-4.2.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libtasn1-4.2.mavericks.bottle.tar.gz
🍺  /usr/local/Cellar/libtasn1/4.2: 55 files, 568K
==> Installing wireshark dependency: gmp
==> Downloading https://homebrew.bintray.com/bottles/gmp-6.0.0a.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring gmp-6.0.0a.mavericks.bottle.tar.gz
🍺  /usr/local/Cellar/gmp/6.0.0a: 15 files, 3.2M
==> Installing wireshark dependency: nettle
==> Downloading https://homebrew.bintray.com/bottles/nettle-2.7.1.mavericks.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring nettle-2.7.1.mavericks.bottle.1.tar.gz
🍺  /usr/local/Cellar/nettle/2.7.1: 66 files, 1.7M
==> Installing wireshark dependency: gnutls
==> Downloading https://homebrew.bintray.com/bottles/gnutls-3.3.13.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring gnutls-3.3.13.mavericks.bottle.tar.gz
🍺  /usr/local/Cellar/gnutls/3.3.13: 1020 files, 8.8M
==> Installing wireshark dependency: libgpg-error
==> Downloading https://homebrew.bintray.com/bottles/libgpg-error-1.18.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libgpg-error-1.18.mavericks.bottle.tar.gz
🍺  /usr/local/Cellar/libgpg-error/1.18: 17 files, 332K
==> Installing wireshark dependency: libgcrypt
==> Downloading https://homebrew.bintray.com/bottles/libgcrypt-1.6.3.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libgcrypt-1.6.3.mavericks.bottle.tar.gz
🍺  /usr/local/Cellar/libgcrypt/1.6.3: 16 files, 1.3M
==> Installing wireshark dependency: d-bus
==> Downloading https://homebrew.bintray.com/bottles/d-bus-1.8.14.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring d-bus-1.8.14.mavericks.bottle.tar.gz
==> Caveats
To have launchd start d-bus at login:
    ln -sfv /usr/local/opt/d-bus/*.plist ~/Library/LaunchAgents
Then to load d-bus now:
    launchctl load ~/Library/LaunchAgents/org.freedesktop.dbus-session.plist
==> /usr/local/Cellar/d-bus/1.8.14/bin/dbus-uuidgen --ensure=/usr/local/var/lib/dbus/machine-id
==> Summary
🍺  /usr/local/Cellar/d-bus/1.8.14: 39 files, 2.0M
==> Installing wireshark dependency: geoip
==> Downloading https://homebrew.bintray.com/bottles/geoip-1.6.5.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring geoip-1.6.5.mavericks.bottle.tar.gz
🍺  /usr/local/Cellar/geoip/1.6.5: 16 files, 736K
==> Installing wireshark dependency: c-ares
==> Downloading https://homebrew.bintray.com/bottles/c-ares-1.10.0.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring c-ares-1.10.0.mavericks.bottle.tar.gz
🍺  /usr/local/Cellar/c-ares/1.10.0: 57 files, 540K
==> Installing wireshark dependency: qt
==> Downloading https://homebrew.bintray.com/bottles/qt-4.8.6.mavericks.bottle.6.tar.gz
######################################################################## 100.0%
==> Pouring qt-4.8.6.mavericks.bottle.6.tar.gz
==> Caveats
We agreed to the Qt opensource license for you.
If this is unacceptable you should uninstall.
 
.app bundles were installed.
Run `brew linkapps qt` to symlink these to /Applications.
==> Summary
🍺  /usr/local/Cellar/qt/4.8.6: 2790 files, 122M
==> Installing wireshark
==> Downloading https://www.wireshark.org/download/src/all-versions/wireshark-1.12.4.tar.bz2
######################################################################## 100.0%
==> Patching
patching file configure
Hunk #1 succeeded at 16946 (offset 243 lines).
==> ./configure --disable-silent-rules --prefix=/usr/local/Cellar/wireshark/1.12.4 --with-gnutls --disable-gtktest --with-qt
==> make
==> make install
==> Caveats
If your list of available capture interfaces is empty
(default OS X behavior), try the following commands:
 
  curl https://bugs.wireshark.org/bugzilla/attachment.cgi?id=3373 -o ChmodBPF.tar.gz
  tar zxvf ChmodBPF.tar.gz
  open ChmodBPF/Install\ ChmodBPF.app
 
This adds a launch daemon that changes the permissions of your BPF
devices so that all users in the 'admin' group - all users with
'Allow user to administer this computer' turned on - have both read
and write access to those devices.
 
See bug report:
  https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=3760
==> Summary
🍺  /usr/local/Cellar/wireshark/1.12.4: 270 files,  64M, built in 3.8 minutes

wiresharkの起動は以下のコマンドでやります。
$ wireshark-qt

参考URL
http://momijiame.tumblr.com/post/43785788212/mac-os-x-mountain-lion-homebrew-wireshark
http://stackoverflow.com/questions/26242156/install-wireshark-on-macos-x-via-brew

2015年3月18日水曜日

gitでリモートブランチを削除する

gitのリモートブランチを消すことがあるのですが、
やろうとするといつもやり方忘れて調べてるのでここにメモ。

まずはローカルのブランチの削除
$ git branch -d test
Deleted branch test (was 927001f).

ローカルのブランチ削除でエラー出るときは強制的に削除
$ git branch -d test
error: The branch 'test' is not fully merged.
If you are sure you want to delete it, run 'git branch -D test'.
 
$ git branch -D test
Deleted branch test (was 5c0b0be).

続いてリモートブランチの削除。
調べてみたらいくつかやり方があるみたいです。
$ git push origin :test
To git@github.com:syakasyaka/sample.git
 - [deleted]         test

git1.7.0以降からはこちらも使える。
$ git push --delete origin test
To git@github.com:syakasyaka/sample.git
 - [deleted]         test
直感的には後者のやつの方がわかりやすいですね。


参考URL
http://shoma2da.hatenablog.com/entry/2014/03/08/234523
http://blog.koogawa.com/entry/2014/03/08/121751
http://www.backlog.jp/git-guide/reference/remote.html
http://hail2u.net/blog/software/git-push-delete.html

2015年3月13日金曜日

mixi iOS Training第5回に参加してきました

またmixiで開催されたiOS Trainingの勉強会に行ってきました。
http://app-training.connpass.com/event/12473/

最初のゲストインタビューはトレタの@y_kohさんで、
トレタのサービス紹介と開発手法についての発表でした。
トレタではクラッシュレポートにHockeyAppを使ってるそうです。
詳しくはここにあるそうです。
http://qiita.com/y_koh/items/81d8648914a893ec2d16

授業でメモったことをつらつらと書いていきます。

3.3 UIView Animation
https://github.com/mixi-inc/iOSTraining/wiki/3.3-UIView-Animation

・アニメーション止めたりとかはbegin/commitで実装

・xibはpropertyでIBOutletとして読み込ませる


Auto Layout入門
https://github.com/mixi-inc/iOSTraining/wiki/Auto-Layout%E5%85%A5%E9%96%80

・missing constraintsは今の状態で位置と高さと幅が決定できるかどうかで出る。
xcodeが自動で補完する機能あるが、昔は押した結果また出てくるという無限ループに陥ることがあった

・auto layoutはシンプルにしたほうがいい
複雑なものを後から見たりすると死にたくなる


Auto Layout ドリル
https://github.com/mixi-inc/iOSTraining/wiki/Auto-Layout-%E3%83%89%E3%83%AA%E3%83%AB

・Update Framesで制約に従った場所にviewが移動してくれる
(ずれてないときは実行できない)

・leading edgesとtrailing edges
文章を書くときに先頭に来る方向がleadingで末尾の方がtrailing
多言語対応のためにright,leftではないらしい


次回からはTODOアプリ作りながら学んでく形式。楽しみだ。

2015年3月9日月曜日

railsでfind_each使った時にはまった件

railsでバッチ処理を書いててfind_eachを使おうとしたらエラーではまった時にやったことです。

まず最初はこんな感じのテーブルにしていました。
mysql> desc mail_send_targets;
+-------------+------------+------+-----+---------+-------+
| Field       | Type       | Null | Key | Default | Extra |
+-------------+------------+------+-----+---------+-------+
| user_id     | bigint(20) | NO   | MUL | NULL    |       |
| item_id     | bigint(20) | NO   | MUL | NULL    |       |
| expire_date | datetime   | NO   |     | NULL    |       |
+-------------+------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

このテーブルに対して、こういうコードを書いたところ、実行したらエラーがでました。
targets = MailSendTarget.where(item_id: item_id)
targets.find_each(batch_size: 2000) do |target|
  #処理
end

ERROR -- : Mysql2::Error: Unknown column 'mail_send_targets.' in 'order clause': SELECT  `mail_send_targets`.* FROM `mail_send_targets`  WHERE `mail_send_targets`.`item_id` = 96  ORDER BY `tmp_mail_send_targets`.`` ASC LIMIT 2000 (ActiveRecord::StatementInvalid)

エラーの内容を見ていくと、ORDER BYのカラムが指定されていなくて、
どうやらprimary keyをorder byに指定するようなので、
テーブルにprimary keyを設定する必要がありそうです。
mysql> desc mail_send_targets;
+-------------+------------+------+-----+---------+-------+
| Field       | Type       | Null | Key | Default | Extra |
+-------------+------------+------+-----+---------+-------+
| id      | bigint(20) | NO   | PRI | 0       |       |
| user_id     | bigint(20) | NO   | MUL | NULL    |       |
| item_id     | bigint(20) | NO   | MUL | NULL    |       |
| expire_date | datetime   | NO   |     | NULL    |       |
+-------------+------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

プライマリーキーを設定したところ、エラーが起こらずに処理が流れるようになりました。

2015年3月3日火曜日

jenkinsでrubocop実行したらジョブがエラーになった時の対応

rubocopで定期的にコーディングチェックをしたかったので、
jenkinsで実行したらジョブがエラーになったので調べました。
前提として、rubocopで警告が1個以上出る状態で実行しています。
jenkinsのバージョンは1.599-1.1

jenkinsのジョブでシェルの実行に以下を追加してジョブを実行する
bundle exec rubocop --debug --rails --no-color --require rubocop/formatter/checkstyle_formatter --format RuboCop::Formatter::CheckstyleFormatter --out test/reports/checkstyle.xml
実行してみたらこんな感じでfailureになりました。
12:32:28 + bundle exec rubocop --debug --rails --no-color --require rubocop/formatter/checkstyle_formatter --format RuboCop::Formatter::CheckstyleFormatter --out test/reports/checkstyle.xml
12:32:29 warning: parser/current is loading parser/ruby21, which recognizes
12:32:29 warning: 2.1.5-compliant syntax, but you are running 2.1.4.
12:32:36 For /var/lib/jenkins/jobs/test/workspace: configuration from /var/lib/jenkins/jobs/test/workspace/.rubocop.yml
12:32:36 Inheriting configuration from /var/lib/jenkins/jobs/test/workspace/.rubocop_todo.yml
12:32:36 Default configuration from /var/lib/jenkins/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rubocop-0.28.0/config/default.yml
12:32:36 Inheriting configuration from /var/lib/jenkins/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rubocop-0.28.0/config/enabled.yml
12:32:36 Inheriting configuration from /var/lib/jenkins/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rubocop-0.28.0/config/disabled.yml
12:32:36 Scanning /var/lib/jenkins/jobs/test/workspace/Gemfile
12:32:36 Scanning /var/lib/jenkins/jobs/test/workspace/Rakefile
12:32:36 Scanning /var/lib/jenkins/jobs/test/workspace/Capfile
・・・・
12:32:53 Finished in 23.879888448 seconds
12:32:53 Build step 'シェルの実行' marked build as failure

シェルの内容を最後に必ずexit 0を返す以下に変更してみたが状況は変わらず。。
bundle exec rubocop --debug --rails --no-color --require rubocop/formatter/checkstyle_formatter --format RuboCop::Formatter::CheckstyleFormatter --out test/reports/checkstyle.xml
exit 0

jenkinsについて調べてみると、jenkinsのシェルの実行は
/bin/sh -xe
で実行されているので、0でない終了コードが出た時点でスクリプトが終了するらしい。

シェルの内容を以下に変更してみる
/bin/sh -x
bundle exec rubocop --debug --rails --no-color --require rubocop/formatter/checkstyle_formatter --format RuboCop::Formatter::CheckstyleFormatter --out test/reports/checkstyle.xml
exit 0

再度実行してみると無事に成功しました。
12:44:42 + bundle exec rubocop --debug --rails --no-color --require rubocop/formatter/checkstyle_formatter --format RuboCop::Formatter::CheckstyleFormatter --out test/reports/checkstyle.xml
12:44:43 warning: parser/current is loading parser/ruby21, which recognizes
12:44:43 warning: 2.1.5-compliant syntax, but you are running 2.1.4.
12:44:50 For /var/lib/jenkins/jobs/test/workspace: configuration from /var/lib/jenkins/jobs/test/workspace/.rubocop.yml
12:44:50 Inheriting configuration from /var/lib/jenkins/jobs/test/workspace/.rubocop_todo.yml
12:44:50 Default configuration from /var/lib/jenkins/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rubocop-0.28.0/config/default.yml
12:44:50 Inheriting configuration from /var/lib/jenkins/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rubocop-0.28.0/config/enabled.yml
12:44:50 Inheriting configuration from /var/lib/jenkins/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rubocop-0.28.0/config/disabled.yml
12:44:50 Scanning /var/lib/jenkins/jobs/test/workspace/Gemfile
12:44:50 Scanning /var/lib/jenkins/jobs/test/workspace/Rakefile
12:44:50 Scanning /var/lib/jenkins/jobs/test/workspace/Capfile
・・・
12:45:07 Finished in 23.688404726 seconds
12:45:07 + exit 0


参考URL
http://qiita.com/mechamogera/items/f689b95670127d5bf046