Skip to content

Instantly share code, notes, and snippets.

@burke
Created October 13, 2009 17:37
Show Gist options
  • Save burke/209392 to your computer and use it in GitHub Desktop.
Save burke/209392 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# -*- ruby -*-
block = ["news.ycombinator.com",
"reddit.com",
"stackoverflow.com"]
fblock = block.map{|e|"127.0.0.1 #{e}"}.join("\n")
hosts = File.readlines("/etc/hosts").join
if ARGV[0] == "stop"
if hosts =~ /# BEGIN INTERBLOCK BLOCK/
hosts.sub!(/\n# BEGIN INTERBLOCK BLOCK\n.*\n# END INTERBLOCK BLOCK\n/m,'')
end
else # start
if hosts =~ /# BEGIN INTERBLOCK BLOCK/
puts "already started!"
else
hosts << "\n# BEGIN INTERBLOCK BLOCK\n#{fblock}\n# END INTERBLOCK BLOCK\n"
end
end
File.open("/etc/hosts","w") do |f|
f.puts hosts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment