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)


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]

A Single Command to Download a Website

9 April 2017
wget --recursive --level=2 --no-parent --no-clobber --convert-links --continue

How to Remove Old Kernels in Ubuntu

10 September 2016
sudo apt install byobu
sudo purge-old-kernels


Making Code Block Wrap in Jira

5 September 2016

It is a hack.

Set Jira Administration -> System -> Announcement Banner -> Announcement:

<style type="text/css">
pre {
    white-space: pre-wrap!important;

One-liner to check MongoDB Connections

2 September 2016
mongo --eval "JSON.stringify(db.currentOp(true))" | \
tail -n +3 | \
jq -r .inprog[].client | \
sed 's/\(.*\):.*/\1/' \
| sort | uniq -c | sort -nr
  • dump connection information in standard JSON format
  • remove MongoDB header
  • extract IP:port as a list
  • trim port
  • sort IPs by freqencies