Log in

No account? Create an account

March 20th, 2012

Getting Shit Done

I came across an old LifeHacker article Get Shit Done Blocks Distracting Web Sites So You Can Do As the Name Instructs, that mentions a productivity script, get-shit-done. So I went to the github repository only to discover that the Python script was no longer functional. I didn't have permission to fix the script at the site, so here's a quick note-to-self to get around to that. Until then...

[Edit]: There's a better, live branch at GitHub. Use leftnode's version.

Here's an archive of my changes before I discovered leftnode's branch.

  • The syntax errors were fixed. (Like the "play" string in the dictionary at the end that was supposed to be the play method.)

  • It's more Windows friendly. Changing the "hosts" file doesn't require a network driver restart in Windows.

  • You no longer have to specify an argument, "work" or "play." It'll just toggle modes every time you run it now.

  • When reverting to "play" mode, it retains whatever was in the hosts file after the endToken now.

  • I removed the bit of code that optionally reads in from an ini file. The ini file format (the keys, in particular) struck me as awkward.

#!/usr/bin/env python

import sys
import getpass
import subprocess
import os

def exit_error(error):
    print >> sys.stderr, error
    exit( 1 )

restartNetworkingCommand = ["/etc/init.d/networking", "restart"]
# Windows users may have to set up an exception for write access
# to the hosts file in Windows Security Essentials.
hostsFile = '/etc/hosts'
startToken = '## start-gsd'
endToken = '## end-gsd'
siteList = ['reddit.com', 'forums.somethingawful.com',
            'somethingawful.com', 'digg.com', 'break.com',
            'news.ycombinator.com', 'infoq.com',
            'bebo.com', 'twitter.com', 'facebook.com',
            'blip.com', 'youtube.com', 'vimeo.com',
            'flickr.com', 'friendster.com', 'hi5.com',
            'linkedin.com', 'livejournal.com',
            'meetup.com', 'myspace.com', 'plurk.com',
            'stickam.com', 'stumbleupon.com', 'yelp.com',
            'slashdot.com', 'lifehacker.com',
            'plus.google.com', 'gizmodo.com']

def rehash():
    if sys.platform != 'cygwin':

def work():
    with open( hostsFile, 'a' ) as hFile:
        print >> hFile, startToken
        for site in siteList:
            print >> hFile, "\t" + site
            if site.count( '.' ) == 1:
                print >> hFile, "\twww." + site
        print >> hFile, endToken

def play( startIndex, endIndex, lines ):
    with open(hostsFile, "w") as hFile:
        hFile.writelines( lines[0:startIndex] )
        hFile.writelines( lines[endIndex+1:] )

if __name__ == "__main__":
    if sys.platform != 'cygwin' and getpass.getuser() != 'root':
        exit_error( 'Please run script as root.' )

    # Determine if our siteList is already present.
    startIndex = -1
    endIndex = -1
    with open(hostsFile, "r") as hFile:
        lines = hFile.readlines()
        for i, line in enumerate( lines ):
            line = line.strip()
            if line == startToken:
                startIndex = i
            elif line == endToken:
                endIndex = i

    if startIndex > -1 and endIndex > -1:
        play( startIndex, endIndex, lines )



  • 5 Mar 2019, 22:27
    Welcome back to LJ.
    Even if it's just one post :-P

    People moved all over the internet.
    I stil like Plurk the best.
  • 4 Mar 2019, 06:13
    Good to see you checking in at LJ again, too. No, I'm not online anywhere like we used to be at LJ and Plurk. I really liked having a place where we could share our thoughts in a long-form post that…
  • 4 Mar 2019, 03:33
    Good to "see" you checking in at LJ... and taking steps to preserve your LJ and Google+ histories!

    Even better to see "you" and not your Dead Man Switch kicking in... again.

    Do you have a primary…
  • 13 Jan 2018, 18:54
    I "Searched" some of your archive looking for the fluorescent bulb post, but couldn't find it through 2009-02-06, and before that, LiveJournal no longer offers pages of your feed, just daily access,…
  • 10 Jan 2018, 18:22
    Ha ha! How coincidental, I was thinking about light bulbs yesterday myself. One of my Instagram contacts mentioned that the EU regulates the types of light bulbs people can use in their homes in…
Powered by LiveJournal.com
Designed by Jared MacPherson