2020/02/24~2020/03/08のメモ

だいぶサボってた…

catalinaにjava sdkをインストールする

これが正解なのかわからないがbrewでいれた。

brew install java11
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk

circleciのrubyイメージでmysql2 gemがうまく使えない

  • circleci/ruby:2.3.7-node-browsers
    • そもそもこれが古い
  • mysql2は0.5.2
  • インストールは成功するが、いざ使う段になって次のエラーがでる
    • LoadError: libmysqlclient.so.18: cannot open shared object file: No such file or directory - /home/circleci/repo/vendor/bundle/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/mysql2.soになる
  • 原因はgemのキャッシュだった。Dockerのimageが変わるときにはgemのキャッシュをpurgeされるようにしておいたほうがいいのかも?

ruby - Sunspot/Solr: indexing a time field results in NumberFormatException - Stack Overflow

  • Dockerで用意したsolrがデフォルト設定なので、2gram前提で作っているテストがコケた

    • solrにschema設定してデータをpostする - Qiita
    • のようにRESTで設定を突っ込むとよいのかな
      • これはsolr6からっぽい(と思ったがdockerhubのsolr5系ではAPIがデフォルトになっていそう)
      • RESTで設定を投入できることを確認したが、そもそもデフォルトで用意されている設定とsunspotが想定している設定はかなり違いそうなので、xmlで用意してあげるのが良さそう
    • solrconfig.xmlの一部設定を変更することでschema.xmlを読みに行かせることができる
    • sunspotはsolr7系以上で使えるschema.xmlを用意している
    • ワンチャン使えるかな?と思ってsolr5.5で試してみたけどだめだったのでsolr7系を使うように変更した
    • Apache Solr設定メモ - Qiita
      • solrconfig、schema.xmlを使うためには7のやつにschema.xmlを使う設定を足すだけではだめだった
      • 不要な設定を↑を参考に削除した
  • Dockerfileを作って、developmentのとtestのcoreをbuild時に作るようにした

  • sunspot.ymlはERB使える模様

cp — Docker-docs-ja 17.06.Beta ドキュメント

dockerでscpみたいなのできるのかな…と思っていたが普通にできましたね…

docker pushのお作法

  • たまにしかやらないので忘れる。
  • imageとして willnet/hoge:1.0.0のような名前にしておく必要があった
  • docker tag 今の名前 新しい名前で新しいタグを作れる

CentOS7で実行ファイルの不足している依存関係を解消する(CentOS7でElectronが試せない話に関連して) - Qiita

  • yum whatprovides便利では
  • yum providesでも同じそう

Amazon LinuxでImageMagicK(Imagick)を使う | ハックノート

古い環境に古いimagemagickインストールバトルつらい…

RPMパッケージをインストール/アンインストールするには

↑でimagemagickyum経由でインストールするには、関連するrpmを都度インストールして依存関係を満たして上げる必要がありそう。めんどい

bundle installした古いバージョンのgemが参照されている

bundle -v
Bundler version 2.1.4
bundle clean

したら解消(当たり前だけど)した。gemコマンドもしくはbundlerかなあ…。

sidekiqでメール送信したときにエラーになってもsentryには通知したくない

  • どうせすぐリトライするので、少なくともerrorではなくてwarnかinfo程度にしておきたい
  • 数回ためして全部ダメだったら初めてerrorとして通知したい
  • Error Handling · mperham/sidekiq Wiki
    • 規定のリトライ回数実行してもだめだったときの処理を↓のように書ける
    • ので、workerの設定側で
      • 基本的にはwarnでSentryに投げる
      • sidekiq_retries_exhaustedではerrorで投げる
      • のようにすれば目的達成できるかな
class FailingWorker
  include Sidekiq::Worker

  sidekiq_retries_exhausted do |msg, ex|
    Sidekiq.logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}"
  end
  
  def perform(*args)
    raise "or I don't work"
  end
end
  • しかし↑で書いたやり方だと、sentryが定義しているやりかたを完全に上書きするようになってしまう。なんかもうちょっとスマートなやり方ないかな
  • sentryはこんな感じでsidekiqのerror_handlersを定義して、server_middlewareにsentry用のmiddlewareを追加している raven-ruby/sidekiq.rb at master · getsentry/raven-ruby
    • sidekiqのcontextに、何回目のエラーであるという情報は含まれないのだろうか
    • sentryの実際のエラーページ見た感じだと含まれてなさそう?
  • 結局、自作のerror_handlersを定義する必要があるかな
    • ravenの読み込み方を工夫すると、sidekiq用のコードを読ませずにロードできそう
      • gem 'sentry-raven, require: 'sentry-raven-without-integrations'
      • ドキュメントもあった
  • error_handlersに失敗回数渡せるのかな
    • ざっと見た感じでは渡せていそうなので、頑張ればできるか
    • だれか他にやってる人いるんじゃないのかな…

elasticsearch

How should I generate an API key that allows me to use the Heroku Platform API? - Heroku Help

  • herokuのAPIをこれを使って生成してみた
  • いつの間にか2酒類API token(それぞれ有効期限が違う)が使えるようになっていたらしい

Chromeで自己証明書(などの不正証明書)を使用したサイトにアクセスする方法 - Qiita

Promise#finally

finallyという名前から、いつ登録しても最後に呼ばれるのでは?と勘違いしていまったが普通に登録した順ですね…。

Promise.resolve(1).then((v) => { console.log(v); return v }).finally((v) => console.log('finally'))
VM502:1 1
VM502:1 finally
Promise {<resolved>: 1}
Promise.resolve(1).finally((v) => console.log('finally')).then((v) => { console.log(v); return v })
VM516:1 finally
VM516:1 1

Type 'string' is not assignable to type 'RequestCredentials' · Issue #21618 · microsoft/TypeScript

  • これはこういうものらしい
  • 最初objectのpropertyとして定義されるときに型が推測されるのでstringとして扱われてしまう
  • fetchの引数として即突っ込む場合はRequestCredentialsと判断される
  • ↓のようにしたら通った
    let options = {
      # ...
      credentials: <RequestCredentials>'include'
    }

RubyMineを使っているならReformatでもっと幸せになろう | mah365

rubymine弱なので、どこかからコピペしたコードのインデントがずれていたときに手動でインデント直したりしていた。reformatという単語だけ覚えておけば次からなんとかなりそう

2020/02/18~23のメモ

Application Security Management Platform | Sqreen

雑に眺めたので間違ってるかもだけど

  • アプリケーションサーバに対するファイヤウォール
  • エージェント(かな?)をアプリケーションサーバにインストールして、攻撃を検知する
  • 試すのはともかくお値段だいぶ高そうなので、ちゃんと売上の立っていてかつセンシティブなサービスでないと導入が難しそうな雰囲気がある
  • 小さいサービス(3Mリクエスト/月)なら無料で使えるので手持ちのサービスにいれて雰囲気を掴んでみたい

Develop. Preview. Ship. - ZEIT

  • 無料でサーバレス環境使えるのは便利そうではある
  • rubyも使えるっぽい

que-rb/que: A Ruby job queue that uses PostgreSQL's advisory locks for speed and reliability.

  • better delayed_jobっぽい
  • postgres限定
  • postgres のadvisory lockを使っているので速いとのこと

ghq

  • brew upgrade ghqでバージョンアップしたらメジャーバージョンがあがり非互換な変更が入っていた
  • デフォルトのディレクトリが~/.ghqから~/ghqに変更されていた
  • 単純にmv .ghq ghqとして対応

  • yoshiori/fish-peco_select_ghq_repository がうまく動かなくなった

    • そもそも↑でghq配下のリポジトリに移動すると、ghqやfishのプロセスが残ってしまって標準入力を奪っているような挙動を見せることがあってなんとかしたいな、と思ってバージョンアップを始めたのだった
    • が、バージョン上げたらそもそも動かなくなったぞ

fishのお作法がよくわかっていない

fish-peco_select_ghq_repository/peco_select_ghq_repository.fish at master · yoshiori/fish-peco_select_ghq_repository を読みつつ何をやっているのかざっと書く

function peco_select_ghq_repository
  ghq list | peco | read line

  if [ $line ]
    cd (ghq list --full-path --exact $line)
    commandline -f repaint
  end
end

yarn

yarn install --frozen-lockfile

でyarn.lockが更新されないことを保証できる。yarn.lockがpackage.jsonの記述を満たさないときは通常yarn.lockは更新されるのだけど、このオプションではそれを抑制できるっぽい

yarn install | Yarn

webpackerってどうやって最新のnpmがインストールされていることを確認しているんだっけ

NOTE: The command yarn check has been historically buggy and undermaintained and, as such, has been deprecated and will be removed in Yarn 2.0. You should use yarn install --check-files instead.

  • yarn checkは使わないほうがいいらしい。
    • これはyarn check単体の話で、yarn check --integrityyarn check --verify-treeはまた別(つかってもよい)のかな?
      • いろいろ見た感じ、どうも同様っぽいぞ
  • yarn check(使わない)はpackage.jsonとyarn.lockとの整合性を見る
  • yarn check --integrityはpackage.jsonとyarn.lockとの整合性と、yarn.lockのハッシュ値が正しいかを見る
  • yarn check --verify-treeはpackage.jsonnode_modules配下に置いてあるファイルのバージョンとの整合性を見る(yarn.lockは見ない)

  • Remove yarn check by arcanis · Pull Request #106 · yarnpkg/rfcs

It has to do with the way we make an early bailout if the node_modules is already there (to avoid running an installation if there is no need). Without --check-files Yarn will only checks for the various folders to exist (plus various other settings), whereas with --check-files it will also check for all the registered files to exist. It's not super useful anymore, but it's not as redundant as yarn check.

  • yarn install --check-filesはインストール前にnode_modeles配下をちゃんとファイル単位で見る、というのが--check-filesなしとの違いのよう

Add strict_loading mode to optionally prevent lazy loading by eileencodes · Pull Request #37400 · rails/rails

lazy loadingしないぞ!という強い決意を示したいとき(どういうときだろ)に使えそう

Spark

2020/02/17のメモ

Linux Tips – RAMディスク(/dev/shm)のIO性能をチューニングに活用する方法

yumリポジトリ追加リスト 完全版 - Qiita

Amazon Linux 2 EC2 インスタンスに Extras Library からソフトウェアをインストールする

こんな仕組みあるの知らなかったな

Amazon Linux 2のExtras Library(amazon-linux-extras)を使ってみた | Developers.IO

2020/02/16のメモ

Modern site search for companies of all sizes | Algolia

elasticsearch用のgem

searchkickとchewyはどちらもelasticsearch-rubyベース

deviseを所有しているorgが変わっていた

For all other Open Source projects under the Plataformatec organization on GitHub, we will reach out to the current maintainers and take the necessary steps to transfer the ownership of all relevant assets, including names, source code, and logos of such projects.

Important information about our Elixir and Ruby Open Source projects « Plataformatec Blog

ということで、買収がきっかけで別の人にOSSプロジェクトを引き渡したってことかな。

heartcombo

SQLite3の実際の型 - すがブロ

2020/02/14のメモ

macにmongodbをインストール

brew install mongodbではだめだった。

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

brew tap mongodb/brew
brew install mongodb-community@4.2

↓で起動

mongod --config /usr/local/etc/mongod.conf

MongoDBのデータダンプとリストア - Qiita

mysqldumpっぽさある

What is an "Unregistered User"? – CircleCI Support Center

  • circleciに一度もsignupしていないユーザはUnregistered User
  • signupしても過去Unregistered Userとなっていたものは更新されない

2020/02/13のメモ

GitHub CLI Beta | Take GitHub to the command line

  • hubを完全に置き換えられるのかな
  • 現時点ではそうではなさそう
Work seamlessly with GitHub from the command line.

GitHub CLI is in early stages of development, and we'd love to hear your
feedback at <https://forms.gle/umxd3h31c7aMQFKG7>

Usage:
  gh [command]

Available Commands:
  help        Help about any command
  issue       Create and view issues
  pr          Create, view, and checkout pull requests

Flags:
      --help              Show help for command
  -R, --repo OWNER/REPO   Select another repository using the OWNER/REPO format
      --version           Show gh version

Use "gh [command] --help" for more information about a command.

2020/02/12のメモ

rollbar

  • githubのように、一つのアカウントが複数のorganizationに所属できるイメージだったんだけどうまくorganizsationへの追加ができなかった
  • 招待メールアドレスをユーザに追加しておくのが条件っぽい(メールアドレスを追加したらいけた)

Refactoring Rails

Investigate libxml2 vulnerabilities patched in USN-4274-1 · Issue #1992 · sparklemotion/nokogiri

Merge pull request #37174 · rails/rails@a6cf649

  • ActiveSupport::Concernにprependサポートが入った
  • (使うかどうかはさておき)なるほど感ある