Pretty Printing from the Commmand Line


The python standard library provides a json library that can be used to pretty print json.

$  echo '{"this": ["that"]}' | python -m json.tool
  "this": [


$  echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' | xmllint --format -
<?xml version="1.0"?>
  <foo a="b">lorem</foo …
more ...

Safely force pushing with Git


I want to modify the most recent commit but its already been pushed to origin. Using the --force-with-lease flag I can "more safely" push to origin and overwrite the existing data.

The --force-with-lease flag checks to make sure the remote repo matches the local cache. In other words, it ensures …

more ...

Rescue a missing git stash


I lost a git stash the other day mysteriously. Here is the process I used to recover a lost stash.

Where is my Stash?

Lets assume you have a git stash:

$ git stash
Saved working directory and index state WIP on master: 1f96501 Unmark two old posts as drafts, check …
more ...

CI for latex files

I wanted to make a build pipeline for my resume which is written in Latex. Using Travis CI, I was able to add a build that would upload an automatically compiled PDF as a release for every tag in a git repository.

sudo: required
dist: trusty
- sudo apt-get -qq …
more ...

Tracing Functions in Python


Sometimes I want to debug the inputs and outputs of function calls to visualize flow or to follow execution passively.

Rather than adding logging statements and littering them around the code, a single decorator can be crafted to show the life cycle of a function:

def trace_args(f):
    def wrapper …
more ...

Spinning down a Harddrive

I wanted to spin down a hard drive before disconnecting. I have an external hard drive and even after I unmounted the drive the disks were still spinning.

Find the device label of the mounted drive:

$ lsblk
sda    253:0    0  20G …
more ...

List User Installed Packages

I started thinking about doing a fresh linux install and was worried that I might not remember all the packages that I had manually installed. A quick search revealed a one-liner that compares the currently installed packages to the list of packages that were available initially to produce a nice …

more ...

Clean up Docker Instances

Three useful commands to clean up docker if you run out of space

Clean up Containers

docker rm $(docker ps -a -q)

Clean up Images

docker rmi $(docker images | grep "^<none>" | awk '{print $3}')

Clean up Volumes

docker volume rm $(docker volume ls -qf dangling=true)
more ...