Created
October 13, 2009 17:37
-
-
Save burke/209392 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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