The Most Productive Code I've Ever Written
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 "
127.0.0.1 twitter.com
127.0.0.1 www.twitter.com
127.0.0.1 reddit.com
127.0.0.1 www.reddit.com
127.0.0.1 www.linkedin.com
127.0.0.1 linkedin.com
127.0.0.1 www.facebook.com
127.0.0.1 facebook.com
127.0.0.1 youtube.com
127.0.0.1 www.youtube.com" >> /etc/hosts'
}
After that, we can create a shell script potato.sh
which will source the .bashrc
file and call the block
function
potato.sh
#!/bin/bash
source /Users/simon/.bashrc
block
Now, to make sure this blocking happens frequently, you can add it to your crontab
.
Crontab
0 * * * * sh /PATH_TO_FILE/potato.sh
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.
Sweet
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!
Comments