helen's blog

ずっとおもしろいことしてたいな。

$ git show-branchって意外と使えるかもしれない

masterをチェックアウトして実行してみた

$ git show-branch
! [aaaaa] Revert "Merge pull request #1 in studygit from develop to master"
 ! [bugfix/revert-merge-commit] Revert "Merge pull request #1 in studygit from develop to master"
  ! [develop] Merge pull request #7 in studygit from feature/fuga to develop
   ! [feature/helen] ゴミコミット
    ! [feature/study-git] untracked branch commit
     * [master] Merge pull request #8 in studygit from release/0420 to master
      ! [real/hoge] testagdhkcl;f
       ! [release/0420] Merge pull request #7 in studygit from feature/fuga to develop
--------
     -   [master] Merge pull request #8 in studygit from release/0420 to master
  -  - - [develop] Merge pull request #7 in studygit from feature/fuga to develop
  -  - - [develop^2] Merge branch 'master' into feature/fuga
  -  - - [master^] Merge pull request #2 in studygit from bugfix/revert-merge-commit to master
+++  * + [aaaaa] Revert "Merge pull request #1 in studygit from develop to master"
  -  - - [master~2] Merge pull request #1 in studygit from develop to master
  -  - - [develop^] Merge pull request #4 in studygit from feature/fuga to develop
  +  * + [develop^2^] feature/fuga this is my first commit
  +  * + [develop~2^2] ふがこみっと
  +  * + [develop~3^2] ごみ.txt コミット
      +  [real/hoge] testagdhkcl;f
    +    [feature/study-git] untracked branch commit
    +    [feature/study-git^] initial commit at feature
   +     [feature/helen] ゴミコミット
+++++*++ [develop~4] initial commit at develop

見方

  • 「---------」より上がローカルブランチ
  • -aで追跡ブランチ、ローカルブランチの両方が見れる
  • *がついてるのが今のブランチ
  • 色がないとわからないけど左側の記号はiTermだと色がついててどのブランチのコミットかわかる

コミットの参照

[feature/study-git^]とか[real/hoge]とか
今のブランチからたどれるコミットとたどり方がわかる

ブランチがどこまでマージされているかを調べる

$ git show-branch branchA branchB

masterとdevelopを比較してどこまでマージされてるか調べれる

ブランチの派生元を調べる

$ git show-branch branchA branchB | tail -1

$ git show-branch master develop
git show-branch master develop
! [master] Merge pull request #8 in studygit from release/0420 to master
 ! [develop] Merge pull request #7 in studygit from feature/fuga to develop
--
-  [master] Merge pull request #8 in studygit from release/0420 to master
-- [develop] Merge pull request #7 in studygit from feature/fuga to develop

一番下の行が派生元
この場合はdevelopが派生元
派生元コミットを参照するときはdevelopで見れる
tail -1で派生元ブランチ、派生元コミットがわかる

参考:Git - git-show-branch Documentation

BrowserifyRails::BrowserifyError

エラー内容

BrowserifyRails::BrowserifyError in Test#index

Extracted source (around line #7):
7: <%= javascript_include_tag "application", 'data-turbolinks-track' => true %>

ActionView::Template::Error (Unable to run node_modules/.bin/browserify. Ensure you have installed it with npm.

nodeのbrowserifyっていうのが動かないからインストールされてるか確認して、だそうです

されてませんでした

browserify

  • Nodeっぽくrequire()が使えるようになる
  • 1つのJSファイルにまとめてくれる
  • Browserify
# インストール
$ npm install browserify --save

# 確認
BrowserifyRails::BrowserifyError in Test#index

Extracted source (around line #7):
7: <%= javascript_include_tag "application", 'data-turbolinks-track' => true %>

ActionView::Template::Error (Unable to run node_modules/.bin/browserifyinc. Ensure you have installed it with npm.

今度はnodeのbrowserifyincがインストールされていないようです

browserifyinc

# インストール
$ npm install browserify-incremental --save

# 確認
Error: Cannot find module 'reactify' from './app/assets/javascripts/components'

次はreactify

reactify

  • JSXをJSに変換してくれる
  • reactifyでJSXをJSに変換し、browserifyがブラウザでNodemoduleを使えるようにしてる
# インストール
$ npm install reactify --save

わーいとりあえずバックエンドのエラーは消えたぞー
つぎはフロントのエラーだー(⌒▽⌒)


そしてどうでもいいんだけどreactifyだけアクセスできなかった

jQuery3.0のRC版が出たから読んでみた

今日はこっちを読みます
jQuery 3.0 Release Candidate…Released! | Official jQuery Blog

Major changes

jQuery.Deferred is now Promises/A+ compatible

  • jQuery.DeferredがPromises/A+とES2015Promiseの互換性を持った
  • 以前はExceptionが.then()にスローされるとcallbackをやめ、親と子のDeferredオブジェクトをロックしていた
  • 子要素、孫要素がコールバックする前に親要素のログが出るようになった

コールバックを操作して要素のコールバックを見てログに出してくれるようになったらしい

あとPromises/A+っていうJSの標準仕様があるらしい
GitHub - promises-aplus/promises-spec: An open standard for sound, interoperable JavaScript promises—by implementers, for implementers.

Added .catch() to Deferreds

  • promiseオブジェクトにcatch()メソッドが追加された

Error cases don’t silently fail

  • 変なリクエストを無視するのではなくエラーを返すようになった
  • 3.0を試すなら無効な値をjQueryによって隠していないか確認したほうがいいらしい

Removed deprecated event aliases

  • 1.8から非推奨になった.load、.unload、.errorを削除
  • .onを使いましょう

Animations now use requestAnimationFrame

  • requestAnimationFrameAPIを使ってアニメーション
  • 動きがスムーズになってCPU時間を減らし、スマホのバッテリーを節約

Massive speedups for some jQuery custom selectors

  • jQueryセレクタが超高速になった
  • :visible, :hiddenなどはブラウザの処理速度に依存するが使いたいことが多いので最悪の場合CSSとレイアウトの再計算が起こる
  • :visible, :hiddenなどの使用を止めないけどテスト推奨

ざっくりしてて全然わからん
使ってみないと全然わからん

眠くなってきた

次回はこっち
jQuery Core 3.0 Upgrade Guide | jQuery

npm installしたときに出てるやつ

赤い文字で表示されるからエラーに見えて気持ち悪いのできれいにした

UNMET DEPENDENCY

原因:依存関係がインストールされてない

UNMET DEPENDENCY react@^0.12.2

$ npm install react --save

他にもreactでエラーしてたので
バージョン指定なしでインストールしてみたら15.1.0が入った

UNMET PEER DEPENDENCY

原因:プロジェクトに必要なパッケージがインストールされてない
今回はmaterial-uiで必要なパッケージがなくて怒られた

そのまま $ npm install react-dom@^15.0.0 って書いたらだめだった
react-dom@15.0.0が正解
参考:react-dom

npm WARN EPEERINVALID material-ui@0.15.0 requires a peer of react@^15.0.0 but none was installed.

$ npm install react-dom@15.0.0 --save

npm WARN EPEERINVALID

原因:別のパッケージで依存先がインストールされてない

# react-addons-create-fragmentはreact@^15.0.2が必要だけど入ってません
npm WARN EPEERINVALID react-addons-create-fragment@15.0.2 requires a peer of react@^15.0.2 but none was installed.

$npm install react --save

reactのバージョン気にしてなかったけどまあ良いや

WARN EPACKAGEJSON

原因:package.jsonになんらかの記入漏れがある

npm WARN EPACKAGEJSON <project_name>@ No repository field.
npm WARN EPACKAGEJSON <project_name>@ No license field.

下の方にこれが出てたので以下追記

"repository": "<project_name>",
"license": "ISC"

ググるとlicenseはMITとか(BSD)MITとか書いてあるのが見つかるけど
これじゃなきゃまずいっていうのは特になさげで
npmのv3.3.12でinitした時にデフォルトでISCが入ったからこれでいいかなと
この2つが書いてあればとりあえずWARNは消える

いろいろやってごちゃごちゃになった気がしたので抹消して再インストールした

エラーが消えてすっきりしたのとインストール先間違えたりしたので
一旦キャッシュ消してパッケージをきれいにしといた

$ npm cache clean

# 結局ディレクトリ一旦消すほうが掃除になってよかった
$ rm -rf node_modules/
$ npm install

わーいすっきり(⌒▽⌒)
でもまだエラーで動かないぞー(⌒▽⌒)

chkconfigって結局なんなんだ

よくわかってなかったのでひたすら和訳してみた

$ man chkconfigしてみた

CHKCONFIG(8)                                                      CHKCONFIG(8)

NAME
       chkconfig - updates and queries runlevel information for system services

SYNOPSIS
       chkconfig [--list] [--type type][name]
       chkconfig --add name
       chkconfig --del name
       chkconfig --override name
       chkconfig [--level levels] [--type type] name <on|off|reset|resetpriorities>
       chkconfig [--level levels] [--type type] name

DESCRIPTION
       chkconfig  provides  a simple command-line tool for maintaining the /etc/rc[0-6].d directory hierarchy by relieving system administrators of
       the task of directly manipulating the numerous symbolic links in those directories.

       This implementation of chkconfig was inspired by the chkconfig command present in the IRIX operating system. Rather than maintaining config-
       uration  information  outside  of  the /etc/rc[0-6].d hierarchy, however, this version directly manages the symlinks in /etc/rc[0-6].d. This
       leaves all of the configuration information regarding what services init starts in a single location.

       chkconfig has five distinct functions: adding new services for management, removing services from management, listing the current startup  information  for  services,  changing  the
       startup information for services, and checking the startup state of a particular service.

       When  chkconfig  is run with only a service name, it checks to see if the service is configured to be started in the current runlevel. If it is, chkconfig returns true; otherwise it
       returns false. The --level option may be used to have chkconfig query an alternative runlevel rather than the current one.

        ...

       By default, the on and off options affect only runlevels 2, 3, 4, and 5, while reset and resetpriorities affects all of the runlevels.  The --level option may  be  used  to  specify
       which runlevels are affected.

       Note that for every service, each runlevel has either a start script or a stop script.  When switching runlevels, init will not re-start an already-started service, and will not re-
       stop a service that is not running.

        ...
  • chkconfigは/etc/rc[0-6].dディレクトリを管理するシンプルなコマンドラインツール
  • /etc/rc[0-6].dディレクトリのシンボリックリンクでタスクを管理する
  • /etc/rc[0-6].dの階層外に設定情報を持たない
  • デフォルトでレベル2−5に対して設定される
  • --levelを使うのは特定のランレベルに設定したいとき
  • ランレベルを変えてもサービスの再起動・停止はしない
  • ランレベルを変えても起動していないサービスは再停止しない

見てみた

# この階層でレベルが決まる
$ ll /etc
lrwxrwxrwx.  1 root root     10 Oct 30  2013 rc0.d -> rc.d/rc0.d
lrwxrwxrwx.  1 root root     10 Oct 30  2013 rc1.d -> rc.d/rc1.d
lrwxrwxrwx.  1 root root     10 Oct 30  2013 rc2.d -> rc.d/rc2.d
lrwxrwxrwx.  1 root root     10 Oct 30  2013 rc3.d -> rc.d/rc3.d
lrwxrwxrwx.  1 root root     10 Oct 30  2013 rc4.d -> rc.d/rc4.d
lrwxrwxrwx.  1 root root     10 Oct 30  2013 rc5.d -> rc.d/rc5.d
lrwxrwxrwx.  1 root root     10 Oct 30  2013 rc6.d -> rc.d/rc6.d

# mysqldは2~5がon
$ chkconfig --list mysqld
mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

# mysqldを全部見てみた
$ ll rc.d/rc0.d | grep mysqld
lrwxrwxrwx  1 root root 16 Mar 17 08:41 K36mysqld -> ../init.d/mysqld
$ ll rc.d/rc1.d | grep mysqld
lrwxrwxrwx  1 root root 16 Mar 17 08:41 K36mysqld -> ../init.d/mysqld
$ ll rc.d/rc2.d | grep mysqld
lrwxrwxrwx  1 root root 16 Mar 17 08:41 S64mysqld -> ../init.d/mysqld
$ ll rc.d/rc3.d | grep mysqld
lrwxrwxrwx  1 root root 16 Mar 17 08:41 S64mysqld -> ../init.d/mysqld
$ ll rc.d/rc4.d | grep mysqld
lrwxrwxrwx  1 root root 16 Mar 17 08:41 S64mysqld -> ../init.d/mysqld
$ ll rc.d/rc5.d | grep mysqld
lrwxrwxrwx  1 root root 16 Mar 17 08:41 S64mysqld -> ../init.d/mysqld
$ ll rc.d/rc6.d | grep mysqld
lrwxrwxrwx  1 root root 16 Mar 17 08:41 K36mysqld -> ../init.d/mysqld

Kが停止、Sが起動で番号順に実行される
on,offに合わせて起動シェル終了シェルにシンボリックリンクがある

試してみた

# 2~5がonになっている
$ chkconfig --list mysqld
mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

# 2をオフにして確認
$ sudo chkconfig --level 2 mysqld off
$ chkconfig --list mysqld
mysqld         	0:off	1:off	2:off	3:on	4:on	5:on	6:off

# シンボリックリンクを見る
$ ll rc.d/rc0.d | grep mysqld
lrwxrwxrwx  1 root root 16 May 18 10:19 K36mysqld -> ../init.d/mysqld
$ ll rc.d/rc1.d | grep mysqld
lrwxrwxrwx  1 root root 16 May 18 10:19 K36mysqld -> ../init.d/mysqld
$ ll rc.d/rc2.d | grep mysqld # Kになってる
lrwxrwxrwx  1 root root 16 May 18 10:19 K36mysqld -> ../init.d/mysqld
$ ll rc.d/rc3.d | grep mysqld
lrwxrwxrwx  1 root root 16 May 18 10:19 S64mysqld -> ../init.d/mysqld
$ ll rc.d/rc4.d | grep mysqld
lrwxrwxrwx  1 root root 16 May 18 10:19 S64mysqld -> ../init.d/mysqld
$ ll rc.d/rc5.d | grep mysqld
lrwxrwxrwx  1 root root 16 May 18 10:19 S64mysqld -> ../init.d/mysqld
$ ll rc.d/rc6.d | grep mysqld
lrwxrwxrwx  1 root root 16 May 18 10:19 K36mysqld -> ../init.d/mysqld

すげー

ランレベルとは

$ cat /etc/inittab

...

# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault: # centosが起動したときは3っていう設定
...

0:停止中
1:シングルユーザモード(rootだけ)
2:NFSなしマルチユーザーモード複数人で使用できて、CUIGUIか選べる)
3:マルチユーザモード
4:未使用
5:X11(っていうGUIらしい)
6:再起動

ディストリビューションによって微妙に違うらしい

今のランレベルを調べる

$ runlevel
N 3

一時的にランレベルを変更する

# 5にしようと思ったら再起動しろって言われた
$ init 5
init: Need to be root

ちなみにhelpしてもそんなに出ない

$ chkconfig --help
chkconfig version 1.3.49.3 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage:   chkconfig [--list] [--type <type>] [name]
         chkconfig --add <name>
         chkconfig --del <name>
         chkconfig --override <name>
         chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>

シンボリックリンクで管理するのが衝撃的でした
そしてググってもまともな情報がでない世の中を見てしまいました( ´∀` )