Skip to content

Commit

Permalink
customize block list with a .rc file
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev Purkayastha committed Nov 4, 2009
1 parent 95665a9 commit 3cc26eb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.textile
Expand Up @@ -12,11 +12,13 @@ and fire off the productivity enhancing server:
sudo ruby productivity_ftw.rb
</pre>

(you'll probably need to install the bjeanes-ghost gem first)

note that you *have to use sudo* cause you are taking over port 80, not sure if it's required on windows also.

h2. Adding more hosts to block

open the <code>b-productive.rb</code> file and add to the <code>BLOCK_LIST</code> host array, a better solution is welcome, i am just lazy.
To create your own blocklist, create a <tt>~/.productivity_ftwrc</tt> file in your home directory. See <tt>productivity_ftwrc.sample</tt> for an example of the right format.

h2. "Thank you"s

Expand Down
20 changes: 18 additions & 2 deletions b-productive.rb
Expand Up @@ -4,13 +4,29 @@ class Productivity

require 'rubygems'
begin
gem 'ghost'
gem 'bjeanes-ghost'
require 'ghost'
rescue Gem::LoadError
puts "you need to install the ghost gem from http://github.com/bjeanes/ghost"
end

# Format of .productivity_ftwrc (saved in home dir):
# - Each line is a space-separated list of one or more words.
# - First word is the base of the subdomain.
# - If not qualified with .com/.net/.org, assumed to be .com
# - The www. prefix is assumed to be blocked.
# - subsequent words are subdomains to block.
productivity_ftwrc = "#{ENV['HOME']}/.productivity_ftwrc"
if File.exists?(productivity_ftwrc)
BLOCK_LIST = File.read(productivity_ftwrc).split("\n").map do |domain, subdomains|
domain += ".com" unless domain =~ /\.(org|net|com)/
subdomains ||= []
["#{domain}", "www.#{domain}"] + subdomains.map{|subdomain| "#{subdomain}.#{domain}"}
end.flatten
else
BLOCK_LIST = ["facebook.com", "www.facebook.com", "www.twitter.com", "api.twitter.com", "twitter.com"]
end

BLOCK_LIST = ["facebook.com", "www.facebook.com", "www.twitter.com", "api.twitter.com", "twitter.com"]
ALLOWED_ACTIONS = ["start", "stop"]

def self.start
Expand Down
3 changes: 3 additions & 0 deletions productity_ftwrc.sample
@@ -0,0 +1,3 @@
twitter api search
facebook.com
mls-rumors.net

0 comments on commit 3cc26eb

Please sign in to comment.