nogoth-pastejour 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +55 -0
- data/Rakefile +56 -0
- data/bin/pastejour +16 -0
- data/lib/pastejour.rb +85 -0
- data/lib/pastejour/version.rb +3 -0
- data/spec/helper.rb +11 -0
- data/spec/pastejour/pastejour_spec.rb +7 -0
- data/spec/spec.opts +7 -0
- metadata +72 -0
data/README.rdoc
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= Pastejour
|
2
|
+
|
3
|
+
Broadcast standard out.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
sudo gem install dnssd
|
8
|
+
sudo gem install jbarnette-pastejour --source=http://gems.github.com
|
9
|
+
|
10
|
+
== Usage
|
11
|
+
|
12
|
+
alice$ git diff | pastejour
|
13
|
+
bob$ pastejour alice | cat
|
14
|
+
|
15
|
+
alice$ git diff | pastejour bob
|
16
|
+
bob$ pastejour | cat
|
17
|
+
|
18
|
+
alice$ git diff | pastejour monkeys
|
19
|
+
bob$ pastejour alice-monkeys | cat
|
20
|
+
|
21
|
+
== ORLY?
|
22
|
+
|
23
|
+
Yup. Pastejour gives you a simple, discoverable pipe for standard in and
|
24
|
+
out. By default, Pastejour will only stay up until the first person
|
25
|
+
grabs your paste. If you want to let a bunch of people grab the same
|
26
|
+
thing, shoot it out in multiple mode:
|
27
|
+
|
28
|
+
alice$ git diff | pastejour -m # keeps on serving 'til you CTRL-C
|
29
|
+
|
30
|
+
== Awesome!
|
31
|
+
|
32
|
+
You know it.
|
33
|
+
|
34
|
+
== License
|
35
|
+
|
36
|
+
Copyright (c) 2008 John Barnette, Evan Phoenix
|
37
|
+
|
38
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
39
|
+
a copy of this software and associated documentation files (the
|
40
|
+
"Software"), to deal in the Software without restriction, including
|
41
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
42
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
43
|
+
permit persons to whom the Software is furnished to do so, subject to
|
44
|
+
the following conditions:
|
45
|
+
|
46
|
+
The above copyright notice and this permission notice shall be
|
47
|
+
included in all copies or substantial portions of the Software.
|
48
|
+
|
49
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
50
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
51
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
52
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
53
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
54
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
55
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "date"
|
2
|
+
require "fileutils"
|
3
|
+
require "rubygems"
|
4
|
+
require "rake/gempackagetask"
|
5
|
+
require "spec/rake/spectask"
|
6
|
+
|
7
|
+
require "./lib/pastejour/version.rb"
|
8
|
+
|
9
|
+
pastejour_gemspec = Gem::Specification.new do |s|
|
10
|
+
s.name = "pastejour"
|
11
|
+
s.version = Pastejour::VERSION
|
12
|
+
s.platform = Gem::Platform::RUBY
|
13
|
+
s.has_rdoc = true
|
14
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
15
|
+
s.summary = "Broadcast standard out."
|
16
|
+
s.description = s.summary
|
17
|
+
s.authors = ["John Barnette", "Evan Phoenix"]
|
18
|
+
s.email = "jbarnette@rubyforge.org"
|
19
|
+
s.homepage = "http://github.com/jbarnette/pastejour"
|
20
|
+
s.require_path = "lib"
|
21
|
+
s.autorequire = "pastejour"
|
22
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
|
23
|
+
s.executables = %w(pastejour)
|
24
|
+
|
25
|
+
s.add_dependency "dnssd", ">= 0.6.0"
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::GemPackageTask.new(pastejour_gemspec) do |pkg|
|
29
|
+
pkg.gem_spec = pastejour_gemspec
|
30
|
+
end
|
31
|
+
|
32
|
+
namespace :gem do
|
33
|
+
namespace :spec do
|
34
|
+
desc "Update pastejour.gemspec"
|
35
|
+
task :generate do
|
36
|
+
File.open("pastejour.gemspec", "w") do |f|
|
37
|
+
f.puts(pastejour_gemspec.to_ruby)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :install => :package do
|
44
|
+
sh %{sudo gem install pkg/pastejour-#{Pastejour::VERSION}}
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Run all specs"
|
48
|
+
Spec::Rake::SpecTask.new do |t|
|
49
|
+
t.spec_files = FileList["spec/**/*_spec.rb"]
|
50
|
+
t.spec_opts = ["--options", "spec/spec.opts"]
|
51
|
+
end
|
52
|
+
|
53
|
+
task :default => :spec
|
54
|
+
|
55
|
+
desc "Remove all generated artifacts"
|
56
|
+
task :clean => :clobber_package
|
data/bin/pastejour
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "pastejour"
|
5
|
+
|
6
|
+
multiple = ARGV.delete("-m")
|
7
|
+
name = ARGV.shift
|
8
|
+
|
9
|
+
if $stdin.tty?
|
10
|
+
name = /#{ENV["USER"]}$/ if name.nil? || name.empty?
|
11
|
+
$stdout.write(Pastejour.get(name))
|
12
|
+
$stdout.flush
|
13
|
+
else
|
14
|
+
name = [ENV["USER"], name].compact.join("-")
|
15
|
+
Pastejour.serve(name, multiple, $stdin.read)
|
16
|
+
end
|
data/lib/pastejour.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'net/dns/mdns-sd'
|
2
|
+
require "socket"
|
3
|
+
require "webrick"
|
4
|
+
require "set"
|
5
|
+
require "pastejour/version"
|
6
|
+
|
7
|
+
DNSSD = Net::DNS::MDNSSD
|
8
|
+
|
9
|
+
|
10
|
+
Thread.abort_on_exception = true
|
11
|
+
|
12
|
+
module Pastejour
|
13
|
+
include Socket::Constants
|
14
|
+
|
15
|
+
Paste = Struct.new(:name, :host, :port)
|
16
|
+
PORT = 42424
|
17
|
+
SERVICE = "_pastejour._tcp"
|
18
|
+
|
19
|
+
def self.find(name, first=true)
|
20
|
+
hosts = Set.new
|
21
|
+
|
22
|
+
waiting = Thread.current
|
23
|
+
|
24
|
+
service = DNSSD.browse(SERVICE) do |reply|
|
25
|
+
if name === reply.name
|
26
|
+
DNSSD.resolve(reply.name, reply.type, reply.domain) do |rr|
|
27
|
+
hosts << Paste.new(reply.name, rr.target, rr.port)
|
28
|
+
waiting.run if first
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
sleep 5
|
34
|
+
service.stop
|
35
|
+
|
36
|
+
hosts
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.get(name)
|
40
|
+
hosts = find(name)
|
41
|
+
|
42
|
+
if hosts.empty?
|
43
|
+
STDERR.puts "ERROR: Unable to find #{name}"
|
44
|
+
elsif hosts.size > 1
|
45
|
+
STDERR.puts "ERROR: Multiple possibles found:"
|
46
|
+
hosts.each do |host|
|
47
|
+
STDERR.puts " #{host.name} (#{host.host}:#{host.port})"
|
48
|
+
end
|
49
|
+
else
|
50
|
+
# Set is weird. There is no #[] or #at
|
51
|
+
hosts.each do |host|
|
52
|
+
STDERR.puts "(#{host.name} from #{host.host}:#{host.port})"
|
53
|
+
sock = TCPSocket.open host.host, host.port
|
54
|
+
return sock.read
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# FIXME: actually read the paste contents
|
59
|
+
# TCPSocket.open("localhost", PORT).read
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.serve(name, multiple, contents)
|
63
|
+
tr = DNSSD::TextRecord.new
|
64
|
+
tr['description'] = File.read("#{path}/.git/description") rescue "a git project"
|
65
|
+
|
66
|
+
DNSSD.register(name, SERVICE, "local", PORT, tr.encode) do |reply|
|
67
|
+
puts "Pasting #{name}..."
|
68
|
+
end
|
69
|
+
|
70
|
+
log = WEBrick::Log.new(true) # true fools it
|
71
|
+
def log.log(*anything); end # send it to the abyss
|
72
|
+
|
73
|
+
server = WEBrick::GenericServer.new(:Port => PORT, :Logger => log)
|
74
|
+
|
75
|
+
trap "INT" do
|
76
|
+
server.shutdown
|
77
|
+
exit!
|
78
|
+
end
|
79
|
+
|
80
|
+
server.start do |socket|
|
81
|
+
socket.print(contents)
|
82
|
+
server.shutdown unless multiple
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path("#{File.dirname(__FILE__)}/../lib"))
|
2
|
+
|
3
|
+
require "spec"
|
4
|
+
require "pastejour"
|
5
|
+
|
6
|
+
module Spec::Expectations::ObjectExpectations
|
7
|
+
alias_method :must, :should
|
8
|
+
alias_method :must_not, :should_not
|
9
|
+
undef_method :should
|
10
|
+
undef_method :should_not
|
11
|
+
end
|
data/spec/spec.opts
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nogoth-pastejour
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Barnette
|
8
|
+
- Evan Phoenix
|
9
|
+
- Ben Livingood
|
10
|
+
autorequire: pastejour
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2008-06-03 00:00:00 -07:00
|
15
|
+
default_executable: pastejour
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: net-mdns
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.4.0
|
25
|
+
version:
|
26
|
+
description: Broadcast standard out.
|
27
|
+
email: livingood@gmail.com
|
28
|
+
executables:
|
29
|
+
- pastejour
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- README.rdoc
|
36
|
+
- Rakefile
|
37
|
+
- bin/pastejour
|
38
|
+
- lib/pastejour
|
39
|
+
- lib/pastejour/version.rb
|
40
|
+
- lib/pastejour.rb
|
41
|
+
- spec/helper.rb
|
42
|
+
- spec/pastejour
|
43
|
+
- spec/pastejour/pastejour_spec.rb
|
44
|
+
- spec/spec.opts
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://github.com/nogoth/pastejour
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.0.1
|
68
|
+
signing_key:
|
69
|
+
specification_version: 2
|
70
|
+
summary: Broadcast standard out.
|
71
|
+
test_files: []
|
72
|
+
|