The Most Productive Code I've Ever Written

The Most Productive Code i've Ever Written - Webdesign Antwerpen
Less but more

Lately, I've realized that minimizing all news and social media makes me a happier, calmer and more productive person. 

Crazy, right?

But since I'm also just a fallible human potato who clicks on cat video's, I need help with that.

I've used several browser extensions in the past with time limits, but (being tech-savvy) you can mostly find a way around those.

So the last couple of months I've been using a shell script to update my hosts file which blocks those sites for me.

To set this up, first add the block function in your .bashrc file. This will update your hostsfile to block access to all sites listed.

function block(){
  sudo sed -i "" -e '/twitter/d' /etc/hosts
  sudo sed -i "" -e '/reddit/d' /etc/hosts
  sudo sed -i "" -e '/linkedin/d' /etc/hosts
  sudo sed -i "" -e '/youtube/d' /etc/hosts
  sudo sed -i "" -e '/facebook/d' /etc/hosts

    sudo sh -c 'sudo echo "" >> /etc/hosts'

After that, we can create a shell script which will source the .bashrc file and call the blockfunction

source /Users/simon/.bashrc

Now, to make sure this blocking happens frequently, you can add it to your crontab.


0 * * * * sh /PATH_TO_FILE/

This will block all the sites you've listed every hour of every day. So (at most) you'll have 1 hour of continuous access to those sites.


If I really need to check something, I need to open the hosts file, edit it and save with confirming my password. 

This increased friction usually makes me think twice if it's really needed and has greatly lowered my potato time.

Maybe it's useful for other people as well!