heart_top 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b877bd5fde33399feb6c51f38631661d75bba8bf
4
+ data.tar.gz: 3be1cae7fa2b555645a32a1ab6e0f60ee0a36c8b
5
+ SHA512:
6
+ metadata.gz: 1a68a79c31d766521d925ce1b822f17b9daca246b68973062cc7253e338f2533d523f8351a732ac872ed9ce960158acd616b1d6015b575e5db79ade02478d7c2
7
+ data.tar.gz: 2f04a6cc4fe8c4d3356fbe2a732c6219ba2ca622b93146d97d7c1ea76560fac8aa7fcbe55385bf1ee5527446febdd6fc6e3c78b0dd107120124c1aac253b32c1
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.15.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in heart_top.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Faizal Zakaria
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # HeartTop
2
+
3
+ Ping the heart beat of your laptop every N seconds.
4
+
5
+ ## About
6
+
7
+ To those who work in Coffee Shop, or some random space, have you ever felt the uneasy feeling leaving your laptop unattended ? Well I feel it all the time.
8
+
9
+ HeartTop was born from my frustration working remotely in a random space alone. No one to keep an eye on my laptop. Because I'm paranoid enough to leave my laptop unattended.
10
+
11
+ So I figured, maybe I should have something that constantly pinging my laptop's heartbeat, while leaving it unattended. So here it is.
12
+
13
+ To those who work at Coffee shop, co working space, or random space out there, if you ever feel this, maybe HeartTop could help you out.
14
+
15
+ ## Installation
16
+
17
+ $ gem install heart_top
18
+
19
+ ## Usage
20
+
21
+ ### To start
22
+ ```sh
23
+ $ hearttop start
24
+ ```
25
+
26
+ ### To stop
27
+ ```sh
28
+ $ hearttop stop
29
+ ```
30
+
31
+ ### For help
32
+ ```sh
33
+ $ hearttop -h
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/faizalzakaria/heart_top.
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "heart_top"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/hearttop ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # resolve bin path, ignoring symlinks
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ # add self to libpath
9
+ $:.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ require 'heart_top'
12
+ HeartTop::CLI.run(*ARGV)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/heart_top.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "heart_top/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "heart_top"
8
+ spec.version = HeartTop::VERSION
9
+ spec.authors = ["Faizal Zakaria"]
10
+ spec.email = ["fzakaria@codegarage.co"]
11
+
12
+ spec.summary = %q{HeartTop pings the heartbeat of your laptop every N seconds}
13
+ spec.description = "Have you ever go to free space, coffee shops or some random place to work, \
14
+ and you need to to toilet for pee, or big business? Then worried what would happen to your laptop? \
15
+ This tool could be the solution"
16
+ spec.homepage = "https://github.com/faizalzakaria/heart_top"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.15"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_dependency "terminal-table", "~> 1.8.0"
30
+ spec.add_dependency "rainbow", "~> 2.2.2"
31
+ spec.add_dependency "dante", "~> 0.2.0"
32
+ end
@@ -0,0 +1,26 @@
1
+ require 'heart_top/plugin'
2
+
3
+ class HeartTop::Agent
4
+ PLUGINS = %i(slack)
5
+
6
+ def initialize(interval: , verbose: )
7
+ @interval = interval
8
+ @verbose = verbose
9
+ end
10
+
11
+ def run
12
+ while true do
13
+ execute_plugins
14
+ sleep @interval
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def execute_plugins
21
+ puts 'executing ...' if @verbose
22
+ PLUGINS.each do |plugin|
23
+ Object.const_get("HeartTop::Plugin::#{plugin.capitalize}").send('ping')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,116 @@
1
+ require 'heart_top/agent'
2
+ require 'getoptlong'
3
+ require 'terminal-table'
4
+ require 'rainbow'
5
+ require 'dante'
6
+
7
+ class HeartTop::CLI
8
+ attr_accessor :verbose, :interval
9
+
10
+ class UnsupportedCommand < StandardError; end
11
+
12
+ class << self
13
+ def run(*args)
14
+ begin
15
+ parse_args!(args)
16
+ rescue UnsupportedCommand => e
17
+ print_error(e.message)
18
+ exit
19
+ end
20
+ set_defaults
21
+ print_details
22
+ execute!
23
+ true
24
+ end
25
+
26
+ private
27
+
28
+ def execute!
29
+ send("#@command!")
30
+ end
31
+
32
+ def pid_path
33
+ '/tmp/heartop.pid'
34
+ end
35
+
36
+ def log_path
37
+ '/tmp/hearttop.log'
38
+ end
39
+
40
+ def start!
41
+ options = {
42
+ interval: @interval,
43
+ verbose: @verbose
44
+ }
45
+ Dante::Runner
46
+ .new('hearttop')
47
+ .execute(daemonize: true, pid_path: pid_path, log_path: log_path) do |opts|
48
+ HeartTop::Agent.new(options).run
49
+ end
50
+ end
51
+
52
+ def stop!
53
+ Dante::Runner
54
+ .new('hearttop')
55
+ .execute(:kill => true, :pid_path => pid_path)
56
+ end
57
+
58
+ def set_defaults
59
+ @interval ||= 10
60
+ @verbose ||= false
61
+ end
62
+
63
+ def parse_args!(args)
64
+ opts = GetoptLong.new([ '--help', '-h', GetoptLong::NO_ARGUMENT ],
65
+ [ '--interval', '-i', GetoptLong::REQUIRED_ARGUMENT ],
66
+ [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ])
67
+ @interval = nil
68
+ @verboes = nil
69
+ opts.each do |opt, arg|
70
+ case opt
71
+ when '--help'
72
+ print_help
73
+ when '--interval'
74
+ @interval = arg
75
+ when '--verbose'
76
+ @verbose = true
77
+ end
78
+ end
79
+ @command = args.last
80
+ unless supported_commands?(@command)
81
+ raise UnsupportedCommand.new(Rainbow("Unsupported command detected, ").red + Rainbow(@command).green)
82
+ end
83
+ end
84
+
85
+ def supported_commands?(cmd)
86
+ %w(stop start).include?(cmd)
87
+ end
88
+
89
+ def print_details
90
+ return unless @verbose
91
+ table = Terminal::Table.new do |t|
92
+ t << [Rainbow('verbose').green, Rainbow(@verbose).green]
93
+ t.add_row [Rainbow('interval').green, Rainbow(@interval).green]
94
+ t.add_row [Rainbow('command').green, Rainbow(@command).green]
95
+ end
96
+ puts table
97
+ end
98
+
99
+ def print_error(msg)
100
+ puts Rainbow(msg).red
101
+ end
102
+
103
+ def print_help
104
+ puts <<-EOF
105
+ heartbeat [OPTION]
106
+
107
+ --help, -h:
108
+ show help
109
+
110
+ --interval <interval>, -i <interval>:
111
+ interval, e.g: 10 (in seconds)
112
+
113
+ EOF
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,9 @@
1
+ class HeartTop::Plugin::Base
2
+ class NotImplementedError < StandardError; end
3
+
4
+ class << self
5
+ def ping
6
+ raise NotImplementedError.new "`##{__method__}` must be implemented in subclass"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module HeartTop
2
+ module Plugin
3
+ class Slack
4
+ class << self
5
+ def ping
6
+ puts 'test'
7
+ `curl -X POST --data-urlencode 'payload={"channel": "#hearttop", "username": "hearttop", "text": "This is posted to #hearttop and comes from a bot named hearttop.", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/<key>`
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ module HeartTop
2
+ module Plugin
3
+ end
4
+ end
5
+
6
+ require 'heart_top/plugin/slack'
@@ -0,0 +1,3 @@
1
+ every 1.minute do
2
+ rake "fave:generate_weekly_statements"
3
+ end
@@ -0,0 +1,3 @@
1
+ module HeartTop
2
+ VERSION = "0.1.0"
3
+ end
data/lib/heart_top.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'heart_top/version'
2
+ require 'heart_top/cli'
3
+
4
+ module HeartTop
5
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heart_top
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Faizal Zakaria
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: terminal-table
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rainbow
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.2.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.2.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: dante
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.2.0
97
+ description: Have you ever go to free space, coffee shops or some random place to
98
+ work, and you need to to toilet for pee, or big business? Then worried what would
99
+ happen to your laptop? This tool could be the solution
100
+ email:
101
+ - fzakaria@codegarage.co
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/hearttop
115
+ - bin/setup
116
+ - heart_top.gemspec
117
+ - lib/heart_top.rb
118
+ - lib/heart_top/agent.rb
119
+ - lib/heart_top/cli.rb
120
+ - lib/heart_top/plugin.rb
121
+ - lib/heart_top/plugin/base.rb
122
+ - lib/heart_top/plugin/slack.rb
123
+ - lib/heart_top/schedule.rb
124
+ - lib/heart_top/version.rb
125
+ homepage: https://github.com/faizalzakaria/heart_top
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.6.11
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: HeartTop pings the heartbeat of your laptop every N seconds
149
+ test_files: []