hogashi.*

日記から何から

梅雨快晴知恩寺銀閣寺

f:id:hogashi:20210530220025j:plainf:id:hogashi:20210530220036j:plainf:id:hogashi:20210530220048j:plainf:id:hogashi:20210530220101j:plainf:id:hogashi:20210530220112j:plainf:id:hogashi:20210530220124j:plainf:id:hogashi:20210530220141j:plainf:id:hogashi:20210530220150j:plainf:id:hogashi:20210530220201j:plainf:id:hogashi:20210530220212j:plainf:id:hogashi:20210530220237j:plainf:id:hogashi:20210530220251j:plainf:id:hogashi:20210530232441j:plainf:id:hogashi:20210530220332j:plainf:id:hogashi:20210530221031j:plainf:id:hogashi:20210530221040j:plainf:id:hogashi:20210530221053j:plainf:id:hogashi:20210530221106j:plainf:id:hogashi:20210530221118j:plainf:id:hogashi:20210530221130j:plainf:id:hogashi:20210530221145j:plain

文字読むの助走要る

 記事とか本とか、読むのに気持ちの助走がめちゃくちゃ必要になってきていて、なんでなのかと思っていたけど、読んだということにするにはそれなりに内容をちゃんと噛み砕けないと、後でこれ読んだんだどうだったみたいなのを他人から聞かれたり自分で振り返ったりするときに全く思い出せなくて、それは読んでないじゃん、となるのが嫌だなと思っているんだろうなと思った。噛み砕けたら一番いいけど、それに気を取られて助走つかずに結局全く読まないということもあるので、まず雑に読むというか見るくらいの活動をしたい。しかしちゃんと読むというのは別に意識しないとすべてを雑に見るだけになってしまいそうで、それも困る。

RegExp match indicesためした

 Chrome 90 で入っていた RegExp match indices (https://www.chromestatus.com/feature/6558676666023936) というのを見てへ〜と思ったのでちょろっとおためしした*1

f:id:hogashi:20210507151501p:plain
devtools でおためしした様子

 さっと見た感じでは、マッチしたものそれぞれについて、その登場範囲を配列で返してくれるというものらしい。上の 3つ目の例 ('123aaaabbbb'.match(/(aa)+(?<bee>b)/d))だとこういう感じになっていそう ↓

  • (aa)+(?<bee>b) (全体) にマッチするのは
    • aaaab で (最初を 0文字目として) 3〜7文字目
    • なので [3, 8]
  • (aa) にマッチするのは
    • aa (後半の方) で 5〜6文字目
    • なので [5, 7]
      • 繰り返しだと最後にマッチしたものになってこうなっている?
  • (?<bee>b) にマッチするのは
    • b (最初の1文字) で 7文字目
    • なので [7, 8]

 範囲の感じで終わり側の数字が 1つ多いのは、 GitHub の例を見る限り slice とかでそのまま使えて便利になっています、というように見える。

const re1 = /a+(?<Z>z)?/d;

// indices are relative to start of the input string:
const s1 = "xaaaz";
const m1 = re1.exec(s1);
m1.indices[0][0] === 1;
m1.indices[0][1] === 5;
s1.slice(...m1.indices[0]) === "aaaz";
https://github.com/tc39/proposal-regexp-match-indices#examples

 indices つけるの大変なので /d フラグを明に指定しないとやりません、という仕様らしい。まさにこれがほしいぜというときにつけてあげると小粒に便利そう。 (ところで Chrome Devtools を見ていると /dシンタックスハイライトがまだあたってなさそう……)

As producing this array is expensive, the `.indices` property is only present when the /d flag is passed.

https://www.chromestatus.com/feature/6558676666023936

 GitHub の方には、なんで /d なのかというところに、 d 使っていいのかみたいなことも書かれていた (https://github.com/tc39/proposal-regexp-match-indices#why-use-d-for-the-regexp-flag) 。 indices という単語から取ろうとしたけど、いまある i とかを避けつつ、他の正規表現エンジンも見て d がすでに意味バラバラなので、まあいいかな、みたいな感じになっていそう?

 あとそれに伴って他の正規表現エンジンでの様子をまとめていておもしろい (https://github.com/tc39/proposal-regexp-match-indices/blob/master/flags_comparison.md)。リンクもあるので各エンジンのドキュメントへのリンクまとめみたいになっている……。

www.chromestatus.com

github.com

*1:バージョン: 90.0.4430.93(Official Build) (x86_64)

pt-query-digestのJSON出力の型書いた

 型を公開する練習として、 pt-query-digest *1--output json したときに出力される JSON の型を書いてみた。 JSON.parse() したものにつける型を想定している。

github.com

 index.d.ts とかを書いて、 package.jsontypes として指定しておくと完成らしい。 npm に公開しなくても、とりあえず yarn add -D https://github.com/hogashi/types-pt-query-digest-output-json とかやるとインストールできるのでさっと作ってみるには気楽。

www.typescriptlang.org

 値としては数値なはずだけどプロパティによって number だったり string だったりすることがあってちょっと難しい。ちゃんとコード読んでるわけでもないので、意外と null になるじゃんみたいなものもあったりしそう。あと pt-query-digest の v3.0 時点でもまだ開発中ということなので急に変わったりもしそうではある。

json output was introduced in 2.2.1 and is still in development, so the data structure may change in future versions.

https://www.percona.com/doc/percona-toolkit/3.0/pt-query-digest.html#options&:~:text=json%20output%20was%20introduced%20in%202.2.1%20and%20is%20still%20in%20development

wgetはHSTSをサポートしている

 ホームディレクトリを見ていたら .wget-hsts というファイルがあったので見てみるとこういう感じだった。

$ cat .wget-hsts 
# HSTS 1.0 Known Hosts database for GNU Wget.
# Edit at your own risk.
# <hostname>	<port>	<incl. subdomains>	<created>	<max-age>
raw.githubusercontent.com	0	0	1599047229	31536000
gist.githubusercontent.com	0	0	1605963625	31536000
(後略)

 調べると wget は HSTS (HTTP Strict Transport Security) *1 をサポートしていて、このファイルはそのデータベースですとのことだった。なのでこれをちゃんと編集したら好きなホスト名についてとにかく https で接続できそう。素朴。

‘--hsts-file=file’

By default, Wget stores its HSTS database in ~/.wget-hsts. You can use ‘--hsts-file’ to override this. Wget will use the supplied file as the HSTS database.

(中略)

An HSTS entry line consists of several fields separated by one or more whitespace:

<hostname> SP [<port>] SP <include subdomains> SP <created> SP <max-age>

https://www.gnu.org/software/wget/manual/html_node/HTTPS-_0028SSL_002fTLS_0029-Options.html#:~:text=hsts-file

www.gnu.org

拡張機能「twitter画像原寸ボタン」 v3.1.3 公開

 拡張機能twitter画像原寸ボタン」 v3.1.3 公開しました。特に変更はなく依存パッケージのアップデートです。すでにインストールされていれば自動で更新されます。

chrome.google.com

 あと今回から Microsoft Edge アドオンにも公開しています。

twitter画像原寸ボタン - Microsoft Edge Addons

 互換性ある API しか使ってないから Port するだけなのでやってみませんか、みたいなメールを Microsoft Edge アドオンの担当の人?からなぜかもらったのでやったけど、本当に単にそれだけでできました。なるほど感。

docs.microsoft.com