78 comments

[ 3.2 ms ] story [ 97.9 ms ] thread
I do this, although only by saying

    sudo cp hosts.play /etc/hosts
or

    sudo cp hosts.work /etc/hosts
It's simple, and surprisingly efficient.
The only problem with this method is that if you modify your hosts file, you have to modify both.
sudo cp /etc/hosts /etc/hosts.bak && cat hosts.work >> /etc/hosts

sudo cp /etc/hosts.bak /etc/hosts

Note: I just wrote this now with no testing whatsoever.

Just create a Makefile or something that cats together hosts.common and hosts.work or hosts.play.

  all:
      cat hosts.common hosts.work.in > hosts.work
      cat hosts.common hosts.play.in > hosts.play
Make common changes to hosts.common and easily build your final hosts files.

  play:
     cat hosts.play | sudo tee /etc/hosts > /dev/null

  work:
     cat hosts.work | sudo tee /etc/hosts > /dev/null
How often do you modify your hosts file? I only ever find myself adding more things to block to it.
I did this in the past too. The amazing thing is that it actually cures the addiction, not just the symptoms. On the first day you find yourself clicking on the reddit bookmark like an idiot every 20 mins, only to be redirected to localhost. After a few days the impulse is gone and you can actually go back to a non censured /etc/hosts: your self control is back. YMMV.
Does this work with Chrome? I believe Chrome does it's own dns resolution and skips the host file. (I defiantly know it won't resolve localhost if you're offline)
I've edited my hosts file with various domain->ip mappings, and it's worked fine for me in chrome.
When I am working on Linux I do the same thing, except I have cron job copy hosts.work to hosts at 9am(insert your favorite get to work time) and hosts.play at 5pm. Works really well.

I wonder if one can do the same on Windows 7, some way of scheduling tasks easily.

Does it have a timer to keep me from modifying it every 2 minutes?
You should be able to use an asynchronous cron scheduler to implement something like Pomodoro with this. Combined with the right notification tool this could work quite well.
Use FreeBSD, set the kernlevel to something above the minimum, and add the flags to the file so it can't be changed, then until you reboot you won't be able to modify the hosts file =)
https://addons.mozilla.org/en-us/firefox/addon/leechblock/

does windows of access, allows for x minutes, has grouping. Course, it's FF only where hosts file gets your whole connection.

StayFocusd for Chrome Users - https://chrome.google.com/webstore/detail/laankejkbhbdhmipfm...

latest version has a neat feature which tracks links from blocked pages. Ie if I give myself 15 mins of HN a day, but end up wasting 2 hours because I only spend 10 secs on HN opening up tabs to read, it now tracks that. Any links you click from HN will count towards your time limit.

leechblock has helped my compulsive reddit habit :/
For Mac users, SelfControl is a GUI approach to this idea: http://visitsteve.com/made/selfcontrol/
One of the best features is that it runs on a timer and you can't cancel it prematurely. Even if you restart.
You can. It uses ipfw, and I think you can reset the rules. At least I managed when I tried it, but this was some 3 years ago.
I used StayFocusd for a day or two and realized I was a lost cause when I found myself opening its sqlite database in my Chrome profile to add time to the clock.
Unfortunately you can just right click and disable extensions on chrome. Since the exit barrier is so low, I was always able to exit even when I shouldn't have.
Isn't the point of this approach to be _difficult_ to switch back and forth? Next thing you know there will be a chrome extension that swaps your hosts file and you will be separated from procrastination by a single click.
I found it useful to force myself to manually comment/uncomment lines in my hosts file. It gives a critical few moments for a bit of humiliation to set in, as you realize how desperate you are for diversion. On the other end, it gives a moment to mentally pat yourself on the back for eliminating the distractions.
Nowhere near as broad-ranging, but I'll make the note for HN users not aware of it - if HN is your sole (main?) distraction, you can use the noprocrast feature on your user page. Change to Yes, add a max time you allow yourself to visit HN and then the min time you want to be forced to be away.

As I say, nowhere near as broadly applicable or useful as the OP, but worth noting especially if (like me) HN is your distraction of choice and you have minimal technical skills.

>if (like me) HN is your distraction of choice and you have minimal technical skills.

this is a small and interesting portion of mindspace

The noprocrast feature stops working very well when you use Safari. It has the web page preview stuff, and every-time that refreshes the noprocrast kicks in. Since it does that way more often than I visit the site the site is continuously in noprocrast mode.
After playing with noprocrast, I found very good settings for me are

maxvisit: 20

minaway: 1

That means, every 20 minutes HN kicks me off for one minute. I leave it like that constantly - it means if I'm spending time on here nonstop for an hour or two, I get a couple little reminders to ask myself if I really want to be on here. If I do, it's not a big deal to get up and make myself a tea or whatever until 1 minute passes, if not I close the tab and get to business, and it's low enough that I don't cheat by logging in with another browser or Chrome Incognito Mode.

It is not the greatest distraction, but a significant fraction of it (#1 distraction, and about 3x as big as #2, according to RescueTime).

While it is not a huge problem, and there is lot of value I extract from this site, culling seems like a good idea. A daily quota would help me avoid the high hitters and still keep myself "well read".

treating the symptoms rather than the disease is only a good choice for short term or for incurable diseases
You may be right. But repeating an action forms a habit, or in this case learning to not repeatedly open up HN or Reddit can become a long-term habit for anyone with the right mindset.
my main point being that if they stop with HN/Reddit something else will fill that gap. Not working is the issue.
Sorry to be the guy decrying PHP, but the only arguments I've found in it's favor are it's ubiquity and being sometimes "the right tool for the job" if you're quickly hacking together a dynamic webpage.

Surely a simple cli app isn't the right job for this tool.

Now, all that said, it _does_ work, and blahblahblah.

Yep, beware I didn't even tested it:

    #!/usr/bin/env zsh

    (($#<1)) && {
        print -- "usage: $0:t (play|work)"
            exit 1
    }>&2
    blacklist=(
            reddit.com
            ycombinator.com
            slashdot.com
            )

    hostfile=/etc/host

    if [[ $1 = "play" ]]; then
        if [[ ! -e $hostfile.orig ]]; then
            cp $hostfile{,.orig}
        else
            print -- "You're already playin" >&2
            exit 1
        fi
        cp $hostfile{.orig,}
        for elem in $blacklist; do
            print -- "127.0.0.1\t$elem" >> /etc/host
            print -- "127.0.0.1\twww.$elem" >> /etc/host
        done
    fi

    if [[ $1 = "work" ]]; then
        cp $hostfile{.orig,}
        \rm $hostfile.orig
    fi

    /etc/init.d/networking restart
Thank god! Let me just waste some time getting this installed and then I'll waste some more time testing it, then I'll waste some more time posting this comment to hacker news.
So distracted by this.
Just a quick hack. I added timer-applet in ubuntu. I work on 30 mins intervals and then rest 5 mins. It is pretty handy.
Similar to this, I use eternity time tracker on my iphone to work in 30 minute intervals. During the interval, no email, news sites etc. It has worked really well for me.
I might as well plug tasktop - it's great.
Thankfully this was the first link on the HN homepage. Just reading the articles and comments made me feel sufficiently guilty to stop reading any more :)
Why such interest in this script? Besides being written in php, it's also a fairly kludgey approach to managing /etc/hosts. Is it the vulgarities?

    #!/bin/sh
    [ $UID -eq 0 ] || { echo "You're not root, asshole."; exit 1; }
    [ -f "/etc/hosts.$1" ] || { echo "/etc/hosts.$1 doesn't exist, asshole."; exit 1; }
    cat /etc/hosts.{$1,tail} > /etc/hosts
...

    sudo ~/bin/stopfuckingoff play
It was a sad day when Red Hat removed the insults from sudo.
(comment deleted)
I once wrote a similar script which was configurable and it installed as a service. It would periodically scan /etc/hosts to check I wasn't cheating.

  $ sudo /etc/inid.d/procrastination-ctl start
  OK.
  $ sudo /etc/inid.d/procrastination-ctl stop
  You need to wait 59 minutes before you can stop.
Managed to waste a whole day on that one.
> Managed to waste a whole day on that one

I love the irony.

that's just investment....
yep, pure gold of a punchline
I always wanted to rename the script to "/etc/init.d/procrastination" whereby the command "stop" would start the service and vice-versa.
I took a really simple approach: removing HN, Facebook, Clicky, and Google Reader from my bookmarks bar. Having to type them in manually instead of compulsively clicking is enough to limit me to an hour or two of dicking around per day.
Firefox's AwesomeBar makes this hard. Hacker News is just a 'control-t y tab enter' away.
I don't even use bookmarks because it would take longer to click a bookmark than typing "n" for HN (or "r" for reddit or "f" for facebook) and letting Chrome auto-complete and pressing enter, so this wouldn't help me that much.
Oh, I guess I would call myself a "burst typer", so I usually find it faster to just type all or most of the domain than to type one letter and check to see if Chrome got the right thing. But of course that requires a little bit of effort, so it's still just enough to make me consider whether to go there or get some work done.

I just subconsciously don't trust one-letter autocomplete I guess.

in firefox i have 'red' <down> <enter> already ingrained for reddit, same with 'new' for HN ... it's automatic and you can't tell me typing it all out is faster :P
I permanently blocked all from my laptop and only surf from my iPad now. Works great for me.
Curious, how do you permanently block the sites?
I think it just means that the sites stay redirected in his hosts file.
Correct. If I ever catch myself surfing to a website from my laptop, it gets bookmarked for my iPad and blocked in my /etc/hosts.
this comment thread is turning into quite the social experiment. is ADD a prerequisite for being a good programmer/hacker/etc...?
How does this compare to Programming, Motherfucker?