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 / fx_sort_by.sh
Created October 29, 2025 08:46
fx: How to Sort JSON array in-place
#!/usr/bin/env bash
fx ./data/podcasts.json '{...x, podcasts: sortBy(x => x.title)(x.podcasts)}' save
@wjkoh
wjkoh / unix_time.go
Created October 18, 2025 07:21
Go: UnixTime
type UnixTime struct{ time.Time }
func (t *UnixTime) UnmarshalJSON(b []byte) error {
if string(b) == "null" {
t.Time = time.Time{}
return nil
}
var timestamp float64
if err := json.Unmarshal(b, &timestamp); err != nil {
return err
@wjkoh
wjkoh / job_manager.go
Created October 10, 2025 17:24
Go: Background Job Manager
package main
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"log/slog"
"sync"
@wjkoh
wjkoh / sqlite_lru_cache.go
Last active October 2, 2025 06:07
Go: SQLite-based, On-disk LRU Cache
package fred
import (
"context"
"database/sql"
"errors"
"log/slog"
"time"
)
@wjkoh
wjkoh / levenshtein.go
Last active September 23, 2025 17:22
Go: Levenshtein Distance
package main
import "golang.org/x/text/unicode/norm"
type levenshteinDistancer struct {
deletionCost int
insertionCost int
substitutionCost int
}
@wjkoh
wjkoh / audio_cutter.go
Last active September 22, 2025 18:57
Go: How to Cut or Chunk an Audio File using FFmpeg
package main
import (
"context"
"encoding/json"
"fmt"
"io"
"log/slog"
"os/exec"
"strings"
@wjkoh
wjkoh / esc_to_switch_to_english.json
Last active September 2, 2025 16:59
MacOS: Press Escape to switch to English (sends Escape multiple times)
{
"description": "Press Escape to switch to English (sends Escape multiple times)",
"manipulators": [
{
"conditions": [
{
"input_sources": [{ "language": "^en$" }],
"type": "input_source_unless"
}
],
@wjkoh
wjkoh / sitemap.go
Created August 31, 2025 18:36
Go: How to Generate sitemap.xml
package main
import (
"encoding/xml"
"io"
)
const defaultXmlNs = "http://www.sitemaps.org/schemas/sitemap/0.9"
type Url struct {
@wjkoh
wjkoh / htmx_response_error.html
Last active August 21, 2025 07:52
HTMX + Alpine.js: Displaying HTTP Errors Using the HTML <dialog> Element
<!-- Copy and paste the following to every html file. -->
<div x-data="{ open: false, title: '', content: '' }"
x-on:htmx:response-error.window="title = $event.detail.xhr.statusText; content = $event.detail.xhr.responseText; open = true">
<dialog x-bind:open="open">
<article>
<h2>Error: <span x-text="title"></span></h2>
<p><code x-text="content"></code></p>
<footer>
<button x-on:click="open = false">OK</button>
</footer>
@wjkoh
wjkoh / camelcase.go
Last active August 20, 2025 07:40
Go: camelCase
package main
import (
"fmt"
"strings"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)