Skip to content

Instantly share code, notes, and snippets.

@whitekid
whitekid / whitekid.plugin.zsh
Created March 30, 2022 14:24
oh-my-zsh custom plugin
# place this file at ~/.oh-my-zsh/custom/plugins/whitekid
alias bumpup="git add . && git commit --amend -C HEAD && git push -f"
alias rebase-build="git remote update && git rebase && make"
TARGET=bin/<your-target>
GO_PKG=<your-module-name>
SRC=$(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "*_test.go")
GO?=go
BUILD_FLAGS?=-v
.PHONY: clean test dep tidy
all: build
@whitekid
whitekid / chan1.go
Last active November 19, 2019 07:33
chan broadcast
package main
import (
"fmt"
"sync"
)
func chanEvent1() {
ch := make(chan struct{})
var wg sync.WaitGroup
package main
import (
"bufio"
"bytes"
"fmt"
"os"
"regexp"
"strings"
)
//
// yaml multiple document를 parsing하는데, 각 document의 타입을 미리 확정할 수 없을 때
// 각각의 document를 scanner로 분리하고 try & error로 각 document를 decoding하는 예제..
//
package main
import (
"bufio"
"bytes"
"errors"
@whitekid
whitekid / stop_multiple_goroutine.go
Last active October 17, 2018 06:25
Stop multiple goroutine
// play at https://play.golang.org/p/lHRnRJHPheY
package main
import (
"context"
"errors"
"log"
"sync"
"time"
)
@whitekid
whitekid / json_decode_failback.go
Created October 4, 2018 13:38
golang json failback
package main
import (
"encoding/json"
"strings"
)
type Data struct {
Build struct {
Name string `json:"name"`
@whitekid
whitekid / depreciated.py
Last active November 17, 2017 07:11
depreciated decorator
import inspect
import warnings
from functools import wraps
def decorator(func_or_class):
warnings.filterwarnings('default', category=DeprecationWarning)
is_class = inspect.isclass(func_or_class)
if is_class:
type_name = 'class'
else:
@whitekid
whitekid / go-proxy.go
Last active August 24, 2018 01:49
golang network proxy
// netcat go version
// Usage:
// go-nc hostname port
//
// - connect to hostname:port
// - read stdin and send to socket
// - read socket and write to stdout
package main
import (
@whitekid
whitekid / inject.py
Created October 27, 2017 17:45
inject method into class
from functools import wraps
def inject(klass):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
setattr(klass, func.__name__, func)