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 / lazyvim_keymaps.md
Last active July 31, 2025 08:04
LazyVim: LSP Diagnostics and Renaming
]d
Go to the next diagnostic (e.g., an error or warning).
[d
Go to the previous diagnostic.
<leader>cr
Rename the symbol under the cursor (e.g., a function or variable).

Note: The default <leader> key in LazyVim is the Space key.

@wjkoh
wjkoh / delete_cookie.go
Created July 25, 2025 07:08
Go: How to Delete HTTP Cookie Correctly
@wjkoh
wjkoh / http_rate_limiter.go
Last active July 24, 2025 19:33
Go: HTTP Rate Limiter with LRU Cache
package main
import (
"log/slog"
"net"
"net/http"
"sync"
"github.com/golang/groupcache/lru"
"golang.org/x/time/rate"
@wjkoh
wjkoh / sqlite3_email_column.sql
Last active July 24, 2025 07:59
SQLite3: The Best Type for Emails is `TEXT UNIQUE COLLATE NOCASE`
-- Create a table named 'users' with an 'email' column.
-- The 'email' column is set to be UNIQUE and uses NOCASE collation,
-- which means case will be ignored for uniqueness checks.
CREATE TABLE users(email TEXT UNIQUE COLLATE NOCASE);
-- Insert an email address. The case will be preserved as entered.
INSERT INTO users(email) VALUES("[email protected]");
-- Retrieve the email from the 'users' table.
-- The email is stored exactly as entered, preserving its original case.
@wjkoh
wjkoh / go_merge_two_filesystems.go
Last active July 25, 2025 04:21
Go: Merge Two Filesystems Seamlessly (io/fs.FS)
type dualFS struct {
primary fs.FS
secondary fs.FS
}
var (
_ fs.FS = &dualFS{}
_ fs.ReadDirFS = &dualFS{}
_ fs.ReadFileFS = &dualFS{}
_ fs.StatFS = &dualFS{}
@wjkoh
wjkoh / neovim_go_template.md
Last active July 23, 2025 08:00
Effortless Go HTML Template Formatting in Neovim

Effortless Go HTML Template Formatting in Neovim

Here’s a straightforward guide to automatically format Go HTML templates (*.html files) in Neovim using the LazyVim distribution and Prettier.


1. Configure LazyVim for Go

First, ensure you have LazyVim installed. Then, you need to enable the built-in Go language extras.

@wjkoh
wjkoh / cryptographically_safe_uuid.go
Last active July 19, 2025 20:19
Go: Cryptographically Safe UUID
package main
import (
"crypto/rand"
"github.com/google/uuid"
)
// NewSafeUUID creates a cryptographically safe UUID.
//
@wjkoh
wjkoh / non_iso_8601_datetimes_in_json.go
Last active July 15, 2025 05:54
Go: Parsing Non-ISO 8601 Datetimes in JSON
type CustomDatetime time.Time
func (d *CusotmDatetime) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
t, err := time.Parse(time.RFC3339, s)
if err != nil {
t, err = time.ParseInLocation("2006-01-02T15:04:05", s, newNewYorkOnce())
@wjkoh
wjkoh / go_sqlite3_in_not_in.go
Last active July 14, 2025 11:18
Go: How to Query "IN" or "NOT IN" with SQLite3
package main
import (
"database/sql"
"fmt"
"strings"
"github.com/mattn/go-sqlite3"
)
@wjkoh
wjkoh / reserved_character.go
Last active July 12, 2025 07:04
Go: How to Escape Reserved Characters for SSML, WebVTT, and others.
package main
import (
"fmt"
"strings"
)
func main() {
// https://cloud.google.com/text-to-speech/docs/ssml#support-for-ssml-elements
// https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API/Web_Video_Text_Tracks_Format#cue_payload