Skip to content

Instantly share code, notes, and snippets.

View hallazzang's full-sized avatar

Hanjun Kim hallazzang

  • Seoul, Republic of Korea
  • 17:14 (UTC +09:00)
View GitHub Profile
@hallazzang
hallazzang / ticker.go
Created March 6, 2024 08:03
Similar to time.Ticker but fires immediately.
import (
"log"
"time"
)
func main() {
const d = 3 * time.Second
t := time.NewTimer(0)
defer t.Stop()
@hallazzang
hallazzang / ticker.go
Created December 10, 2023 19:11
Go ticker which runs immediately after creating
func NewTicker(d time.Duration) *time.Ticker {
ticker := time.NewTicker(d)
oc := ticker.C
nc := make(chan time.Time, 1)
go func() {
nc <- time.Now()
for t := range oc {
nc <- t
}
}()
@hallazzang
hallazzang / limits.md
Last active June 23, 2022 02:56
Cosmos SDK data type limits

sdk.Int

  • maxBitLen = 256
  • positiveMax = 115792089237316195423570985008687907853269984665640564039457584007913129639935(78 digits)
  • negativeMin = -115792089237316195423570985008687907853269984665640564039457584007913129639935(78 digits)

sdk.Dec

  • maxDecBitLen = 256 + 60 = 316
  • positiveMax = 133499189745056880149688856635597007162669032647290798121690100488888732861290.034376435130433535(78 + 18 digits)
@hallazzang
hallazzang / isproxyerror.go
Created January 11, 2021 06:42
Check if net error is a proxy connection error
import (
"errors"
"net"
)
func IsProxyError(err error) bool {
var operr *net.OpError
if errors.As(err, &operr) {
if operr.Op == "proxyconnect" {
return true
@hallazzang
hallazzang / install.sh
Created January 6, 2021 04:19
APT package offline installation
#!/bin/bash
if [ -z "$1" ]; then
echo "usage: ./install.sh <package name>"
exit 0
fi
echo "Installing $1..."
tar xf "$1.tar.gz"
@hallazzang
hallazzang / dump.go
Created January 5, 2021 08:25
Dump configuration struct with defaults
func DumpConfig(s interface{}) {
var dump func(interface{}, int)
dump = func(s interface{}, level int) {
e := reflect.ValueOf(s)
t := e.Type()
for i := 0; i < e.NumField(); i++ {
f := e.Field(i)
ft := t.Field(i)
if !ft.Anonymous {
fmt.Printf("%s%s:", strings.Repeat(" ", level), tagName(ft))
@hallazzang
hallazzang / pool.go
Created October 12, 2020 07:01
Fixed number worker pool implementation #1
type Pool struct {
n int
run func(context.Context)
ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup
}
func NewPool(n int, run func(context.Context)) *Pool {
ctx, cancel := context.WithCancel(context.Background())
@hallazzang
hallazzang / trie.go
Created September 7, 2019 14:24
Golang Trie Implementation
package main
import (
"fmt"
"unicode"
)
type TrieNode struct {
isEndOfWord bool
children [26]*TrieNode
@hallazzang
hallazzang / main.go
Created July 16, 2019 03:50
fourier transform playground
package main
import (
"fmt"
"math"
"math/cmplx"
)
func comp(v int) complex128 {
return complex(float64(v), 0)
@hallazzang
hallazzang / main.go
Last active April 28, 2024 06:58
[go] (Windows) ensure all child processes are killed when main program exits
package main
import (
"os/exec"
"unsafe"
"golang.org/x/sys/windows"
)
// We use this struct to retreive process handle(which is unexported)