Work, work. Zug zug.

I wrote a little script to block websites which would destract me from work. Inspired by get-shit-done and the Orc voices from Warcraft 2. The script can be called as either workwork or readytowork to enable the block, and workcomplete to unblock the websites.

Warning: Contains a list of websites which will waste your time.

#!/usr/bin/env ruby

SiteList = %w{
  reddit.com
  news.ycombinator.com
  twitter.com
  plus.google.com
  slashdot.org
  cracked.com
  vimeo.com
  youtube.com
  digg.com
}

StartToken = '## workwork'
EndToken = "## zugzug\n"

HostsFile = '/etc/hosts'
ConfigFile = '~/.workwork'

def disabled_sites
  if File.exist?(ConfigFile)
    open(ConfigFile).read.split("\n")
  else
    SiteList
  end
end

def workwork
  lines = []
  lines << StartToken
  disabled_sites.each do |site|
    lines << "127.0.0.1\t#{site}"
    lines << "127.0.0.1\twww.#{site}"
  end
  lines << EndToken

  open(HostsFile, 'a+') do |file|
    file.write lines.join("\n")
  end
end

def workcomplete
  open(HostsFile, 'r+') do |file|
    string = file.read
    string.gsub!(/#{StartToken}.*#{EndToken}/m, '')
    file.seek(0)
    file.truncate(0)
    file.write(string)
  end
end

# switch to root since we need to change /etc/hosts
if ENV["USER"] != "root"
  exec("sudo #{ENV['_']} #{ARGV.join(' ')}")
end

case File.basename($0)
when 'workwork' then
when 'readytowork' then
  workwork
when 'workcomplete' then
  workcomplete
else
  puts "Unknown command"
end

Now I just need a script to remove executable permissions from minecraft.