hotoolong's blog

プログラムのことやエンジニアリングに関することを記事にしています。

tmux が 2.7 にバージョンが上がっていたので brew で アップデートする。

⋊> ~ brew info tmux                                                                                                                                                                                                                                                                                                                                                 21:47:47
tmux: stable 2.7 (bottled), HEAD
Terminal multiplexer
https://tmux.github.io/
/usr/local/Cellar/tmux/2.3_2 (10 files, 651.9KB)
  Poured from bottle on 2017-01-04 at 10:50:53
/usr/local/Cellar/tmux/2.5 (10 files, 660.3KB)
  Poured from bottle on 2017-09-19 at 00:14:09
/usr/local/Cellar/tmux/2.6 (10 files, 688.6KB) *
  Poured from bottle on 2018-02-11 at 15:02:02
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/tmux.rb
==> Dependencies
Build: pkg-config ✔
Required: libevent ✔
Optional: utf8proc ✘
==> Options
--with-utf8proc
        Build with utf8proc support
--HEAD
        Install HEAD version
==> Caveats
Example configuration has been installed to:
  /usr/local/opt/tmux/share/tmux

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

tmuxの2.7が既に出ていたのでバージョンアップしてみる。

⋊> ~ brew update tmux                                                                                                                                                                                                                                                                                                                                               21:47:59
Error: This command updates brew itself, and does not take formula names.
Use 'brew upgrade tmux' instead.
⋊> ~ brew upgrade tmux                                                                                                                                                                                                                                                                                                                                              22:03:53
Updating Homebrew...
==> Auto-updated Homebrew!
Updated Homebrew from 760a4601 to 27ec9dae.
Updated 2 taps (homebrew/core, caskroom/cask).
==> New Formulae
angle-grinder                                                                                                             libde265                                                                                                                  petsc
==> Updated Formulae
ansible ✔                   aws-shell                   dartsim                     exim                        git-annex                   jenkins-job-builder         libre                       moc                         osquery                     picard-tools                scrcpy                      tgui                        vtk
libuv ✔                     awscli                      dcd                         faas-cli                    git-fixup                   jetty                       librem                      mongo-orchestration         osrm-backend                pipenv                      scw                         thefuck                     watson
node ✔                      baresip                     dehydrated                  ffmbc                       gitlab-runner               joplin                      libsass                     mpd                         ott                         ppsspp                      sdl2_gfx                    tika                        webp
nvm ✔                       basex                       diamond                     ffmpeg                      gmt                         jruby                       libtensorflow               mpv                         packer                      pqiv                        sfcgal                      tile38                      wireshark
perl ✔                      bdw-gc                      dnscrypt-proxy              ffmpeg2theora               gmt@4                       json-fortran                libwps                      mpw                         paket                       presto                      sfk                         tippecanoe                  wp-cli
ruby-build ✔                bedops                      docfx                       ffmpegthumbnailer           gollum                      juju                        liquibase                   mruby                       pam-u2f                     primesieve                  shogun                      tokei                       wpcli-completion
vim ✔                       bento4                      docker-compose              ffms2                       gpgme                       jump                        logtalk                     nano                        pam_yubico                  pspg                        shyaml                      travis                      xmrig
abcmidi                     bettercap                   docker-compose-completion   field3d                     grafana                     jvgrep                      makeself                    nco                         pandoc                      puzzles                     silk                        twarc                       xonsh
acpica                      bluepill                    dockviz                     flann                       grib-api                    kallisto                    mame                        ncview                      pandoc-citeproc             pypy3                       siril                       txr                         xrootd
adplug                      bzt                         dscanner                    flow                        gws                         knot-resolver               math-comp                   netcdf                      parallel                    qcli                        skaffold                    uftp                        yaz
annie                       caffe                       dvm                         fluent-bit                  hadolint                    kubernetes-helm             maxwell                     nexus                       pcl                         qemu                        skafos                      unpaper                     ykpers
apache-drill                cake                        dynare                      fn                          haskell-stack               libbi                       meson                       nfdump                      pdal                        quex                        snakemake                   unrar                       youtube-dl
apktool                     cayley                      elasticsearch@2.4           fobis                       hdf5                        libdill                     mg                          nomad                       percona-server              r                           snapcraft                   urh                         zanata-client
arangodb                    cgal                        elasticsearch@5.6           folly                       heroku                      libebml                     mgba                        octave                      percona-server-mongodb      radare2                     sphinx-doc                  utf8proc
armadillo                   checkbashisms               emscripten                  fq                          hugo                        libetonyek                  mighttpd2                   odpi                        percona-toolkit             rmlint                      sratoolkit                  vagrant-completion
artifactory                 cockroach                   encfs                       freeciv                     ice                         libfaketime                 mikutter                    opencv                      php                         robot-framework             subversion                  valabind
aspectj                     convox                      erlang                      freeling                    inspircd                    libmatio                    minidlna                    opencv@2                    php@5.6                     rocksdb                     swimat                      varnish@4
atari800                    coq                         erlang@18                   freeradius-server           instead                     libmatroska                 mkl-dnn                     openfortivpn                php@7.0                     rom-tools                   tee-clc                     vault
aubio                       corsixth                    etcd                        get-flash-videos            iozone                      libmwaw                     mkvtoolnix                  openimageio                 php@7.1                     rtf2latex2e                 telegraf                    vim@7.4
audacious                   cpanminus                   etsh                        gifski                      jenkins                     libraw                      mlt                         openrtsp                    pianobar                    scale2x                     texmath                     visp

==> Upgrading 1 outdated package, with result:
tmux 2.6 -> 2.7
==> Upgrading tmux
==> Downloading https://homebrew.bintray.com/bottles/tmux-2.7.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring tmux-2.7.high_sierra.bottle.tar.gz
==> Caveats
Example configuration has been installed to:
  /usr/local/opt/tmux/share/tmux

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/tmux/2.7: 10 files, 700.7KB

以前痛い目に合ってたので念のためなくなっているもしくは名前が変更されているFormulaeがないことを確認しておいたほうがいい。

今回の2.7での変更点はパフォーマンス改善などが行われている以下のURLで確認できる。

https://raw.githubusercontent.com/tmux/tmux/2.7/CHANGES

尚、以下の一文

* Pass PWD to new panes as a hint to shells, as well as calling chdir().

が少しに気になっていてペインにディレクトリ階層を遅れたりしないのかなと思ったのだけどどうやってやったらいいのか。 そもそもそういうことでは無いってことなのか、調べてもよくわからなかったので、詳しく知りたいところ。。

brew で MySQL8.0をインストールする

MySQL8.0がリリースされましたね。

MySQL8.0の機能

MySQL :: MySQL 8.0: Up to 2x Faster

新機能と以下が上げられています。

  • Document Store
  • Transactional Data Dictionary
  • SQL Roles
  • utf8mb4 character set が Default に
  • 共通テーブル式の追加
  • Window関数の追加
  • 不可視化インディックスの追加
  • 降順インディックスでのパフォーマンス改善?

機能改善として以下が上げられています。

Role設定ができることや、不可視化インディックスなど興味深いですね。

文字コードに関してはデフォルト設定が日本語には少し優しくない状態ですが、 以前よりは改善されてます。

blog.kamipo.net

以前からこの問題に関しては かみぽわーる さんが詳しく取り上げてくれていますね。

デフォルトの collationが utf8mb4_0900_ai_ci になってます。

utf8mb4_bin にしておけば概ね大丈夫ですね。 「MySQL」と「MySQL」を区別したくない場合は utf8mb4_0900_as_cs
私が扱っているサイトでは utf8mb4_bin 一択です。

以下のスライドで collation に関して詳しく書かれているので参考にされたい方は見て下さい。

www.slideshare.net

brew で インストール

かなり高速化されていると謳っているので Macで早速試してみたい方はbrewからインストールしてみてください。 brew optionsを見てみると

⋊>  brew options mysql
--with-debug
        Build with debug support
--with-embedded
        Build the embedded server
--with-local-infile
        Build with local infile loading support
--with-memcached
        Build with InnoDB Memcached plugin
--with-test
        Build with unit tests
--devel
        Install development version 8.0.4-rc

になっているので

⋊>  brew install mysql --devel

で8.0.4-rcがインストール可能です。 よいMySQLライフを!

vim-gitgutterでGitコマンドを使う

以前から行単位で変更箇所を戻すのにGitGutterRevertHunkを使ってたのですが、 vim-gitgutterのバージョンを上げるとコマンド名が変更になっていました。

github.com

.config/nvim/init.vim には以下の用にGitGutterRevertHunk だったのを GitGutterUndoHunk に直しておきました。 快適ですね。

" gitgutter {{{
  " nmap <silent>,gr :<C-u>GitGutterRevertHunk<CR>
  nmap <silent>,gr :<C-u>GitGutterUndoHunk<CR>
" }}}

誤って git reset --hard HEAD^ してしまったので取り消したい

表題通り

git reset --hard HEAD^ 

を取り消したくなったので調べてみました。

以下のreflogコマンドで実行履歴を確認できます。

git reflog -n 5

戻したい場所を確認して、以下のコマンドで指定します。

HEAD@{1}に戻す場合は以下の通り

 git reset --hard "HEAD@{1}"

git reset --soft HEAD^ で良かったものを--hardしてしまってローカルから消えてしまったのでかなり焦ってしまいました。 気をつけないと。

qiita.com

qiita.com

今更ながら「20年目のRubyの真実」を読んだ

2015年の話なんですね。 ちょっと長いですが楽しく読めました。 個人的に以下が面白かったです。

  • 驚き最小の法則が逆にめんどくさい
  • 次の言語来てほしいけど誰も載ってこない
  • RailsRubygemsなどのコミュニティが果たす影響はすごく大きい
  • プロモーションが大事
  • 「あなたは10年前に、Rubyの開発に参加してなかったから発言権はありませんって言われたら、それはフェアじゃないよね。そういうのは嫌なのよね。僕がそう言われたくないからだけど」という感性
  • ここまで未来になってもメモリがボトルネックになっている

興味のある方は読んでみて下さい。

情報処理2015年12月号特集記事「20年目のRubyの真実」インタビュー-情報処理学会

CIでbundle install するときには --clean をつけると無駄にキャッシュされない

タイトルどおりなのですが、 目からウロコだったので、メモとして残しておきます。

Circle CI 2.0 でstore_cache、 restore_cache を使って、Bundler の gem をキャッシュしていたので、 とても参考になります。

ローカル環境でも --clean を付けてもいいのかもしれないですが、 ブランチの切り替え時に毎回インストールしないといけなかったりが多発するようであれば 時々claenしてあげるのがいいのではないでしょうか。

blog.yuyat.jp

MySQLのgroup_concatをつかって複数の項目を1行に並べる

1対多のテーブル構成を多になっているテーブルの情報をgroup_concatを使って表示したくなるケースがあったのですが、 単純に1カラムのデータだけを表示する場合はそのまま使えばいいのですが、 複数を一気に選択することができず、副問合せして取得しました。

usersテーブル、user_optionsテーブルがあるとして 普通にgroup_concatを使ってオプションの名前を登録順に取得するケースは以下になります。

select
 users.id,
 group_concat(distinct user_options.name order by user_options.created_at separator ', ')
from
 users
left outer join user_options on user_options.user_id = users.id

これに対してuser_optionsの複数の項目(nameと登録日)を追加したい場合は joinしてるテーブルを副問合せしてしまって以下のようにしました。

select
 users.id,
 group_concat(distinct user_options.name_created_at order by user_options.created_at separator ', ')
from
 users
left outer join (
  select
   id,
   concat(id, '(', date_format(convert_tz(created_at, '+0:00','+9:00'), '%Y-%m-%d'), ')') as name_created_at,
   created_at
  from
   user_options
)
user_options on user_options.user_id = users.id

このようにすることで,区切りで名称(登録日)の情報が1行で表示されるようになります。 力技なのであまり参考にならないかもしれないですが、表示させるのに困ったときには使ってみて下さい。