Skip to content

Instantly share code, notes, and snippets.

View pakkinlau's full-sized avatar
🚩
Focusing

Pak Kin LAU pakkinlau

🚩
Focusing
View GitHub Profile
@pakkinlau
pakkinlau / outgoing katex syntax transformer(for diff or patch files).py
Created December 23, 2025 05:44
outgoing katex syntax transformer(for diff or patch files).py — Make LLM-ish Markdown safe from ChatGPT to other place with other rendering format, such as Obsidian/Quarto (KaTeX/MathJax) etc.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
outgoing katex syntax transformer(for diff or patch files).py — Make LLM-ish Markdown safe from ChatGPT to other place with other rendering format, such as Obsidian/Quarto (KaTeX/MathJax) etc.
PURPOSE
Convert ChatGPT/Codex-style Markdown-with-math into a strict, portable
Markdown+LaTeX subset that renders cleanly. The script normalizes delimiters, fixes common LaTeX
pitfalls, and refuses to touch code/links/previous math.
@pakkinlau
pakkinlau / outgoing edits (.patch or .diff) validator.py
Last active December 23, 2025 16:23
outgoing edits (.patch or .diff) validator.py — Validate that a unified-diff patch (or zip bundle of patches) is machine-applicable.
#!/usr/bin/env python3
"""
outgoing edits (.patch or .diff) validator.py — Validate that a unified-diff patch (or zip bundle of patches) is machine-applicable.
Goals:
- Catch syntactic diff corruption that breaks `git apply` / `patch`:
* missing diff prefixes on blank hunk lines
* hunks without proper @@ headers
* missing ---/+++ headers for each diff --git section
* malformed hunk count (observed line counts don't match @@ header)
@pakkinlau
pakkinlau / use_this_to_parse_repo_snapshot.py
Last active December 30, 2025 05:47
Utilities for querying a repo snapshot bundle produced by the `agentic_repo_snapshot_curator.py` snapshot tool (or any tool that emits the same layout).
#!/usr/bin/env python3
"""
repo_snapshot_query.py
Utilities for querying a repo snapshot bundle produced by the
`agentic_repo_snapshot_curator.py` snapshot tool (or any tool that emits the same layout).
Snapshot layout (on disk)
-------------------------
@pakkinlau
pakkinlau / chatgpt_web_token_cost_estimator.py
Created December 6, 2025 08:39
With extracted LLM chat local log file, Estimate LLM web token usage and API cost from exported chat logs, with context-window simulation and optional reasoning-token approximation.
#!/usr/bin/env python
"""
Estimate token usage and cost from a ChatGPT web chat log (JSON export),
with:
- Configurable context window (to simulate truncation).
- Optional approximate reasoning token cost.
User-configurable parameters are at the top of this file.
"""
@pakkinlau
pakkinlau / codex_log_query.py
Last active November 24, 2025 18:43
Read the chat session log created by codex CLI
#!/usr/bin/env python3
"""
codex_log_query.py
Small utility module for querying Codex-style JSONL work logs.
Assumed log shape
-----------------
Each line in the JSONL file is a JSON object of the form::
@pakkinlau
pakkinlau / repo_snapshot_query.py
Last active November 24, 2025 18:47
Read the repository snapshot created by "package_to_snapshot_json.py" (https://gist.github.com/pakkinlau/342eede3f7f969b0f2d6b33ce6aa503a)
#!/usr/bin/env python3
"""
repo_snapshot_query.py
Utilities for querying a repo snapshot bundle produced by the
`agentspine` snapshot tool (or any tool that emits the same layout).
Snapshot layout (on disk)
-------------------------
@pakkinlau
pakkinlau / gpt2mermaid.py
Created October 22, 2025 23:54
Purpose: Normalize raw Mermaid flowchart text copied to the clipboard into a strict-parser-friendly form, then write the normalized result back to the clipboard. The transformation is fully deterministic and avoids intent inference; it focuses on syntax hygiene and common portability pitfalls observed across Mermaid renderers. Deterministic Tran…
#!/usr/bin/env python3
"""
gpt2mermaid.py — Deterministic Mermaid Normalizer (clipboard-in, clipboard-out)
Purpose
-------
Normalize raw Mermaid flowchart text copied to the clipboard into a
strict-parser-friendly form, then write the normalized result back to
the clipboard. The transformation is fully deterministic and avoids
intent inference; it focuses on syntax hygiene and common portability
@pakkinlau
pakkinlau / agentic_repo_snapshot_curator.py
Last active December 30, 2025 05:48
agentic_repo_snapshot_curator.py -- Purpose: create per-root JSON snapshot bundles (index + sharded JSONL) with stats, while letting agents tune which zones to include/skip without editing code. Core behavior - For each root in SRC_ROOTS (default "."): emit INDEX__<label>.json + DATA__<label>-NNN.jsonl (sharded). - Optionally include top-level r…
#!/usr/bin/env python3
"""
agentic_repo_snapshot_curator.py
Purpose: create per-root JSON snapshot bundles (index + sharded JSONL) with stats, while letting agents tune
which zones to include/skip without editing code.
Snapshot naming
- Snapshot id: repo=<slug>[__branch=<base> ]__ts=<UTC>__sig=<hash>[__tag=<tag>].
- Artifacts live in repo-snapshot-json/<snapshot_id>/; filenames are prefixed with the snapshot id.

🎯 Big goal

():

  • Context: <2–3 sentences describing why this goal matters, without solution hints.>
  • Constraints & assumptions:
  • Stakeholders / owners: <names/roles>

@pakkinlau
pakkinlau / install-and-run-facefusion.ps1
Created June 29, 2025 01:11
Create venv, install and run the facefusion tool in the one and single pass.
<#
.SYNOPSIS
One-shot installer & launcher for FaceFusion 3.3.0 (Windows 10/11).
.DESCRIPTION
– Creates a Conda env “facefusion” with Python 3.12
– Installs CUDA 12.9 runtime + cuDNN 9.10 (NVIDIA GPUs)
– Installs FFmpeg 7.0.2 globally *and* inside the env
– Clones FaceFusion from GitHub and installs with ONNXRuntime-GPU
– Force-downloads all model weights (resumable)