Skip to content

Instantly share code, notes, and snippets.

@buivuanh
buivuanh / reader.go
Created September 19, 2019 07:46 — forked from jmackie/reader.go
Pass a single io.Reader to multiple goroutines
/*
Package fan is a little concurrent io experiment.
Example Use Case
----------------
You have a function that takes a single io.Reader as an argument. You would like
to pass that reader to several processing functions. You could just make the
function accept an io.ReadSeeker, invoke each function serially in a for loop,
seeking after each call. But that's not cool.
@buivuanh
buivuanh / _struct_to_map.go
Created July 30, 2020 05:29 — forked from bxcodec/_struct_to_map.go
Golang Struct To Map Example By JSON tag
/*
This function will help you to convert your object from struct to map[string]interface{} based on your JSON tag in your structs.
Example how to use posted in sample_test.go file.
*/
func structToMap(item interface{}) map[string]interface{} {
res := map[string]interface{}{}
if item == nil {
return res
}
@buivuanh
buivuanh / go_cpu_memory_profiling_benchmarks.sh
Created April 20, 2021 08:50 — forked from arsham/go_cpu_memory_profiling_benchmarks.sh
Go cpu and memory profiling benchmarks. #golang #benchmark
go test -run=. -bench=. -benchtime=5s -count 5 -benchmem -cpuprofile=cpu.out -memprofile=mem.out -trace=trace.out ./package | tee bench.txt
go tool pprof -http :8080 cpu.out
go tool pprof -http :8081 mem.out
go tool trace trace.out
go tool pprof $FILENAME.test cpu.out
# (pprof) list <func name>
# go get -u golang.org/x/perf/cmd/benchstat
benchstat bench.txt
Task 1: Create a project jumphost instance
Navigation menu > Compute engine > VM Instance
Task 2: Create a Kubernetes service cluster
gcloud config set compute/zone us-east1-b
gcloud container clusters create nucleus-webserver1
@buivuanh
buivuanh / install-pgtap.sh
Last active December 27, 2022 09:11
postgres 14 with pgtap extension docker image
#!/bin/bash
cd /pgtap
make
make install
make installcheck
psql -U postgres -c 'CREATE EXTENSION pgtap;'
@buivuanh
buivuanh / postgres-cheatsheet.md
Created March 3, 2023 06:54 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
must to have: M
nice to have: N
optional: null
Requirement tech stack:
- DB:
- Postgresql (M)
- MongoDB (N)
- Cache:
- Redis (M)