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

Run: Graceful Goroutine Orchestration

Overview While Go provides goroutines, channels and selects as first-class citizens to support concurrent programming, it is not trivial to combine these elements to address important concerns of goroutine orchestration, e.g. error handling, panic recovery, goroutine leak prevention, goroutine reuse, goroutine throttle and logging. The package provides a mini-framework to address those cross-cutting concerns. Quick start go get -u h12.io/run Here is an example illustrating the usage of the goroutine pool and the group. The task is described in the “Google Search 2.0” page from this slide. ...

December 14, 2018

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

buid: Bipartite Unique Identifier

A BUID is a 128-bit unique ID composed of two 64-bit parts: shard and key. It is not only a unique ID, but also contains the sharding information, so that the messages with the same BUID could be stored together within the same DB shard. Also, when a message is stored in a shard, the shard part of the BUID can be trimmed off to save the space, and only the key part needs to be stored as the primary key. ...

November 15, 2017

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