ときどきの雑記帖 RE* (新南口)
春の魔術
世界史アップデート
以前、読売新聞に掲載の「日本史アップデート」 という週一連載のことを書いたことがありますが、 オリンピック等々があったせいか しばらく見ないと思っていたところに 今週久しぶりに見たら 「世界史アップデート」 になっててちょっとびっくり。
今年の頭からそうなっていたみたいだけど記憶にないなあ…
本日1月18日の読売新聞夕刊に「世界史アップデート 史上初の世界一周航路」という記事がありました。
— モカ (@moca_u) January 18, 2022
マゼランたちによる西回りアジア航路開拓のお話ですが、5隻で出航 帰還は1隻など知らなかったことばかりで興味深く読みました。
いや、このマゼラン云々は見た覚えがあるな?🤔
関内
しばらく行ってないけど様変わりしている模様。
- 「関内駅北口広場」3月30日オープン。屋根や歩行者空間整備 - Impress Watch
- 横浜市、JR関内駅北口改札前に屋根付きの歩行者広場。「関内駅北口広場」3月30日供用開始 - トラベル Watch
awk
awk関連の話題をいくつか。
goawk
negative field indexes
これはgawkを使っていてもあったらなあと思う機能だ😄
Add support for negative field indexes by benhoyt · Pull Request #106 · benhoyt/goawk
This change adds support for negative field indexes to return a field counting from the right, so for example, $-1 is the last field, $-2 is the second-to-last, and so on. If n is greater than NF in the expression $-n, GoAWK returns empty string (and does nothing when setting the field).
Usage example:
$ echo a b c d e | goawk '{ print $-1, $-2, $-10, $1 }' e d a
Getting or setting a negative field number is currently an error in original-awk, gawk, and mawk, so as far as I’m concerned this is a backwards-compatible change – no current AWKs support it (and it’s not defined by POSIX), so this is a GoAWK extension.
まあメンテナーのArnoldの性格を考えると入らんだろうなあ。 そういえば負の数の添え字云々で思い出したがこんなツイートが過去にあった。
配列を逆順にしたいとき、
— しゅもん (@shumon_84) March 22, 2019
array[array.length - i - 1]
みたいにすると思うんですけど、この-1が気に入らないので色々考えてたら、天才なので
array[array.length + ~i]
を発明した
CSV support
通常のフィールド分割では対応が面倒だし、あらかじめこういうものがあればありがたい。
CSV support by benhoyt · Pull Request #107 · benhoyt/goawk
mawk
久しぶりに動きが。 と思ったが関係ない人たちの(間隔のあいた)やり取りだった。
printf in mawk 1.9.9.6 is much slower than mawk 1.3.3 · Issue #5 · mikebrennan000/mawk-2
始まりは
mawk-1.9.9.6, Windows 10 64bit 1903, MinGW64 GCC 9.3.0
mawk "BEGIN{while(i++<100000)printf i}" > a.txt
This command takes 37.76 seconds. While mawk 1.3.3 takes only 0.06 seconds.
なんだけど、printf i
(print iではないのに注意)で色々と。
one true awk
one true awkからも、ひとつ。
Fix assignment operand handling to preserve ARGV by mpinjr · Pull Request #143 · onetrueawk/awk
awkのコマンドライン引数に=
を含んだものを渡すと
それはファイル名ではなく
変数に対する代入と解釈されるという機能があるんだけど、
それに関して「副作用」があったという話。
$ echo | ./master 'BEGIN { print ARGV[1] } { print ARGV[1] }' name=value
name=value
name
$ echo | ./a.out 'BEGIN { print ARGV[1] } { print ARGV[1] }' name=value
name=value
name=value
History: setclvar had been modifying its string argument without ill-effect from the beginning (7th Edition UNIX, 1979) [1], when, in 1989, SVR4 switched the source of the argument from argv to ARGV [2]. The former cannot be accessed by the application, the latter can. Thus, a private implementation detail unintentionally became a public defect.
[1] https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/awk/lib.c [2] https://github.com/danfuzz/one-true-awk/blob/master/versions/1989-10-11/lib.c
洋書
最近邦訳されたO'REILLY社の「ソフトウェアアーキテクチャの基礎」の著者達が執筆した「Software Architecture: Modern Trade-off Analyses for Distributed Architectures」が良さげ。
— iselegant | Masaya ARAI (@msy78) March 12, 2022
分散システムアーキテクチャのトレードオフに特化して書かれてる。
高いけど・・買うか。https://t.co/RbEXO09f2N
と言うのを見かけたのでいくらくらいのものだろうかと調べると
今日(2022年3月20日)の時点では6881JPY。まあ安くはないですね。 そして例によって元のUSDでの値段はjpではわからないのでこっちはcomで
List Price: $69.99 Details
Save: Save: $27.00 (39%)
一瞬実売価格で比較してびっくりしたけど、List Priceから考えると まあ…という感じですやね。
ところでcomの方で関連商品に出てきたものにも面白そうなものがあった。
Publisher : Addison-Wesley Professional; 1st edition (November 15, 2021)
Language : English
Paperback : 406 pages
ISBN-10 : 0137464401
ISBN-13 : 978-0137464401
Item Weight : 1.5 pounds
Dimensions : 7 x 0.92 x 9.13 inches
Publisher : Addison-Wesley Professional; 1st edition (November 4, 2021)
Language : English
Paperback : 416 pages
ISBN-10 : 013691571X
ISBN-13 : 978-0136915713
Item Weight : 1.5 pounds
Dimensions : 6.95 x 1.15 x 9.05 inches
Publisher : Will Larson (January 31, 2021)
Language : English
Paperback : 371 pages
ISBN-10 : 1736417916
ISBN-13 : 978-1736417911
Item Weight : 1.19 pounds
Dimensions : 6 x 0.84 x 9 inches
最初の二つはなんか見たような表紙とどこかで聞いたようなタイトルだなあと思ったら、 なんかシリーズものになってたらしいすね。あれ >Robert C. Martin Series
Robert C. Martin (全14巻) Kindle版
三つめは、少し前(今年の初めくらい?)に
英語でスカウトのメールをもらったけどStaff Engineer
という肩書を勘違いして…というツイートを見かけたことが
あったので気になった。
Toward a better list iterator for the Linux kernel
Linuxカーネルの連結リストを舐める操作を安全に行うための新しいマクロについて。連結リストのノードの型は値の型によって変わるため、Linuxではlist_head型の値を持つ構造体を連結リストのノードと見做す。未知の型が対象になるためリストの操作はマクロで実装されるhttps://t.co/sK4YH9XRWB
— Fadis (@fadis_) March 14, 2022
ツイートについているリンクだと
3/24まではSubscription required
だけど
- Toward a better list iterator for the Linux kernel | Hacker News
- Toward a better list iterator for the kernel [LWN.net]
これと同じなんだろうか(番号が同じ)?
The following subscription-only content has been made available to you by an LWN subscriber. Thousands of subscribers depend on LWN for the best news from the Linux and free software communities. If you enjoy this article, please consider subscribing to LWN. Thank you for visiting LWN.net!
はい。
で、文章は除いてマクロのみを見ていくと
struct inode *inode;
/* ... */
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
/* Process each inode here */
}
/* Should not use the iterator here */
#define list_for_each_entry(pos, head, member) \
for (typeof(pos) __iter = list_first_entry(head, typeof(*pos), member); \
!list_entry_is_head(__iter, head, member) && (((pos)=__iter),1); \
__iter = list_next_entry(__iter, member))
#define list_for_each_entry(pos, head, member) \
for (typeof(pos) pos = list_first_entry(head, typeof(*pos), member); \
!list_entry_is_head(pos, head, member); \
pos = list_next_entry(pos, member))
こうする意味がすぐには理解できなかったのだけど
Now the loop-scope iteration variable is declared with the same name as the outer variable, shadowing it. With this version, the iterator variable declared in the outer scope will never be used within the loop at all.
ということなのね。なるほど。
変数のスコープを限定するのとは別に 後始末(?)をきちんとしておこうという流れもあって
James Bottomley suggested a different approach:
#define list_for_each_entry(pos, head, member) \
for (pos = list_first_entry(head, typeof(*pos), member); \
!list_entry_is_head(pos, head, member) && ((pos = NULL) == NULL; \
pos = list_next_entry(pos, member))
一瞬((pos = NULL) == NULL
で🤔となったけど、
ループの判定部にあるので==NULL
をつけることで
ループが継続するようになっていると(もちろん&&
の前の条件による)。
Yet another approach was proposed by Xiaomeng Tong:
#define list_for_each_entry_inside(pos, type, head, member) \
for (type * pos = list_first_entry(head, type, member); \
!list_entry_is_head(pos, head, member); \
pos = list_next_entry(pos, member))
これはマクロに型を与えることでtypeofを使わなくてもできるように…
ということでよいのかな? auto
(を使ったtype infer)があればというのはこの辺を指してのことかな。
で結局のところ
A solution at last?
After having rejected various solutions, Torvalds went off to think about what a good solution might look like. a solution that implements this idea. It starts with a new declaration macro:
#define list_traversal_head(type,name,target_member) \
union { struct list_head name; type *name##_traversal_type; }
#define list_traverse(pos, head, member) \
for (typeof(*head##_traversal_type) pos = list_first_entry(head, typeof(*pos), member);\
!list_entry_is_head(pos, head, member); \
pos = list_next_entry(pos, member))
の二つになったということでよい?
なんとなく大昔の、テンプレートが導入される前のC++を 思い出さないでもない😄
Hugo メモ
0.94の時代はあっという間に過ぎて0.95に。
Release v0.95.0 · gohugoio/hugo
GA4
GIGZINEも記事にしていた Googleアナリティクスが2023年に旧バージョンを廃止すると発表、「GA4」への移行方法はこんな感じ - GIGAZINE けど、 数日前からGoogle Analyticsの画面を開くと 「はよ移行せい」と言った感じのメッセージが出てくるようになったので 面倒くせーと思いつつちょっと調べた。
themes/ananke/layouts/_defaults/baseof.htmlを見ると
<!DOCTYPE html>
<html lang="{{ $.Site.LanguageCode | default "en" }}">
<head>
...省略...
{{/* NOTE: These Hugo Internal Templates can be found starting at https://github.com/spf13/hugo/blob/master/tpl/tplimpl/template_embedded.go#L158 */}}
{{- template "_internal/opengraph.html" . -}}
{{- template "_internal/schema.html" . -}}
{{- template "_internal/twitter_cards.html" . -}}
{{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") }}
{{ template "_internal/google_analytics_async.html" . }}
{{ end }}
{{/* add */}}
{{- partial "analytics" . -}}
</head>
hugo/google_analytics_async.html at master · gohugoio/hugo
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
{{ end }}
となっていて、google_analytics_async.htmlはGA4には対応していないらしい。
_internal
とあるように実行バイナリが抱えているものなので
(Hugoそのものを自前でビルドしない限り)ユーザーが書き換えることはできない
(まあその外側(たとえばこのbaseof.html)で自前のものに置き換えられるけど)。
ところでこの、GA4に対応していないというのはずいぶん前からissueが 立てられているのだけど、放置状態?
Hugo のテーマに Global Site Tag (gtag.js) の設定を追加した - m1yam0t0.com
テンプレートで gtag.js が使用されていない件については、issue にもなっており、milestone にも追加されている。 Update the internal GA template - issue #4479 - gohugoio/hugo
で、そのissue #4479を見ると、バージョンが上がるたびに
added this to the v0.xx.0 mileston
という記述が追加され続けて
現在(2022年3月20日)では
Update the internal GA template · Issue #4479 · gohugoio/hugo
bep added this to the v0.96.0 mileston
Update Google Analytics internal template to new style(gtag.js) · Issue #4327 · gohugoio/hugo
bep added this to the v0.96.0 milestone
のような状態。
検索するといくつか対応した事例も見つかるけど さてどうしよう…
- Hugoサイトに最新版のGoogle Analyticsのタグを埋め込む – Helve Tech Blog
- Googleアナリティクスのタグをanalytics.jsからgtag.jsに更新 - Mehr Sonntag
- How do I install google tag manager correctly? - support - HUGO
- Hugoで未だ対応していないgtag.jsを利用して Googleアナリティクスする - Qiita