macOSでkey repeatが動かない時の対処法
実際はkeyrepeatは作動している。(例えば、$などはブラウザ上でキーリピートするし、Terminalでは問題なく動く) この現象のときは、下記をターミナルを開いて打つ。
defaults write -g ApplePressAndHoldEnabled -bool false
そして、再起動。
Railsで特定のバージョンのmigrationをロールバックする方法
git branchを行ったり来たりしていてしっかり管理しないとlocalでゴミテーブルができるのでしっかりdownさせる。
db:migrate:status
でマイグレーションの状態を確認。
bundle exec rake db:migrate:status
最初の数列をコピペしてそのファイルだけ戻す。
bundle exec rake db:migrate:down VERSION=20190611235049
その後必要ならSQLでmigrationエントリを消す
rails dbconsole > delete from schema_migrations where version = '20190611235049'; #sqlite3
Sidekiqでdelayを使う。しかし、クラスメソッドを使いダイナミックなQueue名を使わない
DelayedJobと比べると使い方が少し違うので注意が必要。
Extentionを読み込むとdelayが使える
config/initializers/sidekq.rb
に下記を追加(存在しない場合は作成)。これで毎回performを書かなくて良い。
Sidekiq::Extensions.enable_delay!
これで、User.delay.my_method
が使える!
https://github.com/mperham/sidekiq/wiki/Delayed-extensions
インスタンスメソッドを使わない
インスタンスメソッドでも一見動いたので大丈夫かと思ったが実際運用してみるとだめだった。クラスメソッドでWrapして使いましょう。よく見ると太字でだめと書かれている。
I strongly recommend avoiding delaying methods on instances. This stores object state in Redis which can get out of date, causing stale data problems.
ランタイム時に動的なQueue名を指定しない
それ用のライブラリが別途あるのでそれを使用。スタティックなQueue使いにくい。。ユーザ毎にキューを用意したい。。
https://stackoverflow.com/questions/20133346/how-can-i-create-sidekiq-queues-with-variable-names-at-runtime
[LXD/LXC] lxd imageのexportとimport方法
LXDのversionは3.03
LXD export
作成してあるコンテナのイメージではなくて初期起動時にダウンロードしてくるOSイメージをexportするにはlxc launch
で指定するイメージ名を引数にいれてexportする。
$ lxc image export ubuntu:18.04 .
LXD import
version3.03ではtar.xzとsquashfsが作成されるのでこれを2つとも指定し、importする。aliasで名前をイメージ名を指定できる。:
(コロン)は使えないので注意。
lxc image import ubuntu-18.04-server-cloudimg-amd64-lxd.tar.xz ubuntu-18.04-server-cloudimg-amd64.squashfs --alias ubuntu18.local
launchまでの速度比較
同じfingerprintのイメージをimageリストに持てないので、ubuntu16と18で比較してますが、、だいたい同じになると思います。
イメージダウンロード後にLaunch
$ time lxc launch ubuntu:16.04 default2 Creating default2 Starting default2 real 3m32.754s user 0m0.059s sys 0m0.027s
約3分半。
importしてlaunch
$ time lxc image import ubuntu-18.04-server-cloudimg-amd64-lxd.tar.xz ubuntu-18.04-server-cloudimg-amd64.squashfs --alias ubuntu18.local Image imported with fingerprint: c234ecee3baaee25db84af8e3565347e948bfceb3bf7c820bb1ce95adcffeaa8 real 0m5.358s user 0m0.171s sys 0m0.551s root@ip-172-31-36-58:~# time lxc launch ubuntu18.local test Creating test Starting test real 0m46.986s user 0m0.026s sys 0m0.005s
52秒ぐらいで2分半は早く起動できることを確認!