Less Is More: Directed Acyclic Graph

A directed acyclic graph or DAG is a directed graph with no directed cycles. An arbitrary directed graph may also be transformed into a DAG, called its condensation, by contracting each of its strongly connected components into a single super vertex. Go’s import declaration declares a dependency relation between the importing and imported package. It is illegal for a package to import itself, directly or indirectly, or to directly import a package without referring to any of its exported identifiers. ...

May 12, 2022

Go vs Python

Slices Go slice and Python slice have very similar syntax, but Python slice is a shallow copy of part of the original list, while Go slice is just a new range within the same underlying array of the original slice. Let’s try: a = [1, 2, 3] b = a[:2] b[0] = 9 print(a) print(b) # output: # [1, 2, 3] # [9, 2] See a[0] remains the same. package main import ( "fmt" ) func main() { a := []int{1, 2, 3} b := a[:2] b[0] = 9 fmt.Println(a) fmt.Println(b) # output: # [9 2 3] # [9 2] } See a[0] changes because slice a and b shares the same underlying array. ...

September 27, 2019

Learning Frontend

Vanilla JavaScript React Emotion

February 15, 2019

JavaScript Surprises to a Go Developer

The scope of var is wrong Never use var to declare variables, use let instead. REF == is conversion and comparison What you really need is ===, which is similar to comparing two interface{}. === is shallow {a:1}==={a:1} is false, while Go struct with string are compared by contents (but not for slice). Also this affects map key comparison. So object key is not so useful in JS as struct key in Go. The equality test is always on the references rather than the contents. ...

February 12, 2019

How to Start Godoc on Mac

Fish: godoc -http=:6060 &; disown (pidof godoc) Bash: godoc -http=:6060 &; disown `pidof godoc` And pidof can be installed with Homebrew.

May 5, 2018

Tmux Cheatsheet on Mac

Create a new session with iTerm2 integration tmux -CC new -s [session-name] Attach to a session with iTerm2 integration tmux -CC attach -t [session-name]

April 20, 2018

How to Diff two JSON Files

Just sort the keys first! Example: cat a.json | jq --sort-keys . > aa.json cat b.json | jq --sort-keys . > bb.json vimdiff aa.json bb.json

April 10, 2018

Pagination Done Right

Server side pagination is intrinsically not accurate, as long as the data is dynamic. The data items could be inserted, deleted or changed on the server side while the user goes forward and backward among the pages. However, there is an algorithm that can keep the pagination as stable as possible: encode the id and sorting fields of last value in a page as the continue-token return the continue-token along with each page the client must pass the continue-token to fetch the next page the next page starts with value > continue-token || (value == continue-token && value.id > continue-token.id) Reference Pagination with Dynamic Data Loading

February 28, 2018

How to Measure Response Time with Curl

curl [args] --write-out "%{time_total}s" --output /dev/null --silent [URL]

June 20, 2017

How to Delete a Git Branch

git fetch --prune origin git branch --delete [branch-name] git push origin --delete [branch-name]

June 9, 2017