From eeba67de1cc4fc766aa9860a2e404071584364dd Mon Sep 17 00:00:00 2001 From: sterni Date: Mon, 6 Jan 2025 17:03:02 +0100 Subject: [PATCH] =?UTF-8?q?refactor(sterni/bl=C3=ABrg):=20avoid=20calling?= =?UTF-8?q?=20mhdr=20once=20per=20header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can actually get all the headers we are interested in just one call of mhdr(1) since it can query multiple headers in multiple messages in just one call. With BQNs reshape / two dimensional array facilities it is easy to group the lines of headers by their originating message and append the original path to the result array. We still use a separate mhdr(1) call for the Date header since we rely on the -D option for parsing the header. Change-Id: Iaaf8f21fa22ab3e32e6900df4ae164e72c722cd3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/13016 Reviewed-by: sterni Tested-by: BuildkiteCI Autosubmit: sterni --- users/sterni/blërg/blërg.bqn | 25 ++++++++++++++----------- users/sterni/exercises/aoc/lib.bqn | 2 ++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/users/sterni/blërg/blërg.bqn b/users/sterni/blërg/blërg.bqn index de5986acd..ce32e9939 100755 --- a/users/sterni/blërg/blërg.bqn +++ b/users/sterni/blërg/blërg.bqn @@ -17,16 +17,15 @@ MkDirP ← •file.CreateDir⍟(¬•file.Exists) AsciiDown ← ('A'-'a')⊸(⊢-×⟜('A'⊸≤∧≤⟜'Z')) -nl ← @+10 +_join ← {(∾⟜(𝕗⊸∾))´𝕩;𝕨∾𝕗∾𝕩} +nl ← @+10 SplitChar ← ((=(¯1˙⍟⊣)¨+`∘=)⊔⊢) Lines ← nl⊸SplitChar ReadPosInt ← {(𝕨⊸×+⊣)´∘⌽-⟜'0'𝕩} # ty leah2 ReadPosDec ← 10⊸ReadPosInt -ApplyMany ← {fs 𝕊 arg: {𝕏 arg}¨ fs} - Chomp ← {⟨nl⟩≡¯1↑𝕩? ¯1↓𝕩; 𝕩} Run ← { @@ -43,16 +42,20 @@ LR ← Lines∘R # (Apple) Mail Notes Backend # TODO(sterni): avoid argv limit by chunking -Hdr ← {LR "mhdr"‿"-dh"‿𝕨∾𝕩} -Date ← {ReadPosDec¨ LR "mhdr"‿"-Dh"‿"Date"∾𝕩} +Hdrs ← {LR "mhdr"‿"-dh"‿(':' _join 𝕨)∾𝕩} +Dates ← {ReadPosDec¨ LR "mhdr"‿"-Dh"‿"Date"∾𝕩} +headerNames ← "X-Uniform-Type-Identifier"‿"X-Universally-Unique-Identifier"‿"Subject" MailNotesBackend ← {𝕊 mailDir: - Filter ← {𝕩 ("com.apple.mail-note"⊸≡¨/⊣) "X-Uniform-Type-Identifier" Hdr 𝕩} - Id ← AsciiDown "X-Universally-Unique-Identifier"⊸Hdr - Title ← "Subject"⊸Hdr - MkRenderer ← {𝕊 p: {R "execline-cd"‿𝕩‿"mshow"‿"-x"‿p ⋄ R "mn2html"‿p}} - # TODO(sterni): entries could become namespaces - Entries ⇐ {𝕊: ⍉>⟨Id,Title,Date,MkRenderer¨⟩⊸ApplyMany Filter LR "mlist"‿mailDir} + Entries ⇐ {𝕊: + ms ← LR "mlist"‿mailDir + th ← ⍉⟨≠ms,≠headerNames⟩⥊headerNames Hdrs ms + dh ← Dates ms + ah ← (("com.apple.mail-note"⊸≡⊑)˘/⊢) ⍉th∾dh≍ms + {𝕊 ·‿id‿title‿date‿path: + ⟨AsciiDown id, title, date, {"execline-cd"‿𝕩‿"mshow"‿"-x"‿path ⋄ R "mn2html"‿path}⟩ + }˘ ah + } } # Rendering diff --git a/users/sterni/exercises/aoc/lib.bqn b/users/sterni/exercises/aoc/lib.bqn index 5c02358b5..ad3fdd7e5 100644 --- a/users/sterni/exercises/aoc/lib.bqn +++ b/users/sterni/exercises/aoc/lib.bqn @@ -19,3 +19,5 @@ Xor ⇐ (¬⊸∧∨∧⟜¬) # To get all Diagonals (⊢∾○Diagonals⌽) Diagonals ⇐ {(0‿0⊸⍉ ↓⟜𝕩)¨ (↕≠𝕩)} + +ApplyMany ← {fs 𝕊 arg: {𝕏 arg}¨ fs}