DEV Community

Cover image for Distractions, whose life is it anyway?

Posted on

Distractions, whose life is it anyway?

Some websites these days are designed to waste your time. You click and before you know it, you wasted an hour or more of your life.

You probably have better things to do.

So how do you get your life back?

Browser blocking

The most simple way is browser blocking. But that doesn't help, because as an experienced developer you have so many ways to quickly browse the web : chrome,firefox,falkon,safari,links,lynx.

Chances are you are using multiple computers at once. So that approach isn't effective.

Lets be honest: Browser block isn't effective for hardcore developer.

But you can try with leechblock, stayfocusd or tools like that

System blocking

One way is blocking those sites in /etc/hosts
So you can add a line like this

That would block the site. This works fine in an office computer, but what if you're working from home?

Firefox DNS caching

Now if you use Firefox, it has it's own DNS cache expiriation. Open about:config, search for network.dnsCacheExpiration and set it to 0. Then restart Firefox.

Python to the rescue

Can write a Python script that automatically blocks at certain hours.
Something like this (I haven't extensively tested this yet):

import time
from datetime import datetime as dt
from datetime import datetime

#Path to the host file, redirect to local host, list of websits to block
host_path = "/etc/hosts"
redirect = ""
website_list = ["","", "","","","",""]

def is_between(time, time_range):
    if time_range[1] < time_range[0]:
        return time >= time_range[0] or time <= time_range[1]
    return time_range[0] <= time <= time_range[1]

while True:
    #Check for the current time

    what_time_is_it ='%H:%M')
    if not is_between(what_time_is_it, ("09:00", "17:00")):
        file = open(host_path,'w+')
        print("Work time now")
        file = open(host_path,'w+')
        for website in website_list:
            print('block ' + website)
            line = redirect + "  " + website + "\n"


Now this could run in the background. As a tech geek, you can just use pkill to close Python. So this also wouldn't be perfect.

Related links:

Discussion (0)