whosup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrew Hare
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Whosup
2
+
3
+ A baby monitor, written in Ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'whosup'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install whosup
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/whosup ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "whosup/cli"
4
+
5
+ Whosup::CLI.start
data/lib/whosup.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "whosup/version"
2
+ require "whosup/server"
3
+ require "whosup/client"
4
+ require "whosup/meter"
5
+ require "whosup/terminal"
6
+
7
+ module Whosup
8
+ end
data/lib/whosup/cli.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "whosup"
2
+ require "thor"
3
+
4
+ module Whosup
5
+ class CLI < Thor
6
+
7
+ DEFAULT_PORT = 51703
8
+
9
+ desc "server", "Start a Who's Up server."
10
+ # method_option :port, aliases: "-p", default: DEFAULT_PORT, required: true
11
+ # def server(port)
12
+ def server
13
+ Server.new.start(51703)
14
+ # Server.new.start(port)
15
+ end
16
+
17
+ desc "client", "Start a Who's Up client."
18
+ # method_option :server, aliases: "-s", required: true
19
+ # method_option :port, aliases: "-p", default: DEFAULT_PORT, required: true
20
+ # def client(server, port)
21
+ def client
22
+ # Client.new.start(server, port)
23
+ Client.new.start("192.168.2.54", 51703)
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ require "socket"
2
+ require "narray"
3
+ require "multi_json"
4
+
5
+ module Whosup
6
+ class Client
7
+
8
+ def start(server, port)
9
+
10
+ meter = Meter.new
11
+ output = CoreAudio.default_output_device.output_buffer(1024)
12
+
13
+ output.start
14
+ TCPSocket.open(server, port) do |socket|
15
+ while message = socket.gets
16
+ data = MultiJson.load(message)
17
+ output << data
18
+ meter << data
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,30 @@
1
+ module Whosup
2
+ class Meter
3
+
4
+ MAX = 15_000.0
5
+
6
+ def <<(data)
7
+ level = data.map(&:first).map(&:abs).reduce(:+) / data.size
8
+ percent = level / MAX
9
+ percent = 1 if percent > 1
10
+ bars = (percent * columns).to_i
11
+ print "\r"
12
+ (0..bars).each do |i|
13
+ color = 32 if i <= (columns * 0.5).to_i
14
+ color = 33 if i > (columns * 0.5).to_i
15
+ color = 31 if i >= (columns * 0.75).to_i
16
+ print colorize("|", color)
17
+ end
18
+ print " " * (columns - bars)
19
+ end
20
+
21
+ def colorize(text, color_code)
22
+ "\e[#{color_code}m#{text}\e[0m"
23
+ end
24
+
25
+ def columns
26
+ @columns ||= Whosup::Terminal.columns
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ require "coreaudio"
2
+ require "socket"
3
+ require "multi_json"
4
+ require "artii"
5
+
6
+ module Whosup
7
+ class Server
8
+
9
+ def start(port)
10
+
11
+ puts "=" * Whosup::Terminal.columns
12
+ puts Artii::Base.new.asciify("Who's Up?")
13
+ puts "Waiting for the client to connect..."
14
+
15
+ server = TCPServer.open(port)
16
+ client = server.accept
17
+
18
+ puts "Client connected!"
19
+ puts "Press Ctl+C to shutdown the server..."
20
+
21
+ puts "=" * Whosup::Terminal.columns
22
+
23
+ input = CoreAudio.default_input_device.input_buffer(1024)
24
+ input.start
25
+
26
+ loop do
27
+ client.puts MultiJson.dump(input.read(4096).to_a)
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,9 @@
1
+ module Whosup
2
+ module Terminal
3
+
4
+ def self.columns
5
+ `tput cols`.chomp.to_i - 1
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Whosup
2
+ VERSION = "0.0.1"
3
+ end
data/whosup.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "whosup/version"
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "whosup"
8
+ gem.version = Whosup::VERSION
9
+ gem.author = "Andrew Hare"
10
+ gem.description = "A baby monitor."
11
+ gem.summary = "A baby monitor."
12
+ gem.license = "MIT"
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.require_paths = ["lib"]
17
+ gem.executables = "whosup"
18
+
19
+ gem.add_dependency "thor"
20
+ gem.add_dependency "coreaudio"
21
+ gem.add_dependency "multi_json"
22
+ gem.add_dependency "oj"
23
+ gem.add_dependency "artii"
24
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whosup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Hare
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: coreaudio
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: multi_json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: oj
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: artii
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: A baby monitor.
95
+ email:
96
+ executables:
97
+ - whosup
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - bin/whosup
107
+ - lib/whosup.rb
108
+ - lib/whosup/cli.rb
109
+ - lib/whosup/client.rb
110
+ - lib/whosup/meter.rb
111
+ - lib/whosup/server.rb
112
+ - lib/whosup/terminal.rb
113
+ - lib/whosup/version.rb
114
+ - whosup.gemspec
115
+ homepage: ''
116
+ licenses:
117
+ - MIT
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.23
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: A baby monitor.
140
+ test_files: []