Skip to content

Instantly share code, notes, and snippets.

View manhdaovan's full-sized avatar

Vanmanh Dao manhdaovan

View GitHub Profile
@manhdaovan
manhdaovan / gist:393c732a02e6ce2e2488099c22cc98f5
Created May 1, 2018 07:29
Extract csv content by column(s)
$awk -F "\"*,\"*" '{b=$2","$3","$4","$5","$6; print b}' /path/to/file.csv
@manhdaovan
manhdaovan / gist:354fb4b503dc62ca720fd9244bc3881c
Created September 13, 2018 01:42 — forked from shyouhei/gist:266178ffedab5767a5b69b972c76f88a
優秀なプログラマーになるためのコツ

優秀なプログラマーになるためのコツ

重要な順で

優秀なプログラマーになるには非常に長い時間がかかるという現実を直視すべし

優秀なプログラマーというのは寝ている間に異世界に召喚されて無双するのとはわけが違うんですよ。

自分の例で言うとプログラミングを始めた中学生の時から優秀なプログラマだったかって、そんなわけない。みんなヘッポコからスタートしているに決まってるわけです。以来二十余年、地道に生き恥を晒し続けてきた結果として、現在いちおう業界の末席を汚すところまで来ている。このプロセスから目を背けるべきではないです。優秀なプログラマーに生まれる人間なんかいない。優秀なプログラマーに「育つ」んだし、それには時間が必要。今日から無双したいと思うな。

@manhdaovan
manhdaovan / phone-number-transition.json
Created October 5, 2018 06:13 — forked from sondnm/phone-number-transition.json
Transition from 11 digits to 10 digits Vietnam phone number
{
"0162": "032",
"0163": "033",
"0164": "034",
"0165": "035",
"0166": "036",
"0167": "037",
"0168": "038",
"0169": "039",
"0120": "070",
@manhdaovan
manhdaovan / Makefile
Created January 9, 2019 05:19 — forked from isaacs/Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@manhdaovan
manhdaovan / main.go
Last active June 11, 2023 08:07
Simple simulation for gRPC ChainUnaryServer - interceptors
package main
import (
"fmt"
)
type handler func (string) string
type interceptor func(string, handler) string
func chainInterceptor(interceptors ...interceptor) interceptor {
interceptorsLen := len(interceptors)
@manhdaovan
manhdaovan / worker_pool.go
Last active June 24, 2019 07:37
Worker pool in Go
package workerpool
import (
"context"
)
/*
* Worker Pool for executing heavy tasks to avoid OOM error from OS
* Usage example:
* pool := workerpool.NewPool(3) // Number of workers should be adjusted appropriately to your services
@manhdaovan
manhdaovan / io_reader_writer_testing.go
Created June 11, 2019 14:12
mocking testing with io.Reader and io.Writer
// GetTextAndDisplay reads and display data to io
func GetTextAndDisplay(r io.Reader, w io.Writer) error {
buf := make([]byte, 10<<20) // 10MB
readBytes, err := r.Read(buf)
if err != nil {
return err
}
_, err = w.Write(buf[0:readBytes])
if err != nil {
@manhdaovan
manhdaovan / 01.[proto]echo.proto
Last active June 13, 2019 02:25
Example about GRPC cancellation: client calls context.cancel(), then the context in server side is canceled, too.
syntax = "proto3";
// EchoRequest is the request for echo.
message EchoRequest {
string message = 1;
}
// EchoResponse is the response for echo.
message EchoResponse {
string message = 1;
@manhdaovan
manhdaovan / async_client.go
Last active August 1, 2019 01:34
Simple test grpc.ClientConn
// asynchronous requesting with same client
func main() {
err := logger.RegisterLoggerFactory(func() (logger.Logger, error) {
return onelog.NewOneLogger(os.Stdout), nil
})
if err != nil {
fmt.Printf("error on register logger factory: %v", err)
return
}
lgr, _ := logger.NewLogger()
type sequenceIDGenerator struct {
idMgrClient IDManagerClient // client for getting IDPrefix
preGenerateIDs chan string // pre-generated ids
}
// Pre-generate id and send to channel.
// This method should be called once and only once when init generator
func (g *sequenceIDGenerator) preGenIDs() {
var idBase, id string
var seq uint64