Hero Image
Articles

SingleFlight macOS 奇怪的安全扫码机制 Agentic Design Patterns 你不知道的 Claude Code:架构、治理与工程实践 你不知道的 Agent:原理、架构与工程实践 rtk: CLI proxy that reduces LLM token consumption by 60-90% on common dev commands. Single Rust binary, zero dependencies difftastic: a structural diff that understands syntax I Ditched Elasticsearch for Meilisearch. Here’s What Nobody Tells You. 策展島嶼的深度敘事: https://github.com/frank890417/taiwan-md Linux 中网络包的一生 Gitingest: Turn any Git repository into a prompt-friendly text ingest for LLMs. 7 More Common Mistakes in Architecture Diagrams Use Cases Superpowers: Superpowers is a complete software development workflow for your coding agents, built on top of a set of composable “skills” and some initial instructions that make sure your agent uses them. everything-claude-code: The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond. Agency Agents: A complete AI agency at your fingertips - From frontend wizards to Reddit community ninjas, from whimsy injectors to reality checkers. Each agent is a specialized expert with personality, processes, and proven deliverables. MiroFish: A Simple and Universal Swarm Intelligence Engine, Predicting Anything. Lightpanda Browser: the headless browser designed for AI and automation Anatomy of the .claude/ Folder Cocoa-Way: Native macOS Wayland Compositor written in Rust using Smithay. Experience seamless Linux app streaming on macOS without XQuartz. Pretext: Fast, accurate & comprehensive text measurement & layout Ghostmoon.app: A Swiss Army Knife for your macOS menu bar CodingFont: A game to help you pick a coding font The Git Commands I Run Before Reading Any Code Winhance: Application designed to optimize, customize and enhance your Windows experience. Native Instant Space Switching on MacOS FluidCAD: Write CAD models in JavaScript. See the result in real time. Awesome DESIGN.md: Copy a DESIGN.md into your project, tell your AI agent “build me a page that looks like this” and get pixel-perfect UI that actually matches. graphify: AI coding assistant skill (Claude Code, Codex, OpenCode, Cursor, Gemini CLI, GitHub Copilot CLI, OpenClaw, Factory Droid, Trae, Google Antigravity). Turn any folder of code, docs, papers, images, or videos into a queryable knowledge graph SingleFlight package analyzer import ( "context" "sync" "golang.org/x/sync/singleflight" "github.com/nathan/stock_bot/internal/storage" ) type AnalysisService struct { genai *GenAIClient d1Client *storage.D1Client stockCache map[string]*StockAnalysisResult mu sync.RWMutex sf singleflight.Group } func (s *AnalysisService) analyzeStock(ctx context.Context, code, name string) (*StockAnalysisResult, error) { // 1. 第一層防護:檢查記憶體快取 (L1 Cache) s.mu.RLock() if result, ok := s.stockCache[code]; ok { s.mu.RUnlock() return result, nil } s.mu.RUnlock() // 2. 第二層防護:Singleflight (請求合併) key := "stock:" + code v, err, _ := s.sf.Do(key, func() (interface{}, error) { // 3. 執行昂貴的邏輯 (DB + Gemini API) result, err := s.doAnalyzeStock(ctx, code, name) if err != nil { return nil, err } // 4. 寫入快取 (務必在 singleflight 內部完成,防止下一波瞬間擊穿) s.mu.Lock() s.stockCache[code] = result s.mu.Unlock() return result, nil }) if err != nil { return nil, err } return v.(*StockAnalysisResult), nil } func (s *AnalysisService) doAnalyzeStock(ctx context.Context, code, name string) (*StockAnalysisResult, error) { // 建立一個子 Context 用於內部的多個非同步任務 g, ctx := errgroup.WithContext(ctx) var dbData string var aiResult string // 任務 1:查資料庫 g.Go(func() error { // 隨時檢查 Context 是否已取消 select { case <-ctx.Done(): return ctx.Err() default: // 模擬資料庫查詢 dbData = "Historical Data" return nil } }) // 任務 2:呼叫 Gemini API g.Go(func() error { // 將 ctx 傳入 API 客戶端,讓它能跟隨整體的超時控制 res, err := s.genai.Generate(ctx, "Analyze this: "+code) if err != nil { return err } aiResult = res return nil }) // 等待所有任務完成或其中一個出錯 if err := g.Wait(); err != nil { return nil, err } return &StockAnalysisResult{Data: dbData, Analysis: aiResult}, nil } func (s *AnalysisService) analyzeStockWithMetrics(ctx context.Context, code string) (*StockAnalysisResult, error) { key := "stock:" + code v, err, shared := s.sf.Do(key, func() (interface{}, error) { return s.doAnalyzeStock(ctx, code, "Name") }) // 紀錄監控指標:分辨是「原始呼叫」還是「共享結果」 status := "original" if shared { status = "shared" } s.sfCounter.Add(ctx, 1, metric.WithAttributes( attribute.String("stock_code", code), attribute.String("type", status), )) if err != nil { return nil, err } return v.(*StockAnalysisResult), nil } macOS 奇怪的安全扫码机制 # 查看最近的 syspolicyd 扫描记录 log show --predicate 'subsystem == "com.apple.syspolicy.exec"' --last 5m --style compact | grep performScan System Settings → Privacy & Security → Full Disk Access,给 VS Code 完全磁盘访问权限有效

Hero Image
Mosdns-X

Mosdns-X 讓 Linux 系統的 DNS 更快更乾淨:部署 Mosdns-X 安裝 bash <(curl -sL https://raw.githubusercontent.com/lidebyte/bashshell/refs/heads/main/mosdns-x-manager.sh) 設定 sudo tee /etc/mosdns-x/config.yaml > /dev/null <<'EOF' # mosdns-x 并发查询(无分流)配置 log: level: info file: /var/log/mosdns-x/mosdns-x.log plugins: # 缓存插件 - tag: cache type: cache args: size: 1024 lazy_cache_ttl: 1800 # 并发上游:取最先返回的可用答案 - tag: forward_all type: fast_forward args: upstream: # 阿里 - addr: "udp://223.5.5.5" - addr: "tls://dns.alidns.com" # DNSPod / doh.pub - addr: "udp://119.29.29.29" - addr: "tls://dot.pub" # Cloudflare - addr: "udp://1.1.1.1" - addr: "tls://cloudflare-dns.com" # Google - addr: "udp://8.8.8.8" - addr: "tls://dns.google" # 主流水线:小缓存 → 并发优选 - tag: main type: sequence args: exec: - cache - forward_all # 监听(双栈 UDP/TCP 53) servers: - exec: main listeners: - addr: :53 protocol: udp - addr: :53 protocol: tcp EOF systemd sudo tee /etc/systemd/system/mosdns.service > /dev/null <<'EOF' [Unit] Description=Mosdns-X DNS Accelerator After=network.target [Service] Type=simple User=root Group=root ExecStart=/usr/local/bin/mosdns-x start --as-service -d /usr/local/bin -c /etc/mosdns-x/config.yaml Restart=always RestartSec=5 StandardOutput=journal StandardError=journal SyslogIdentifier=mosdns [Install] WantedBy=multi-user.target EOF sudo systemctl daemon-reload sudo systemctl enable --now mosdns # 备份系统 DNS sudo cp -n /etc/resolv.conf /etc/resolv.conf.mosdns-backup # 改为使用本地 Mosdns-X echo -e "nameserver 127.0.0.1\noptions edns0" | sudo tee /etc/resolv.conf # 若 53 端口被 systemd-resolved 占用,可禁用它 sudo systemctl disable --now systemd-resolved 2>/dev/null || true # 如果想顺便加锁(防止被 DHCP 修改),加上 chattr 一起执行: echo -e "nameserver 127.0.0.1\n" > /etc/resolv.conf && chattr +i /etc/resolv.conf # 查看进程状态 sudo systemctl status mosdns --no-pager # 测试解析速度(第二次命中缓存更快) dig +stats www.google.com dig +stats www.baidu.com # 查看实时日志 tail -f /var/log/mosdns-x/mosdns-x.log

Hero Image
Go 文章

學會 gin 參數校驗之 validator 函式庫,看這一篇就夠了 字串約束 excludesall:不包含參數中任意的 UNICODE 字元,例如 excludesall=ab excludesrune:不包含參數表示的 rune 字元,excludesrune=asong startswith:以參數子字串為前綴,例如 startswith=hi endswith:以參數子字串為後綴,例如 endswith=bye。 contains=:包含參數子字串,例如 contains=email containsany:包含參數中任意的 UNICODE 字元,例如 containsany=ab containsrune:包含參數表示的 rune 字元,例如 containsrune=asong excludes:不包含參數子字串,例如 excludes=email 範圍約束 範圍約束的欄位型別分為三種: 對於數值,我們可以約束其值 對於切片、陣列和 map,我們可以約束其長度 對於字串,我們可以約束其長度 常用 tag 介紹: ne:不等於參數值,例如 ne=5 gt:大於參數值,例如 gt=5 gte:大於等於參數值,例如 gte=50 lt:小於參數值,例如 lt=50 lte:小於等於參數值,例如 lte=50 oneof:只能是列舉出的值其中之一,這些值必須是數值或字串,以空格分隔;如果字串中有空格,請用單引號包起來,例如 oneof=male female。 eq:等於參數值,注意與 len 不同。對於字串,eq 約束字串本身的值,而 len 約束字串長度。例如 eq=10 len:等於參數值,例如 len=10 max:小於等於參數值,例如 max=10 min:大於等於參數值,例如 min=10 欄位約束 eqfield:定義欄位間相等約束,用於約束同一結構體中的欄位。例如:eqfield=Password eqcsfield:約束同一結構體中欄位等於另一個欄位(相對),確認密碼時可以使用,例如:eqcsfield=ConfirmPassword nefield:用來約束兩個欄位是否不同,確認兩種顏色是否一致時可以使用,例如:nefield=Color1 necsfield:約束兩個欄位是否不同(相對) 常用約束 unique:指定唯一性約束,不同型別處理不同: