Skip to content

Instantly share code, notes, and snippets.

View wjkoh's full-sized avatar
🎯
Focusing

Woojong Koh wjkoh

🎯
Focusing
View GitHub Profile
@wjkoh
wjkoh / truncated_exponential_backoff.go
Last active July 3, 2025 07:24
Go: Retries with Truncated Exponential Backoff and Jitter
package main
import (
"context"
"errors"
"math"
"math/rand/v2"
"time"
)
@wjkoh
wjkoh / Taskfile.yml
Last active June 30, 2025 05:35
Go: How to Install `playwright-go` Dependencies using Taskfile
# https://taskfile.dev
version: '3'
tasks:
playwright:
vars:
PWGO_VER:
sh: go list -m -f "{{ "{{.Version}}" }}" github.com/playwright-community/playwright-go
cmds:
@wjkoh
wjkoh / treeblood-reddit.md
Last active June 30, 2025 03:58
TreeBlood: Pure Go LaTeX to MathML Renderer for LLM Output

TreeBlood: Pure Go LaTeX to MathML Renderer for LLM Output

Hi everyone,

I'm excited to announce TreeBlood, the world's first pure-Go LaTeX to MathML renderer! If you're working with LLMs like ChatGPT or Gemini and need to display mathematical formulas generated in their responses, TreeBlood offers a fast, server-side solution.

Authored by Wyatt Sheffield, TreeBlood efficiently converts any LaTeX expressions into web-browser-ready MathML. For example, if you have an equation like $\int_0^1 x^{-x} dx = \sum_{n=1}^\infty n^{-n}$, TreeBlood will transform it into the following:

@wjkoh
wjkoh / cloud_run_request_count.md
Last active June 21, 2025 07:34
Google Cloud Run: Retrieve the total number of requests, not a rate, from Metrics Explorer

Check out this comment by Sanjeev Kumar or the following copy.

I was struggling as well to get the actual counts. In the current UI , there might be some issue with selecting resources (I was not able to do so). Hence I used PromQL language.

  1. Go to the metric explorer in monitoring.
  2. select promQL on right hand side.
  3. Enter this code: sum by (response_code_class)(run_googleapis_com:request_count{monitored_resource="cloud_run_revision"})

Give the dashboard some time to refresh and collect the data , Later you can see the request cumulatively adding up based on you selected filter on time.

@wjkoh
wjkoh / proxy_client.go
Last active June 23, 2025 04:52
Go: How to use a proxy server with `net/http` (ft. Bright Data)
// Please refer to the following code if you encounter "tls: failed to verify certificate: x509: “*.example.com” certificate is not standards compliant"
package main
import (
"crypto/tls"
"crypto/x509"
"errors"
"net"
"net/http"
"net/url"
@wjkoh
wjkoh / ffprobe_get_format_and_duration.sh
Last active June 17, 2025 07:59
ffprobe: How to get the audio and video format and duration from a file
#!/usr/bin/env bash
# Use https://jqlang.org/
ffprobe -i test.ogg -show_format -output_format json | jq
# Use https://fx.wtf/
ffprobe -i test.ogg -show_format -output_format json | fx
@wjkoh
wjkoh / duration_to_min_sec_ms.go
Last active June 5, 2025 14:45
Go: Split a time.Duration into minute, second, and millisecond parts
package main
import (
"fmt"
"time"
)
func main() {
const d = 123456789 * time.Microsecond
fmt.Println(d.String())
@wjkoh
wjkoh / sqlite_rwc_ro.go
Last active May 31, 2025 08:04
Go: Open two SQLite connections, one for read-write-create and the other for read only
// https://github.com/mattn/go-sqlite3/issues/1022#issuecomment-1067353980
func newSqlDb(name string) (*sql.DB, *sql.DB, error) {
u := url.URL{
Scheme: "file",
Opaque: name,
}
q := make(url.Values)
q.Set("mode", "rwc")
q.Set("_foreign_keys", "true")
q.Set("_journal_mode", "WAL")
@wjkoh
wjkoh / graceful_http_server_shutdown.go
Last active May 30, 2025 08:00
Go: Graceful HTTP Server Shutdown
package main
import (
"context"
"log"
"log/slog"
"net"
"net/http"
"os"
"os/signal"
@wjkoh
wjkoh / hl-l2400d.md
Last active May 25, 2025 16:51
How to Use the Brother HL-L2400D printer on macOS

First, download the printer driver from https://support.brother.com/g/b/downloadtop.aspx?c=us&lang=en&prod=hll2300d_us_eu_as. Even though the webpage is for the HL-L2300D, the printer driver contains multiple model drivers.

Second, after installation, add your HL-L2400D but choose "Brother HL-L2395DW series CUPS" as the driver.

Now you can print anything, single-sided or double-sided, without a problem. I tried the HL-L2300D driver and had a problem with double-sided printing.