@h12.io

How to Start Godoc on Mac

5 May 2018

Fish:

godoc -http=:6060 &; disown (pidof godoc)

Bash:

godoc -http=:6060 &; disown `pidof godoc`

And pidof can be installed with Homebrew.

Tmux Cheatsheet on Mac

20 April 2018

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]

How to Diff two JSON Files

10 April 2018

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

Pagination Done Right

28 February 2018

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:

  1. encode the id and sorting fields of last value in a page as the continue-token
  2. return the continue-token along with each page
  3. the client must pass the continue-token to fetch the next page
  4. the next page starts with value > continue-token || (value == continue-token && value.id > continue-token.id)

Reference

buid: Bipartite Unique Identifier

15 November 2017

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.

Bigendian is chosen to make each part byte-wise lexicographic sortable.

The string representation uses basex 62 encoding.

How to Measure Response Time with Curl

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

How to Delete a Git Branch

9 June 2017
git fetch       --prune  origin
git branch      --delete [branch-name]
git push origin --delete [branch-name]