mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* sample/*: whitespace patch by Sergio Campama [Fixes GH-364]
https://github.com/ruby/ruby/pull/364 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
368cecc151
commit
b4489ae953
25 changed files with 314 additions and 309 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sat Jul 20 22:39:56 2013 Zachary Scott <e@zzak.io>
|
||||||
|
|
||||||
|
* sample/*: whitespace patch by Sergio Campama [Fixes GH-364]
|
||||||
|
https://github.com/ruby/ruby/pull/364
|
||||||
|
|
||||||
Sat Jul 20 22:33:13 2013 Zachary Scott <e@zzak.io>
|
Sat Jul 20 22:33:13 2013 Zachary Scott <e@zzak.io>
|
||||||
|
|
||||||
* doc/regexp.rdoc: [DOC] Fix typo in example [Fixes GH-365]
|
* doc/regexp.rdoc: [DOC] Fix typo in example [Fixes GH-365]
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Cal
|
||||||
ta = gr.collect{|xs| xs.join(' ')}
|
ta = gr.collect{|xs| xs.join(' ')}
|
||||||
|
|
||||||
ca = %w(January February March April May June July
|
ca = %w(January February March April May June July
|
||||||
August September October November December)[m - 1]
|
August September October November December)[m - 1]
|
||||||
ca = ca + ' ' + y.to_s if !@opt_y
|
ca = ca + ' ' + y.to_s if !@opt_y
|
||||||
ca = ca.center(@mw)
|
ca = ca.center(@mw)
|
||||||
|
|
||||||
|
@ -132,10 +132,10 @@ if __FILE__ == $0
|
||||||
|
|
||||||
begin
|
begin
|
||||||
GetoptLong.new(['-c', GetoptLong::REQUIRED_ARGUMENT],
|
GetoptLong.new(['-c', GetoptLong::REQUIRED_ARGUMENT],
|
||||||
['-j', GetoptLong::NO_ARGUMENT],
|
['-j', GetoptLong::NO_ARGUMENT],
|
||||||
['-m', GetoptLong::NO_ARGUMENT],
|
['-m', GetoptLong::NO_ARGUMENT],
|
||||||
['-t', GetoptLong::NO_ARGUMENT],
|
['-t', GetoptLong::NO_ARGUMENT],
|
||||||
['-y', GetoptLong::NO_ARGUMENT]).
|
['-y', GetoptLong::NO_ARGUMENT]).
|
||||||
each do |opt, arg|
|
each do |opt, arg|
|
||||||
case opt
|
case opt
|
||||||
when '-c'; cal.opt_c(arg) || raise
|
when '-c'; cal.opt_c(arg) || raise
|
||||||
|
|
|
@ -38,7 +38,7 @@ at_exit do
|
||||||
end
|
end
|
||||||
cov
|
cov
|
||||||
else
|
else
|
||||||
p line
|
p line
|
||||||
warn("coverage file corrupted, ignoring: #{ cfile }")
|
warn("coverage file corrupted, ignoring: #{ cfile }")
|
||||||
break []
|
break []
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,18 +19,18 @@ class Biff
|
||||||
last = Time.now
|
last = Time.now
|
||||||
while true
|
while true
|
||||||
begin
|
begin
|
||||||
sleep(@interval)
|
sleep(@interval)
|
||||||
current = File::mtime(@filename)
|
current = File::mtime(@filename)
|
||||||
if current > last
|
if current > last
|
||||||
changed
|
changed
|
||||||
begin
|
begin
|
||||||
notify_observers(@filename, current)
|
notify_observers(@filename, current)
|
||||||
rescue Error
|
rescue Error
|
||||||
end
|
end
|
||||||
last = current
|
last = current
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,16 +47,16 @@ class ChatServer
|
||||||
msg2 = ">#{name}< #{str}"
|
msg2 = ">#{name}< #{str}"
|
||||||
@mutex.synchronize do
|
@mutex.synchronize do
|
||||||
for m in @members.keys
|
for m in @members.keys
|
||||||
begin
|
begin
|
||||||
if m == there
|
if m == there
|
||||||
@members[m].listen(msg2)
|
@members[m].listen(msg2)
|
||||||
else
|
else
|
||||||
@members[m].listen(msg)
|
@members[m].listen(msg)
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
p $!
|
p $!
|
||||||
@members.delete(m)
|
@members.delete(m)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,8 +21,8 @@ class Logger
|
||||||
def flush
|
def flush
|
||||||
begin
|
begin
|
||||||
while(1)
|
while(1)
|
||||||
@fp.puts(@queue.pop)
|
@fp.puts(@queue.pop)
|
||||||
@fp.flush
|
@fp.flush
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
@fp.close
|
@fp.close
|
||||||
|
|
|
@ -6,20 +6,20 @@ module DRb
|
||||||
module HTTP0
|
module HTTP0
|
||||||
class StrStream
|
class StrStream
|
||||||
def initialize(str='')
|
def initialize(str='')
|
||||||
@buf = str
|
@buf = str
|
||||||
end
|
end
|
||||||
attr_reader :buf
|
attr_reader :buf
|
||||||
|
|
||||||
def read(n)
|
def read(n)
|
||||||
begin
|
begin
|
||||||
return @buf[0,n]
|
return @buf[0,n]
|
||||||
ensure
|
ensure
|
||||||
@buf[0,n] = ''
|
@buf[0,n] = ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def write(s)
|
def write(s)
|
||||||
@buf.concat s
|
@buf.concat s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -29,47 +29,47 @@ module DRb
|
||||||
|
|
||||||
def self.open(uri, config)
|
def self.open(uri, config)
|
||||||
unless /^http:/ =~ uri
|
unless /^http:/ =~ uri
|
||||||
raise(DRbBadScheme, uri) unless uri =~ /^http:/
|
raise(DRbBadScheme, uri) unless uri =~ /^http:/
|
||||||
raise(DRbBadURI, 'can\'t parse uri:' + uri)
|
raise(DRbBadURI, 'can\'t parse uri:' + uri)
|
||||||
end
|
end
|
||||||
ClientSide.new(uri, config)
|
ClientSide.new(uri, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
class ClientSide
|
class ClientSide
|
||||||
def initialize(uri, config)
|
def initialize(uri, config)
|
||||||
@uri = uri
|
@uri = uri
|
||||||
@res = nil
|
@res = nil
|
||||||
@config = config
|
@config = config
|
||||||
@msg = DRbMessage.new(config)
|
@msg = DRbMessage.new(config)
|
||||||
@proxy = ENV['HTTP_PROXY']
|
@proxy = ENV['HTTP_PROXY']
|
||||||
end
|
end
|
||||||
|
|
||||||
def close; end
|
def close; end
|
||||||
def alive?; false; end
|
def alive?; false; end
|
||||||
|
|
||||||
def send_request(ref, msg_id, *arg, &b)
|
def send_request(ref, msg_id, *arg, &b)
|
||||||
stream = StrStream.new
|
stream = StrStream.new
|
||||||
@msg.send_request(stream, ref, msg_id, *arg, &b)
|
@msg.send_request(stream, ref, msg_id, *arg, &b)
|
||||||
@reply_stream = StrStream.new
|
@reply_stream = StrStream.new
|
||||||
post(@uri, stream.buf)
|
post(@uri, stream.buf)
|
||||||
end
|
end
|
||||||
|
|
||||||
def recv_reply
|
def recv_reply
|
||||||
@msg.recv_reply(@reply_stream)
|
@msg.recv_reply(@reply_stream)
|
||||||
end
|
end
|
||||||
|
|
||||||
def post(url, data)
|
def post(url, data)
|
||||||
it = URI.parse(url)
|
it = URI.parse(url)
|
||||||
path = [(it.path=='' ? '/' : it.path), it.query].compact.join('?')
|
path = [(it.path=='' ? '/' : it.path), it.query].compact.join('?')
|
||||||
http = Net::HTTP.new(it.host, it.port)
|
http = Net::HTTP.new(it.host, it.port)
|
||||||
sio = StrStream.new
|
sio = StrStream.new
|
||||||
http.post(path, data, {'Content-Type'=>'application/octetstream;'}) do |str|
|
http.post(path, data, {'Content-Type'=>'application/octetstream;'}) do |str|
|
||||||
sio.write(str)
|
sio.write(str)
|
||||||
if @config[:load_limit] < sio.buf.size
|
if @config[:load_limit] < sio.buf.size
|
||||||
raise TypeError, 'too large packet'
|
raise TypeError, 'too large packet'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@reply_stream = sio
|
@reply_stream = sio
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,111 +8,111 @@ module DRb
|
||||||
|
|
||||||
def self.open_server(uri, config)
|
def self.open_server(uri, config)
|
||||||
unless /^http:/ =~ uri
|
unless /^http:/ =~ uri
|
||||||
raise(DRbBadScheme, uri) unless uri =~ /^http:/
|
raise(DRbBadScheme, uri) unless uri =~ /^http:/
|
||||||
raise(DRbBadURI, 'can\'t parse uri:' + uri)
|
raise(DRbBadURI, 'can\'t parse uri:' + uri)
|
||||||
end
|
end
|
||||||
Server.new(uri, config)
|
Server.new(uri, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
class Callback < WEBrick::HTTPServlet::AbstractServlet
|
class Callback < WEBrick::HTTPServlet::AbstractServlet
|
||||||
def initialize(config, drb)
|
def initialize(config, drb)
|
||||||
@config = config
|
@config = config
|
||||||
@drb = drb
|
@drb = drb
|
||||||
@queue = Queue.new
|
@queue = Queue.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def do_POST(req, res)
|
def do_POST(req, res)
|
||||||
@req = req
|
@req = req
|
||||||
@res = res
|
@res = res
|
||||||
@drb.push(self)
|
@drb.push(self)
|
||||||
@res.body = @queue.pop
|
@res.body = @queue.pop
|
||||||
@res['content-type'] = 'application/octet-stream;'
|
@res['content-type'] = 'application/octet-stream;'
|
||||||
end
|
end
|
||||||
|
|
||||||
def req_body
|
def req_body
|
||||||
@req.body
|
@req.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def reply(body)
|
def reply(body)
|
||||||
@queue.push(body)
|
@queue.push(body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def close
|
def close
|
||||||
@queue.push('')
|
@queue.push('')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Server
|
class Server
|
||||||
def initialize(uri, config)
|
def initialize(uri, config)
|
||||||
@uri = uri
|
@uri = uri
|
||||||
@config = config
|
@config = config
|
||||||
@queue = Queue.new
|
@queue = Queue.new
|
||||||
setup_webrick(uri)
|
setup_webrick(uri)
|
||||||
end
|
end
|
||||||
attr_reader :uri
|
attr_reader :uri
|
||||||
|
|
||||||
def close
|
def close
|
||||||
@server.shutdown if @server
|
@server.shutdown if @server
|
||||||
@server = nil
|
@server = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def push(callback)
|
def push(callback)
|
||||||
@queue.push(callback)
|
@queue.push(callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
def accept
|
def accept
|
||||||
client = @queue.pop
|
client = @queue.pop
|
||||||
ServerSide.new(client, @config)
|
ServerSide.new(client, @config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_webrick(uri)
|
def setup_webrick(uri)
|
||||||
logger = WEBrick::Log::new($stderr, WEBrick::Log::FATAL)
|
logger = WEBrick::Log::new($stderr, WEBrick::Log::FATAL)
|
||||||
u = URI.parse(uri)
|
u = URI.parse(uri)
|
||||||
s = WEBrick::HTTPServer.new(:Port => u.port,
|
s = WEBrick::HTTPServer.new(:Port => u.port,
|
||||||
:AddressFamily => Socket::AF_INET,
|
:AddressFamily => Socket::AF_INET,
|
||||||
:BindAddress => u.host,
|
:BindAddress => u.host,
|
||||||
:Logger => logger,
|
:Logger => logger,
|
||||||
:ServerType => Thread)
|
:ServerType => Thread)
|
||||||
s.mount(u.path, Callback, self)
|
s.mount(u.path, Callback, self)
|
||||||
@server = s
|
@server = s
|
||||||
s.start
|
s.start
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ServerSide
|
class ServerSide
|
||||||
def initialize(callback, config)
|
def initialize(callback, config)
|
||||||
@callback = callback
|
@callback = callback
|
||||||
@config = config
|
@config = config
|
||||||
@msg = DRbMessage.new(@config)
|
@msg = DRbMessage.new(@config)
|
||||||
@req_stream = StrStream.new(@callback.req_body)
|
@req_stream = StrStream.new(@callback.req_body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def close
|
def close
|
||||||
@callback.close if @callback
|
@callback.close if @callback
|
||||||
@callback = nil
|
@callback = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def alive?; false; end
|
def alive?; false; end
|
||||||
|
|
||||||
def recv_request
|
def recv_request
|
||||||
begin
|
begin
|
||||||
@msg.recv_request(@req_stream)
|
@msg.recv_request(@req_stream)
|
||||||
rescue
|
rescue
|
||||||
close
|
close
|
||||||
raise $!
|
raise $!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_reply(succ, result)
|
def send_reply(succ, result)
|
||||||
begin
|
begin
|
||||||
return unless @callback
|
return unless @callback
|
||||||
stream = StrStream.new
|
stream = StrStream.new
|
||||||
@msg.send_reply(stream, succ, result)
|
@msg.send_reply(stream, succ, result)
|
||||||
@callback.reply(stream.buf)
|
@callback.reply(stream.buf)
|
||||||
rescue
|
rescue
|
||||||
close
|
close
|
||||||
raise $!
|
raise $!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ class TupleSpace
|
||||||
@list = list
|
@list = list
|
||||||
@check_idx = []
|
@check_idx = []
|
||||||
@list.each_with_index do |x, i|
|
@list.each_with_index do |x, i|
|
||||||
@check_idx.push i if x
|
@check_idx.push i if x
|
||||||
end
|
end
|
||||||
@size = @list.size
|
@size = @list.size
|
||||||
end
|
end
|
||||||
|
@ -22,9 +22,9 @@ class TupleSpace
|
||||||
def match(tuple)
|
def match(tuple)
|
||||||
return nil if tuple.size != self.size
|
return nil if tuple.size != self.size
|
||||||
@check_idx.each do |i|
|
@check_idx.each do |i|
|
||||||
unless @list[i] === tuple[i]
|
unless @list[i] === tuple[i]
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -47,13 +47,13 @@ class TupleSpace
|
||||||
found = false
|
found = false
|
||||||
@waiting[sz] = @waiting[sz].find_all { |x|
|
@waiting[sz] = @waiting[sz].find_all { |x|
|
||||||
if x[0].match(tuple)
|
if x[0].match(tuple)
|
||||||
begin
|
begin
|
||||||
x[1].wakeup
|
x[1].wakeup
|
||||||
rescue ThreadError
|
rescue ThreadError
|
||||||
end
|
end
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -77,8 +77,8 @@ class TupleSpace
|
||||||
found = false
|
found = false
|
||||||
@que[sz].each_with_index do |x, i|
|
@que[sz].each_with_index do |x, i|
|
||||||
if template.match(x)
|
if template.match(x)
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil unless found
|
return nil unless found
|
||||||
|
@ -110,17 +110,17 @@ class TupleSpace
|
||||||
def in(template, non_block=false)
|
def in(template, non_block=false)
|
||||||
begin
|
begin
|
||||||
loop do
|
loop do
|
||||||
Thread.critical = true
|
Thread.critical = true
|
||||||
tuple = get_que(template)
|
tuple = get_que(template)
|
||||||
unless tuple
|
unless tuple
|
||||||
if non_block
|
if non_block
|
||||||
raise ThreadError, "queue empty"
|
raise ThreadError, "queue empty"
|
||||||
end
|
end
|
||||||
put_waiting(template, Thread.current)
|
put_waiting(template, Thread.current)
|
||||||
Thread.stop
|
Thread.stop
|
||||||
else
|
else
|
||||||
return tuple
|
return tuple
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
Thread.critical = false
|
Thread.critical = false
|
||||||
|
@ -155,11 +155,11 @@ if __FILE__ == $0
|
||||||
def server(ts, id)
|
def server(ts, id)
|
||||||
Thread.start {
|
Thread.start {
|
||||||
loop do
|
loop do
|
||||||
req = ts.in(['req', nil, nil])
|
req = ts.in(['req', nil, nil])
|
||||||
ac = req[1]
|
ac = req[1]
|
||||||
num = req[2]
|
num = req[2]
|
||||||
sleep id
|
sleep id
|
||||||
ts.out([ac, id, num, num * num])
|
ts.out([ac, id, num, num * num])
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -168,14 +168,14 @@ if __FILE__ == $0
|
||||||
Thread.start {
|
Thread.start {
|
||||||
ac = Object.new
|
ac = Object.new
|
||||||
tuples = (1..10).collect { |i|
|
tuples = (1..10).collect { |i|
|
||||||
['req', ac, i * 10 + n]
|
['req', ac, i * 10 + n]
|
||||||
}
|
}
|
||||||
ts.out(*tuples)
|
ts.out(*tuples)
|
||||||
ts.out(tuples[0])
|
ts.out(tuples[0])
|
||||||
puts "out: #{n}"
|
puts "out: #{n}"
|
||||||
11.times do |i|
|
11.times do |i|
|
||||||
ans = ts.in([ac, nil, nil, nil])
|
ans = ts.in([ac, nil, nil, nil])
|
||||||
puts "client(#{n}) server(#{ans[1]}) #{ans[2]} #{ans[3]}"
|
puts "client(#{n}) server(#{ans[1]}) #{ans[2]} #{ans[3]}"
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -183,12 +183,12 @@ if __FILE__ == $0
|
||||||
def watcher(ts)
|
def watcher(ts)
|
||||||
Thread.start {
|
Thread.start {
|
||||||
loop do
|
loop do
|
||||||
begin
|
begin
|
||||||
sleep 1
|
sleep 1
|
||||||
p ts.rd(['req', nil, nil], true)
|
p ts.rd(['req', nil, nil], true)
|
||||||
rescue ThreadError
|
rescue ThreadError
|
||||||
puts "'req' not found."
|
puts "'req' not found."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -58,10 +58,10 @@ if __FILE__ == $0
|
||||||
def server(ts)
|
def server(ts)
|
||||||
Thread.start {
|
Thread.start {
|
||||||
loop do
|
loop do
|
||||||
req = ts.in('req')
|
req = ts.in('req')
|
||||||
ac = req[0]
|
ac = req[0]
|
||||||
num = req[1]
|
num = req[1]
|
||||||
ts.out(ac, num * num)
|
ts.out(ac, num * num)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ end
|
||||||
STDERR.print "conntecting to #{host} port #{port}\n"
|
STDERR.print "conntecting to #{host} port #{port}\n"
|
||||||
c = TCPSocket.new(host, port)
|
c = TCPSocket.new(host, port)
|
||||||
dest = Socket.getnameinfo(c.getpeername,
|
dest = Socket.getnameinfo(c.getpeername,
|
||||||
Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV)
|
Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV)
|
||||||
STDERR.print "conntected to #{dest[0]} port #{dest[1]}\n"
|
STDERR.print "conntected to #{dest[0]} port #{dest[1]}\n"
|
||||||
c.print "GET #{path} HTTP/1.0\n"
|
c.print "GET #{path} HTTP/1.0\n"
|
||||||
c.print "Host: #{host}\n"
|
c.print "Host: #{host}\n"
|
||||||
|
|
|
@ -29,22 +29,22 @@ end
|
||||||
while true
|
while true
|
||||||
as = ls.accept
|
as = ls.accept
|
||||||
Thread.start do
|
Thread.start do
|
||||||
STDERR.print "socket #{myname} accepted, thread ", Thread.current, "\n"
|
STDERR.print "socket #{myname} accepted, thread ", Thread.current, "\n"
|
||||||
s = as # copy to dynamic variable
|
s = as # copy to dynamic variable
|
||||||
str = ''
|
str = ''
|
||||||
while line = s.gets
|
while line = s.gets
|
||||||
break if line == "\r\n" or line == "\n"
|
break if line == "\r\n" or line == "\n"
|
||||||
str << line
|
str << line
|
||||||
end
|
end
|
||||||
STDERR.print "socket #{myname} got string\n"
|
STDERR.print "socket #{myname} got string\n"
|
||||||
s.write("HTTP/1.0 200 OK\n")
|
s.write("HTTP/1.0 200 OK\n")
|
||||||
s.write("Content-type: text/plain\n\n")
|
s.write("Content-type: text/plain\n\n")
|
||||||
s.write("this is test: my name is #{myname}, you sent:\n")
|
s.write("this is test: my name is #{myname}, you sent:\n")
|
||||||
s.write("---start\n")
|
s.write("---start\n")
|
||||||
s.write(str)
|
s.write(str)
|
||||||
s.write("---end\n")
|
s.write("---end\n")
|
||||||
s.close
|
s.close
|
||||||
STDERR.print "socket #{myname} processed, thread ", Thread.current, " terminating\n"
|
STDERR.print "socket #{myname} processed, thread ", Thread.current, " terminating\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
function fib(n) {
|
function fib(n) {
|
||||||
if ( n<2 ) return n; else return fib(n-2) + fib(n-1)
|
if ( n<2 ) return n; else return fib(n-2) + fib(n-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN { print fib(20); }
|
BEGIN { print fib(20); }
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
sub fib {
|
sub fib {
|
||||||
my($n)=@_;
|
my($n)=@_;
|
||||||
if ($n<2) {
|
if ($n<2) {
|
||||||
return $n;
|
return $n;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return fib($n-2)+fib($n-1);
|
return fib($n-2)+fib($n-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(define (fib n)
|
(define (fib n)
|
||||||
(if (< n 2)
|
(if (< n 2)
|
||||||
n
|
n
|
||||||
(+ (fib (- n 2)) (fib (- n 1)))))
|
(+ (fib (- n 2)) (fib (- n 1)))))
|
||||||
|
|
||||||
(display (fib 20))
|
(display (fib 20))
|
||||||
(newline)
|
(newline)
|
||||||
|
|
|
@ -43,8 +43,8 @@ def get_mailfile(user)
|
||||||
[ENV['SPOOLDIR'], '/usr/spool', '/var/spool', '/usr', '/var'].each do |m|
|
[ENV['SPOOLDIR'], '/usr/spool', '/var/spool', '/usr', '/var'].each do |m|
|
||||||
path = "#{m}/mail/#{user}"
|
path = "#{m}/mail/#{user}"
|
||||||
if File.exist?(path)
|
if File.exist?(path)
|
||||||
file = path
|
file = path
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -64,23 +64,23 @@ def from_main
|
||||||
mtime = File.mtime(file)
|
mtime = File.mtime(file)
|
||||||
open(file, "r") do |f|
|
open(file, "r") do |f|
|
||||||
until f.eof?
|
until f.eof?
|
||||||
header = {}
|
header = {}
|
||||||
f.each_line do |line|
|
f.each_line do |line|
|
||||||
next if /^From / =~ line # skip From-line
|
next if /^From / =~ line # skip From-line
|
||||||
break if /^$/ =~ line # end of header
|
break if /^$/ =~ line # end of header
|
||||||
|
|
||||||
if /^(?<attr>\S+?):\s*(?<value>.*)/ =~ line
|
if /^(?<attr>\S+?):\s*(?<value>.*)/ =~ line
|
||||||
attr.capitalize!
|
attr.capitalize!
|
||||||
header[attr] = value
|
header[attr] = value
|
||||||
elsif attr
|
elsif attr
|
||||||
header[attr] += "\n" + line.lstrip
|
header[attr] += "\n" + line.lstrip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
f.each_line do |line|
|
f.each_line do |line|
|
||||||
break if /^From / =~ line
|
break if /^From / =~ line
|
||||||
end
|
end
|
||||||
outcount += fromout(header['Date'], header['From'], header['Subject'])
|
outcount += fromout(header['Date'], header['From'], header['Subject'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
File.utime(atime, mtime, file)
|
File.utime(atime, mtime, file)
|
||||||
|
|
|
@ -7,18 +7,18 @@ while line = gets()
|
||||||
for arg in $4.split(/;\n\s*/)
|
for arg in $4.split(/;\n\s*/)
|
||||||
arg.gsub!(/ +/, ' ')
|
arg.gsub!(/ +/, ' ')
|
||||||
if arg =~ /,/
|
if arg =~ /,/
|
||||||
if arg =~ /(([^*]+) *\** *\w+),/
|
if arg =~ /(([^*]+) *\** *\w+),/
|
||||||
type = $2.strip
|
type = $2.strip
|
||||||
args.push $1.strip
|
args.push $1.strip
|
||||||
arg = $'
|
arg = $'
|
||||||
else
|
else
|
||||||
type = ""
|
type = ""
|
||||||
end
|
end
|
||||||
while arg.sub!(/(\** *\w+)(,|$)/, "") && $~
|
while arg.sub!(/(\** *\w+)(,|$)/, "") && $~
|
||||||
args.push type + " " + $1.strip
|
args.push type + " " + $1.strip
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
args.push arg.strip
|
args.push arg.strip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
printf "%s);\n", args.join(', ')
|
printf "%s);\n", args.join(', ')
|
||||||
|
|
|
@ -8,10 +8,10 @@ class Tick
|
||||||
def initialize
|
def initialize
|
||||||
Thread.start do
|
Thread.start do
|
||||||
loop do
|
loop do
|
||||||
sleep 0.999
|
sleep 0.999
|
||||||
now = Time.now
|
now = Time.now
|
||||||
changed
|
changed
|
||||||
notify_observers(now.hour, now.min, now.sec)
|
notify_observers(now.hour, now.min, now.sec)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
while (<>) {
|
while (<>) {
|
||||||
for (split(/\W+/)) {
|
for (split(/\W+/)) {
|
||||||
$freq{$_}++;
|
$freq{$_}++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (sort keys %freq) {
|
for (sort keys %freq) {
|
||||||
print "$_ -- $freq{$_}\n";
|
print "$_ -- $freq{$_}\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,13 +54,13 @@ class CHashDir
|
||||||
OpenSSL::X509::Certificate.new(str)
|
OpenSSL::X509::Certificate.new(str)
|
||||||
rescue
|
rescue
|
||||||
begin
|
begin
|
||||||
OpenSSL::X509::CRL.new(str)
|
OpenSSL::X509::CRL.new(str)
|
||||||
rescue
|
rescue
|
||||||
begin
|
begin
|
||||||
OpenSSL::X509::Request.new(str)
|
OpenSSL::X509::Request.new(str)
|
||||||
rescue
|
rescue
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -75,15 +75,15 @@ private
|
||||||
Dir.chdir(@dirpath) do
|
Dir.chdir(@dirpath) do
|
||||||
delete_symlink
|
delete_symlink
|
||||||
Dir.glob('*.pem') do |pemfile|
|
Dir.glob('*.pem') do |pemfile|
|
||||||
cert = load_pem_file(pemfile)
|
cert = load_pem_file(pemfile)
|
||||||
case cert
|
case cert
|
||||||
when OpenSSL::X509::Certificate
|
when OpenSSL::X509::Certificate
|
||||||
link_hash_cert(pemfile, cert)
|
link_hash_cert(pemfile, cert)
|
||||||
when OpenSSL::X509::CRL
|
when OpenSSL::X509::CRL
|
||||||
link_hash_crl(pemfile, cert)
|
link_hash_crl(pemfile, cert)
|
||||||
else
|
else
|
||||||
STDERR.puts("WARNING: #{pemfile} does not contain a certificate or CRL: skipping") unless @silent
|
STDERR.puts("WARNING: #{pemfile} does not contain a certificate or CRL: skipping") unless @silent
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -103,7 +103,7 @@ private
|
||||||
}
|
}
|
||||||
unless filepath
|
unless filepath
|
||||||
unless @silent
|
unless @silent
|
||||||
STDERR.puts("WARNING: Skipping duplicate certificate #{org_filename}")
|
STDERR.puts("WARNING: Skipping duplicate certificate #{org_filename}")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
(@cert_cache[name_hash] ||= []) << path(filepath)
|
(@cert_cache[name_hash] ||= []) << path(filepath)
|
||||||
|
@ -118,7 +118,7 @@ private
|
||||||
}
|
}
|
||||||
unless filepath
|
unless filepath
|
||||||
unless @silent
|
unless @silent
|
||||||
STDERR.puts("WARNING: Skipping duplicate CRL #{org_filename}")
|
STDERR.puts("WARNING: Skipping duplicate CRL #{org_filename}")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
(@crl_cache[name_hash] ||= []) << path(filepath)
|
(@crl_cache[name_hash] ||= []) << path(filepath)
|
||||||
|
@ -132,7 +132,7 @@ private
|
||||||
filepath = yield(idx)
|
filepath = yield(idx)
|
||||||
break unless FileTest.symlink?(filepath) or FileTest.exist?(filepath)
|
break unless FileTest.symlink?(filepath) or FileTest.exist?(filepath)
|
||||||
if @fingerprint_cache[filepath] == fingerprint
|
if @fingerprint_cache[filepath] == fingerprint
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
idx += 1
|
idx += 1
|
||||||
end
|
end
|
||||||
|
@ -147,7 +147,7 @@ private
|
||||||
File.symlink(from, to)
|
File.symlink(from, to)
|
||||||
rescue
|
rescue
|
||||||
File.open(to, "w") do |f|
|
File.open(to, "w") do |f|
|
||||||
f << File.read(from)
|
f << File.read(from)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,27 +76,27 @@ private
|
||||||
result = @x509store.verify(cert) do |ok, ctx|
|
result = @x509store.verify(cert) do |ok, ctx|
|
||||||
cert = ctx.current_cert
|
cert = ctx.current_cert
|
||||||
if ctx.current_crl
|
if ctx.current_crl
|
||||||
crl_map[cert.subject] = true
|
crl_map[cert.subject] = true
|
||||||
end
|
end
|
||||||
if ok
|
if ok
|
||||||
if !ctx.current_crl
|
if !ctx.current_crl
|
||||||
if crl = @crl_store.find_crl(cert)
|
if crl = @crl_store.find_crl(cert)
|
||||||
crl_map[cert.subject] = true
|
crl_map[cert.subject] = true
|
||||||
if crl.revoked.find { |revoked| revoked.serial == cert.serial }
|
if crl.revoked.find { |revoked| revoked.serial == cert.serial }
|
||||||
ok = false
|
ok = false
|
||||||
error_string = 'certification revoked'
|
error_string = 'certification revoked'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
error_map[cert.subject] = error_string if error_string
|
error_map[cert.subject] = error_string if error_string
|
||||||
ok
|
ok
|
||||||
end
|
end
|
||||||
error = if result
|
error = if result
|
||||||
nil
|
nil
|
||||||
else
|
else
|
||||||
error_map[cert.subject] || @x509store.error_string
|
error_map[cert.subject] || @x509store.error_string
|
||||||
end
|
end
|
||||||
return error, crl_map
|
return error, crl_map
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -105,13 +105,13 @@ private
|
||||||
cert = generate_cert(certfile)
|
cert = generate_cert(certfile)
|
||||||
case guess_cert_type(cert)
|
case guess_cert_type(cert)
|
||||||
when CERT_TYPE_SELF_SIGNED
|
when CERT_TYPE_SELF_SIGNED
|
||||||
@self_signed_ca << cert
|
@self_signed_ca << cert
|
||||||
when CERT_TYPE_OTHER
|
when CERT_TYPE_OTHER
|
||||||
@other_ca << cert
|
@other_ca << cert
|
||||||
when CERT_TYPE_EE
|
when CERT_TYPE_EE
|
||||||
@ee << cert
|
@ee << cert
|
||||||
else
|
else
|
||||||
raise "Unknown cert type."
|
raise "Unknown cert type."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@c_store.get_crls.each do |crlfile|
|
@c_store.get_crls.each do |crlfile|
|
||||||
|
@ -128,21 +128,21 @@ private
|
||||||
# Ignores criticality of extensions. It's 'guess'ing.
|
# Ignores criticality of extensions. It's 'guess'ing.
|
||||||
case ext.oid
|
case ext.oid
|
||||||
when 'basicConstraints'
|
when 'basicConstraints'
|
||||||
/CA:(TRUE|FALSE), pathlen:(\d+)/ =~ ext.value
|
/CA:(TRUE|FALSE), pathlen:(\d+)/ =~ ext.value
|
||||||
ca = ($1 == 'TRUE') unless ca
|
ca = ($1 == 'TRUE') unless ca
|
||||||
when 'keyUsage'
|
when 'keyUsage'
|
||||||
usage = ext.value.split(/\s*,\s*/)
|
usage = ext.value.split(/\s*,\s*/)
|
||||||
ca = usage.include?('Certificate Sign') unless ca
|
ca = usage.include?('Certificate Sign') unless ca
|
||||||
when 'nsCertType'
|
when 'nsCertType'
|
||||||
usage = ext.value.split(/\s*,\s*/)
|
usage = ext.value.split(/\s*,\s*/)
|
||||||
ca = usage.include?('SSL CA') unless ca
|
ca = usage.include?('SSL CA') unless ca
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if ca
|
if ca
|
||||||
if self_signed
|
if self_signed
|
||||||
CERT_TYPE_SELF_SIGNED
|
CERT_TYPE_SELF_SIGNED
|
||||||
else
|
else
|
||||||
CERT_TYPE_OTHER
|
CERT_TYPE_OTHER
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
CERT_TYPE_EE
|
CERT_TYPE_EE
|
||||||
|
|
|
@ -24,22 +24,22 @@ private
|
||||||
end
|
end
|
||||||
unless crlfiles = @c_store.get_crls(ca.subject)
|
unless crlfiles = @c_store.get_crls(ca.subject)
|
||||||
if crl = renew_crl(cert, ca)
|
if crl = renew_crl(cert, ca)
|
||||||
@c_store.add_crl(crl)
|
@c_store.add_crl(crl)
|
||||||
return crl
|
return crl
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
crlfiles.each do |crlfile|
|
crlfiles.each do |crlfile|
|
||||||
next unless crl = load_crl(crlfile)
|
next unless crl = load_crl(crlfile)
|
||||||
if crl.next_update < Time.now
|
if crl.next_update < Time.now
|
||||||
if new_crl = renew_crl(cert, ca)
|
if new_crl = renew_crl(cert, ca)
|
||||||
@c_store.delete_crl(crl)
|
@c_store.delete_crl(crl)
|
||||||
@c_store.add_crl(new_crl)
|
@c_store.add_crl(new_crl)
|
||||||
crl = new_crl
|
crl = new_crl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if check_valid(crl, ca)
|
if check_valid(crl, ca)
|
||||||
return crl
|
return crl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
nil
|
nil
|
||||||
|
@ -49,7 +49,7 @@ private
|
||||||
@c_store.get_certs(cert.issuer).each do |cafile|
|
@c_store.get_certs(cert.issuer).each do |cafile|
|
||||||
ca = load_cert(cafile)
|
ca = load_cert(cafile)
|
||||||
if cert.verify(ca.public_key)
|
if cert.verify(ca.public_key)
|
||||||
return ca
|
return ca
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
nil
|
nil
|
||||||
|
@ -58,10 +58,10 @@ private
|
||||||
def fetch(location)
|
def fetch(location)
|
||||||
if /\AURI:(.*)\z/ =~ location
|
if /\AURI:(.*)\z/ =~ location
|
||||||
begin
|
begin
|
||||||
c = HTTPAccess2::Client.new(ENV['http_proxy'] || ENV['HTTP_PROXY'])
|
c = HTTPAccess2::Client.new(ENV['http_proxy'] || ENV['HTTP_PROXY'])
|
||||||
c.get_content($1)
|
c.get_content($1)
|
||||||
rescue NameError, StandardError
|
rescue NameError, StandardError
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
|
@ -103,10 +103,10 @@ private
|
||||||
def renew_crl(cert, ca)
|
def renew_crl(cert, ca)
|
||||||
if cdp = get_cdp(cert)
|
if cdp = get_cdp(cert)
|
||||||
if new_crl_str = fetch(cdp)
|
if new_crl_str = fetch(cdp)
|
||||||
new_crl = load_crl_str(new_crl_str)
|
new_crl = load_crl_str(new_crl_str)
|
||||||
if check_valid(new_crl, ca)
|
if check_valid(new_crl, ca)
|
||||||
return new_crl
|
return new_crl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
false
|
false
|
||||||
|
|
|
@ -22,13 +22,13 @@ ARGV.options do
|
||||||
|
|
||||||
# mandatory argument
|
# mandatory argument
|
||||||
opts.on("-r", "--require=LIBRARY", String,
|
opts.on("-r", "--require=LIBRARY", String,
|
||||||
"require the LIBRARY, before",
|
"require the LIBRARY, before",
|
||||||
"executing your script") {|lib|@library=lib}
|
"executing your script") {|lib|@library=lib}
|
||||||
|
|
||||||
# optional argument
|
# optional argument
|
||||||
opts.on("-i", "--inplace=[EXTENSION]",
|
opts.on("-i", "--inplace=[EXTENSION]",
|
||||||
"edit ARGV files in place", # multiline description
|
"edit ARGV files in place", # multiline description
|
||||||
"(make backup if EXTENSION supplied)") {|inplace| @inplace = inplace || ''}
|
"(make backup if EXTENSION supplied)") {|inplace| @inplace = inplace || ''}
|
||||||
|
|
||||||
opts.on("-N=[NUM]", Integer) {|num|@number=num}
|
opts.on("-N=[NUM]", Integer) {|num|@number=num}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ ARGV.options do
|
||||||
|
|
||||||
# limit argument syntax
|
# limit argument syntax
|
||||||
opts.on("-[0-7]", "-F", "--irs=[OCTAL]", OptionParser::OctalInteger,
|
opts.on("-[0-7]", "-F", "--irs=[OCTAL]", OptionParser::OctalInteger,
|
||||||
"specify record separator", "(\\0, if no argument)") {|irs|@irs=irs}
|
"specify record separator", "(\\0, if no argument)") {|irs|@irs=irs}
|
||||||
|
|
||||||
# boolean switch(default true)
|
# boolean switch(default true)
|
||||||
@exec = true
|
@exec = true
|
||||||
|
@ -51,7 +51,7 @@ ARGV.options do
|
||||||
|
|
||||||
# keyword completion
|
# keyword completion
|
||||||
opts.on("--code=CODE", CODES, CODE_ALIASES, "select coding system",
|
opts.on("--code=CODE", CODES, CODE_ALIASES, "select coding system",
|
||||||
"("+CODES.join(",")+",", " "+CODE_ALIASES.keys.join(",")+")") {|c|@code=c}
|
"("+CODES.join(",")+",", " "+CODE_ALIASES.keys.join(",")+")") {|c|@code=c}
|
||||||
|
|
||||||
# optional argument with keyword completion
|
# optional argument with keyword completion
|
||||||
opts.on("--type[=TYPE]", [:text, :binary], "select type(text, binary)") {|t|@type=t}
|
opts.on("--type[=TYPE]", [:text, :binary], "select type(text, binary)") {|t|@type=t}
|
||||||
|
|
|
@ -1,33 +1,33 @@
|
||||||
BEGIN {
|
BEGIN {
|
||||||
sw = 40.0;
|
sw = 40.0;
|
||||||
dw = 78.0;
|
dw = 78.0;
|
||||||
hdw = dw / 2.0;
|
hdw = dw / 2.0;
|
||||||
w = 20.0;
|
w = 20.0;
|
||||||
h =1.0;
|
h =1.0;
|
||||||
d = 0.2;
|
d = 0.2;
|
||||||
ss="abcdefghijklmnopqrstuvwxyz0123456789!#$%^&*()-=\\[];'`,./";
|
ss="abcdefghijklmnopqrstuvwxyz0123456789!#$%^&*()-=\\[];'`,./";
|
||||||
rnd = srand();
|
rnd = srand();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
xr = -hdw; y = h * 1.0; maxxl = -999;
|
xr = -hdw; y = h * 1.0; maxxl = -999;
|
||||||
s = "";
|
s = "";
|
||||||
while (xr < hdw) {
|
while (xr < hdw) {
|
||||||
x = xr * (1 + y) - y * w / 2;
|
x = xr * (1 + y) - y * w / 2;
|
||||||
i = (x / (1 + h) + sw /2);
|
i = (x / (1 + h) + sw /2);
|
||||||
c = (0 < i && i < length($0)) ? substr($0, i, 1) : "0";
|
c = (0 < i && i < length($0)) ? substr($0, i, 1) : "0";
|
||||||
y = h - d * c;
|
y = h - d * c;
|
||||||
xl = xr - w * y / (1 + y);
|
xl = xr - w * y / (1 + y);
|
||||||
if (xl < -hdw || xl >= hdw || xl <= maxxl) {
|
if (xl < -hdw || xl >= hdw || xl <= maxxl) {
|
||||||
t = rand() * length(ss);
|
t = rand() * length(ss);
|
||||||
c = substr(ss, t, 1);
|
c = substr(ss, t, 1);
|
||||||
}
|
|
||||||
else {
|
|
||||||
c = substr(s, xl + hdw, 1);
|
|
||||||
maxxl = xl;
|
|
||||||
}
|
|
||||||
s = s c;
|
|
||||||
xr = xr + 1;
|
|
||||||
}
|
}
|
||||||
print s;
|
else {
|
||||||
|
c = substr(s, xl + hdw, 1);
|
||||||
|
maxxl = xl;
|
||||||
|
}
|
||||||
|
s = s c;
|
||||||
|
xr = xr + 1;
|
||||||
|
}
|
||||||
|
print s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ for dir in path
|
||||||
for f in d = Dir.open(dir)
|
for f in d = Dir.open(dir)
|
||||||
fpath = File.join(dir, f)
|
fpath = File.join(dir, f)
|
||||||
if File.file?(fpath) && (File.stat(fpath).mode & 022) != 0
|
if File.file?(fpath) && (File.stat(fpath).mode & 022) != 0
|
||||||
printf("file %s is writable from other users\n", fpath)
|
printf("file %s is writable from other users\n", fpath)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
d.close
|
d.close
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue