How to clear Terminal output on Mac

If you want to delete all previous output in an OS X terminal window, just press Cmd + K. This will clear the output, but it won’t kill the currently running tasks. I often use this command to remove thousands of lines of logs, so that the new output is easier to search. If you […]

How to change the default Google Assistant timer and clock

A few weeks ago, I bought a Samsung S9. The hardware is great, but the software is terrible. The first thing I did was uninstall the Samsung bloatware and install my favourite apps. I replaced Samsung Clock with Google Clock. Google Clock allows you to set multiple timers, among other things. You might also want […]

How to flatten a directory on Linux and MacOS

If you want to flatten a directory with lots of deeply nested files (for example ./2012/06/09/images/previews/200×200/image1.jpg becomes ./image1.jpg), you can run this simple command: find target/ -mindepth 2 -type f -exec mv -i ‘{}’ target/ ‘;’ All the files in target‘s subdirectories will be moved directly under target. If multiple files have the same name […]

LocalStorage gotchas in Internet Explorer and Safari

localStorage.setItem will throw an “Access denied” error in Internet Explorer InPrivate Browsing mode. Likewise, Safari will give you QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota. To avoid those errors, you will need to wrap your localStorage access in a try/catch block.

How to speed up apt-get on Digital Ocean

For some reason, downloading packages using apt-get install was unusually slow on DigitalOcean this week, barely exceeding 4kbps. Since DigitalOcean droplets are configured to download packages from, all I had to do was to revert them to the default Ubuntu sources using these two commands: sudo sed -i “s/mirrors.digitalocean/archive\.ubuntu/g” /etc/apt/sources.list sudo apt-get update Downloads […]

Deleting directories while preserving symlinks

At work, we needed to replace a pre-existing folder with a symlink. We wanted to symlink the user’s .git/hooks folder to ../build/git-hooks every time the script was run. We wanted to delete .git/hooks if it existed and replace it with a symlink, but we also wanted to avoid deleting ../build/git-hooks‘s contents by accident if the […]

Finding your own phone number in Android Lollipop

If you are a traveller like me, you might often forget your phone number. Here is how to find it: Open Settings Click “About phone” completely at the bottom Click “Status” Click “SIM status”. Your phone number is under “My phone number”

Fixing “/usr/bin/env: node: No such file or directory”

After a fresh install of npm and bower, you may run into the following error while running bower install: /usr/bin/env: node: No such file or directory The fix on Ubuntu is very simple: sudo ln -s /usr/bin/nodejs /usr/bin/node

How to fix slow file read/write in Node.js

This morning, I had trouble with one of my grunt tasks taking several minutes to finish instead of 3-4 seconds. After a bit of troubleshooting, I isolated the bottleneck to a bunch of seemingly harmless file reads. Guess who was the culprit? The company-supplied McAfee. Turning off on-access scan immediately fixed the issue and dropped […]