Recent Posts

Setting up bash completion for git on Mac OS

1 minute read

I’ve been using git for various projects and want to share tips for making it more convenient. One of git’s advantages is cheap branches. A branch is just a file in .git/refs/heads containing the id of the last commit, so creating a new branch takes very little time. With such capabilities, most programmers use branches extensively. Whatever model you choose for branches, you can eventually forget which branch you’re on and commit code to the wrong place. Although this is easily fixed, you can avoid it by adding branch information to your bash prompt.

Bit Counting Methods Overview

2 minute read

Counting the number of bits set to “1” in a number is a classic programming problem. Donald Knuth discusses solution methods in his classic work. This problem matters for three reasons. First, several solution methods differ drastically in performance, and choosing the right implementation can significantly speed up your code. Second, it has many practical applications in routing protocols and search. Third, it appears in interviews at major companies. Counting methods fall into three categories: shifting, algebraic logic, and table lookup.