[obsidian] vault backup: 2025-08-21 12:54:51[
All checks were successful
Build / build (push) Successful in 10m17s

This commit is contained in:
2025-08-21 12:54:51 +09:00
parent e94163fae8
commit bd79a9b4e6
4 changed files with 45 additions and 3 deletions

33
content/Dynamic Macro.md Normal file
View File

@@ -0,0 +1,33 @@
---
date: 2025-08-21 11:55
---
[[増井俊之]]が考案した、キーボード入力の履歴の中から繰り返し動作を自動で検出して再実行できるようにする仕組み
[Dynamic Macro - 増井俊之](https://scrapbox.io/masui/Dynamic_Macro)
実装が非常にシンプル。[[Atom]]用拡張機能の実装がわかりやすい
[atom-dynamic-macro/lib/atom-dynamic-macro.coffee at f050cac0d19eaac20ef2e5ff8092a9f5242cf481 · masui/atom-dynamic-macro · GitHub](https://github.com/masui/atom-dynamic-macro/blob/f050cac0d19eaac20ef2e5ff8092a9f5242cf481/lib/atom-dynamic-macro.coffee#L30C1-L47C8)
```coffeescript
#
# Detect repeated elements at the end of an array
#
# findRep [1,2,3] # => []
# findRep [1,2,3,3] # => [3]
# findRep [1,2,3,1,2,3] # => [1,2,3]
# findRep [1,2,3,3,1,2,3,3] # => [1,2,3,3]
# findRep [1,2,3], (x,y) -> x+1 == y # => [3]
#
findRep: (a,compare) ->
compare = compare ? (x,y) -> x == y
len = a.length
res = []
for i in [0...len/2]
for j in [0..i]
break unless compare(a[len-2-i-j], a[len-1-j])
res = a[len-j..len-1] if i == j-1
res
```
配列を二分探索して、一番長い要素を検出?