discipline 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gem "thor", "~> 0.14.6"
@@ -0,0 +1,9 @@
1
+ GEM
2
+ specs:
3
+ thor (0.14.6)
4
+
5
+ PLATFORMS
6
+ ruby
7
+
8
+ DEPENDENCIES
9
+ thor (~> 0.14.6)
@@ -0,0 +1,45 @@
1
+ # Discipline
2
+
3
+ Discipline is a tool to help you stop procrastinating by blocking distracting online content like Facebook, Twitter and other websites.
4
+
5
+ # Install
6
+
7
+ To install discipline, run this command:
8
+
9
+ gem install discipline
10
+
11
+ # Usage
12
+
13
+ To block unwanted online content, run this command in your terminal:
14
+
15
+ sudo discipline on
16
+
17
+ To unblock unwanted online content, run the inverse command in your terminal:
18
+
19
+ sudo discipline off
20
+
21
+ The "sudo" mode of operation is required because discipline works by modifying your <tt>/etc/hosts/</tt> file, which requires root access.
22
+
23
+ # Configuration
24
+
25
+ Create a <tt>~/.discipline_config.yml</tt> file with the following configuration
26
+
27
+ ---
28
+ - youtube.com
29
+ - www.youtube.com
30
+ - techcrunch.com
31
+ - facebook.com
32
+ - www.facebook.com
33
+ - www.twitter.com
34
+ - twitter.com
35
+ - api.twitter.com
36
+ - linkedin.com
37
+ - www.linkedin.com
38
+
39
+ # Supported platforms
40
+
41
+ I've tested this only on the OSX operating system, so I have no idea how it behaves on other platforms. It should work on Linux, for Windows I wouldn't get my hopes up.
42
+
43
+ # Author
44
+
45
+ Copyright © 2012 Tomislav Car, [Infinum](http://www.infinum.hr)
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ DISCIPLINE_ROOT = File.join(File.dirname(File.expand_path(__FILE__)), '..')
3
+ $:.unshift File.join(DISCIPLINE_ROOT, 'lib')
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+
7
+ # gems and libraries
8
+ require 'yaml'
9
+ require 'thor'
10
+
11
+ # local classes
12
+ require 'discipline'
13
+
14
+ # run with thor
15
+ Discipline::App.start
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
2
+ require 'version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'discipline'
6
+ s.version = Discipline::VERSION
7
+ s.summary = "Tool to help you stop procrastinating."
8
+ s.description = "Discipline is a tool to help you stop procrastinating by blocking distracting online content like Facebook, Twitter and other websites."
9
+ s.authors = ['Tomislav Car']
10
+ s.email = ['tomislav@infinum.hr']
11
+ s.homepage = 'http://github.com/carr/discipline'
12
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ end
@@ -0,0 +1,59 @@
1
+ module Discipline
2
+ class Base
3
+ DISCIPLINE_CONFIG_FILE = File.expand_path("~/.discipline_config.yml")
4
+ HOSTS_FILE = '/etc/hosts'
5
+ DELIMITER_START = '# DISCIPLINE BLOCKED HOSTS START'
6
+ DELIMITER_END = '# DISCIPLINE BLOCKED HOSTS END'
7
+
8
+ def initialize
9
+ begin
10
+ @files = YAML.load(File.read(DISCIPLINE_CONFIG_FILE))
11
+ rescue
12
+ raise "Please create a valid config file at #{DISCIPLINE_CONFIG_FILE}"
13
+ end
14
+ end
15
+
16
+ def on
17
+ append = [clear_hosts_file]
18
+ append << DELIMITER_START
19
+ @files.each do |file|
20
+ append << "0.0.0.0 #{file}"
21
+ end
22
+ append << DELIMITER_END
23
+
24
+ write(append)
25
+ end
26
+
27
+ def off
28
+ write([clear_hosts_file])
29
+ end
30
+
31
+ def clear_hosts_file
32
+ hosts_file = File.read(HOSTS_FILE)
33
+ hosts_file.gsub!(/#{DELIMITER_START}(.*)#{DELIMITER_END}/m, '')
34
+ hosts_file.strip
35
+ end
36
+
37
+ def write(append)
38
+ File.open(HOSTS_FILE, 'w+') do |f|
39
+ f.puts append.join("\n")
40
+ end
41
+ end
42
+ end
43
+
44
+ class App < Thor
45
+ include Thor::Actions
46
+
47
+ desc "on", "Lock down this computer"
48
+ def on
49
+ base = Base.new
50
+ base.on
51
+ end
52
+
53
+ desc "off", "Unlock this computer"
54
+ def off
55
+ base = Base.new
56
+ base.off
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module Discipline
2
+ VERSION = "0.9.1"
3
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: discipline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tomislav Car
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-25 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Discipline is a tool to help you stop procrastinating by blocking distracting
15
+ online content like Facebook, Twitter and other websites.
16
+ email:
17
+ - tomislav@infinum.hr
18
+ executables:
19
+ - discipline
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - Readme.md
27
+ - bin/discipline
28
+ - discipline.gemspec
29
+ - lib/discipline.rb
30
+ - lib/version.rb
31
+ homepage: http://github.com/carr/discipline
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.10
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Tool to help you stop procrastinating.
55
+ test_files: []