Skip to content

Commit 2aa10ea

Browse files
committed
First version
0 parents  commit 2aa10ea

File tree

8 files changed

+252
-0
lines changed

8 files changed

+252
-0
lines changed

.autotest

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- ruby -*-
2+
3+
require 'autotest/restart'
4+
5+
# Autotest.add_hook :initialize do |at|
6+
# at.extra_files << "../some/external/dependency.rb"
7+
#
8+
# at.libs << ":../some/external"
9+
#
10+
# at.add_exception 'vendor'
11+
#
12+
# at.add_mapping(/dependency.rb/) do |f, _|
13+
# at.files_matching(/test_.*rb$/)
14+
# end
15+
#
16+
# %w(TestA TestB).each do |klass|
17+
# at.extra_class_map[klass] = "test/test_misc.rb"
18+
# end
19+
# end
20+
21+
# Autotest.add_hook :run_command do |at|
22+
# system "rake build"
23+
# end

History.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== 1.0.0 / 2013-11-01
2+
3+
* 1 major enhancement
4+
5+
* Birthday!
6+

Manifest.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.autotest
2+
History.txt
3+
Manifest.txt
4+
README.txt
5+
Rakefile
6+
bin/rubyconf
7+
lib/rubyconf.rb
8+
test/test_rubyconf.rb

README.txt

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
= rubyconf
2+
3+
* http://github.com/rubycentral/rubyconf
4+
5+
== DESCRIPTION:
6+
7+
Tools for when you're at rubyconf!
8+
9+
== FEATURES/PROBLEMS:
10+
11+
* Post results about the wireless for us to sample to make the conf better
12+
13+
== SYNOPSIS:
14+
15+
$ rubyconf
16+
17+
== REQUIREMENTS:
18+
19+
* Mac OS X 10.5+
20+
21+
== INSTALL:
22+
23+
* gem install rubyconf
24+
25+
== DEVELOPERS:
26+
27+
After checking out the source, run:
28+
29+
$ rake newb
30+
31+
This task will install any missing dependencies, run the tests/specs,
32+
and generate the RDoc.
33+
34+
== LICENSE:
35+
36+
(The MIT License)
37+
38+
Copyright (c) 2013 Evan Phoenix
39+
40+
Permission is hereby granted, free of charge, to any person obtaining
41+
a copy of this software and associated documentation files (the
42+
'Software'), to deal in the Software without restriction, including
43+
without limitation the rights to use, copy, modify, merge, publish,
44+
distribute, sublicense, and/or sell copies of the Software, and to
45+
permit persons to whom the Software is furnished to do so, subject to
46+
the following conditions:
47+
48+
The above copyright notice and this permission notice shall be
49+
included in all copies or substantial portions of the Software.
50+
51+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
52+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
53+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
54+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
55+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
56+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
57+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Rakefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- ruby -*-
2+
3+
require 'rubygems'
4+
require 'hoe'
5+
6+
7+
Hoe.spec 'rubyconf' do
8+
developer('Evan Phoenix', '[email protected]')
9+
end
10+
11+
# vim: syntax=ruby

bin/rubyconf

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'rubyconf'
4+
require 'optparse'
5+
6+
rc = Rubyconf.new
7+
8+
interval = 300
9+
10+
opts = OptionParser.new do |o|
11+
o.on "--scan", "Display info about all wireless networks around" do
12+
rc.refresh_wireless
13+
rc.show_networks
14+
exit
15+
end
16+
17+
o.on "-i", "--interval INTEGER", "Control how often to post info (default: 300s)" do |s|
18+
interval = s.to_i
19+
end
20+
end
21+
22+
puts "Posting details about wireless network ever #{interval} seconds..."
23+
24+
begin
25+
loop do
26+
rc.post!
27+
sleep interval
28+
end
29+
rescue Interrupt
30+
end

lib/rubyconf.rb

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
require 'plist'
2+
require 'base64'
3+
require 'socket'
4+
require 'json'
5+
require 'net/http'
6+
7+
class Rubyconf
8+
VERSION = '1.0.0'
9+
10+
class WirelessNetwork
11+
def initialize(data)
12+
@data = data
13+
end
14+
15+
def bssid
16+
@data["BSSID"]
17+
end
18+
19+
def channel
20+
@data["CHANNEL"]
21+
end
22+
23+
def ssid
24+
@ssid ||= @data["SSID"].string
25+
end
26+
27+
def noise
28+
@data["NOISE"]
29+
end
30+
31+
def rssi
32+
@data["RSSI"]
33+
end
34+
35+
def show
36+
printf "%20s %4s %d\n", ssid, rssi, channel
37+
end
38+
end
39+
40+
def refresh_wireless(xml=nil)
41+
xml ||= `airport -x -s`
42+
43+
out = Plist.parse_xml xml
44+
45+
@networks = out.map { |w| WirelessNetwork.new(w) }
46+
end
47+
48+
def show_networks(filter=/./)
49+
printf "%20s %4s %s\n", "SSID", "RSSI", "CHANNEL"
50+
@networks.each do |n|
51+
if n.ssid =~ filter
52+
n.show
53+
end
54+
end
55+
end
56+
57+
class CurrentNetwork
58+
def initialize(data)
59+
@data = data
60+
end
61+
62+
def external
63+
{
64+
'ssid' => @data['SSID'],
65+
'bssid' => @data['BSSID'],
66+
'rssi' => @data['agrCtlRSSI'].to_i,
67+
'noise' => @data['agrCtlNoise'].to_i,
68+
'channel' => @data['channel'].to_i,
69+
'txrate' => @data['lastTxRate'].to_i,
70+
'maxrate' => @data['maxRate'].to_i
71+
}
72+
end
73+
end
74+
75+
def current_network
76+
data = `airport -I`
77+
78+
vals = data.split("\n").map { |x| x.split(":", 2).map { |i| i.strip } }
79+
80+
CurrentNetwork.new Hash[*vals.flatten]
81+
end
82+
83+
def ttg
84+
s = TCPSocket.new "74.125.224.134", 80
85+
start = Time.now
86+
s << "GET / HTTP/1.0\r\n\r\n"
87+
s.read(4)
88+
fin = Time.now
89+
s.close
90+
91+
fin - start
92+
end
93+
94+
def post!
95+
data = current_network.external
96+
97+
data['ttg'] = ttg
98+
99+
Net::HTTP.start "rubyconf-wireless.herokuapp.com", 80 do |http|
100+
r = http.post "/sampler", JSON.dump(data)
101+
if r.code != "200"
102+
puts "Error posting results: #{r.inspect}"
103+
if $DEBUG
104+
puts r.body
105+
end
106+
end
107+
end
108+
end
109+
end

test/test_rubyconf.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require "test/unit"
2+
require "rubyconf"
3+
4+
class TestRubyconf < Test::Unit::TestCase
5+
def test_sanity
6+
flunk "write tests or I will kneecap you"
7+
end
8+
end

0 commit comments

Comments
 (0)