Skip to content

Instantly share code, notes, and snippets.

View kanguki's full-sized avatar
😘
love ya

Mo Nguyen kanguki

😘
love ya
View GitHub Profile
package main
import (
"github.com/go-mysql-org/go-mysql/canal"
"github.com/siddontang/go-log/log"
)
type MyEventHandler struct {
canal.DummyEventHandler
}
@kanguki
kanguki / keybindings.json
Last active September 12, 2022 13:20
vi .config/Code/User/
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "ctrl+c",
"command": "-extension.vim_ctrl+c",
"when": "editorTextFocus && vim.active && vim.overrideCtrlC && vim.use<C-c> && !inDebugRepl"
},
{
"key": "ctrl+f",
"command": "-extension.vim_ctrl+f",
@kanguki
kanguki / patterns.md
Last active September 12, 2022 13:00
Simplified microservices patterns note

Saga

Problem

In a long transaction where multiple sub transactions happen in different services, if one transaction fails, works of other services should be rolled back as well

How it works: there are 2 ways to implement saga:

  • Orchestration: (SYNCHRONOUS) A central service acting as an orchestrator calls other services in the due order and if there happens to be a failure, it'll compensate by calling compensating actions on other services it called before. This way, one step must be successful before continuing, so it waits for responses, meaning it's synchronous.
  • Choreography: (ASYNCHRONOUS) No central service. Services react to events and decide what to do/ what to compensate. e.g. when client puchasedgoods, if it failed, it sends FAIL event to MQ, maybe a notification service subscribing to this FAIL event will react on this and nothing else, else if it succeeds, it sends SUCCESS event to MQ, other services like
@kanguki
kanguki / reactNote.md
Last active September 3, 2022 03:33
react note

useReducer

type Reducer: (state: any, action?: any) => void
type Dispatch: (action?: any) => void
function useReducer (reducer: Reducer, initialState: any) [state: any, dispatch: Dispatch] {
  return [initialState, function(action?: any) {
    reducer(initialState, action)
  }]
}
@kanguki
kanguki / go_cpu_memory_profiling_benchmarks.sh
Created June 23, 2022 02:48 — 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
@kanguki
kanguki / setupUbuntu.sh
Last active September 14, 2022 01:34
so I switch to a new pc~
cat << "EOF"
_ _ _
| | | | (_)
___ ___| |_| |_ _ _ __ __ _ _ _ _ __
/ __|/ _ \ __| __| | '_ \ / _` | | | | | '_ \
\__ \ __/ |_| |_| | | | | (_| | | |_| | |_) |
|___/\___|\__|\__|_|_| |_|\__, | \__,_| .__/
__/ | | |
|___/ |_|
EOF
set -g default-terminal "screen-256color"
set -g history-limit 10000
set -g status-fg red
set -g status-bg black
set -g mouse on
# switch panes using Alt-arrow without prefix
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
call plug#begin("~/.vim/plugged")
" Theme
Plug 'dracula/vim'
" Language Client
Plug 'neoclide/coc.nvim', {'branch': 'release'}
let g:coc_global_extensions = ['coc-emmet', 'coc-css', 'coc-html', 'coc-json', 'coc-prettier', 'coc-tsserver', 'coc-eslint', 'coc-pyright', 'coc-go']
" TypeScript Highlighting
Plug 'leafgarland/typescript-vim'
Plug 'peitalin/vim-jsx-typescript'
@kanguki
kanguki / gitconfig
Last active September 3, 2022 10:31
~/.ssh/config and ~/.gitconfig to work with multiple github accounts in one machine. you're welcome~~~
[url "git@private1.github.com:someuser/private-repo-1"]
insteadOf = https://github.com/someuser/private-repo-1
[url "git@private2.github.com:someuser/private-repo-2"]
insteadOf = https://github.com/someuser/private-repo-2
[url "git@customName.github.com:keepThis"]
insteadOf = git@github.com:keepThis
@kanguki
kanguki / treeTraversal.go
Created April 23, 2022 10:26
tree traversal in go (recursively)
package main
import (
"fmt"
)
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode