Skip to content

Instantly share code, notes, and snippets.

View koonix's full-sized avatar
🦆
honk

koonix

🦆
honk
View GitHub Profile
@koonix
koonix / ringbuf.go
Created December 25, 2024 06:23
Ring buffer.
package ringbuf
type RingBuf[T any] struct {
Buf []T
head int
tail int
}
func New[T any](size int) *RingBuf[T] {
return &RingBuf[T]{
@koonix
koonix / muldiv.go
Last active January 7, 2025 23:44
Go 64-bit multiplication and division without overflow.
import "math/bits"
func mulDiv(a, b, c int64) int64 {
hi, lo := bits.Mul64(uint64(a), uint64(b))
quo, _ := bits.Div64(hi, lo, uint64(c))
return int64(quo)
}
@koonix
koonix / aria2ctrlfile.go
Last active December 29, 2024 22:46
aria2's control file format implementation in Go.
// Package aria2ctrlfile implements [aria2]'s [control file format] (version 1).
// See https://github.com/aria2/aria2/blob/release-1.37.0/src/DefaultBtProgressInfoFile.cc
// for implementation details.
//
// [aria2]: https://github.com/aria2/aria2
// [control file format]: https://aria2.github.io/manual/en/html/technical-notes.html#control-file-aria2-format
package aria2ctrlfile
import (
"encoding/binary"
@koonix
koonix / openssl-ed25519-certs.md
Created February 18, 2025 14:02
Creating Self-Signed ED25519 CA and Certificates

Creating Self-Signed ED25519 CA and Certificates

Important

the Common Name (CN) of the servers should be different from that of the CA. Otherwise, things won't work on servers that use OpenSSL.

CA