summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
Diffstat (limited to 'sample')
-rw-r--r--sample/README2
-rw-r--r--sample/biorhythm.rb9
-rw-r--r--sample/cbreak.rb2
-rw-r--r--sample/dir.rb2
-rw-r--r--sample/drb/README.ja.rdoc2
-rw-r--r--sample/drb/README.rdoc2
-rw-r--r--sample/drb/dchats.rb3
-rw-r--r--sample/drb/dhasen.rb1
-rw-r--r--sample/drb/dlogd.rb1
-rw-r--r--sample/drb/dqueue.rb1
-rw-r--r--sample/drb/http0serv.rb9
-rw-r--r--sample/drb/name.rb4
-rw-r--r--sample/drb/old_tuplespace.rb4
-rw-r--r--sample/drb/ring_echo.rb1
-rw-r--r--sample/drb/simpletuple.rb2
-rw-r--r--sample/dualstack-httpd.rb1
-rw-r--r--sample/exyacc.rb2
-rw-r--r--sample/fact.rb4
-rw-r--r--sample/fib.py2
-rw-r--r--sample/freq.rb12
-rw-r--r--sample/iseq_loader.rb6
-rw-r--r--sample/list.rb5
-rw-r--r--sample/list3.rb2
-rw-r--r--sample/observ.rb3
-rw-r--r--sample/occur.rb2
-rw-r--r--sample/occur2.rb13
-rw-r--r--sample/openssl/c_rehash.rb3
-rw-r--r--sample/openssl/cert2text.rb7
-rw-r--r--sample/openssl/certstore.rb7
-rw-r--r--sample/openssl/echo_cli.rb2
-rw-r--r--sample/openssl/echo_svr.rb8
-rw-r--r--sample/openssl/gen_csr.rb14
-rw-r--r--sample/openssl/smime_read.rb11
-rw-r--r--sample/openssl/smime_write.rb15
-rw-r--r--sample/philos.rb1
-rw-r--r--sample/pty/expect_sample.rb14
-rw-r--r--sample/pty/script.rb2
-rw-r--r--sample/ripper/ruby2html.rb6
-rwxr-xr-xsample/rss/blend.rb79
-rwxr-xr-xsample/rss/convert.rb69
-rwxr-xr-xsample/rss/list_description.rb91
-rwxr-xr-xsample/rss/re_read.rb64
-rwxr-xr-xsample/rss/rss_recent.rb85
-rw-r--r--[-rwxr-xr-x]sample/test.rb0
-rw-r--r--sample/testunit/adder.rb13
-rw-r--r--sample/testunit/subtracter.rb12
-rw-r--r--sample/testunit/tc_adder.rb18
-rw-r--r--sample/testunit/tc_subtracter.rb18
-rw-r--r--sample/testunit/ts_examples.rb7
-rw-r--r--sample/timeout.rb18
-rw-r--r--sample/trick2013/kinaba/remarks.markdown4
-rw-r--r--sample/trick2013/mame/music-box.mp4bin580724 -> 0 bytes
-rw-r--r--sample/trick2013/mame/remarks.markdown4
-rw-r--r--sample/trick2013/yhara/entry.rb2
-rw-r--r--sample/trick2015/kinaba/entry.rb2
-rw-r--r--sample/trick2015/ksk_1/remarks.markdown2
-rw-r--r--sample/trick2015/ksk_2/remarks.markdown4
-rw-r--r--sample/trick2018/01-kinaba/authors.markdown3
-rw-r--r--sample/trick2018/01-kinaba/entry.rb8
-rw-r--r--sample/trick2018/01-kinaba/remarks.markdown55
-rw-r--r--sample/trick2018/02-mame/authors.markdown3
-rw-r--r--sample/trick2018/02-mame/entry.rb15
-rw-r--r--sample/trick2018/02-mame/remarks.markdown16
-rw-r--r--sample/trick2018/03-tompng/Gemfile2
-rw-r--r--sample/trick2018/03-tompng/Gemfile.lock13
-rw-r--r--sample/trick2018/03-tompng/authors.markdown3
-rw-r--r--sample/trick2018/03-tompng/entry.rb31
-rw-r--r--sample/trick2018/03-tompng/output.txt44
-rw-r--r--sample/trick2018/03-tompng/remarks.markdown19
-rw-r--r--sample/trick2018/03-tompng/trick.pngbin0 -> 5661 bytes
-rw-r--r--sample/trick2018/04-colin/authors.markdown3
-rw-r--r--sample/trick2018/04-colin/entry.rb2
-rw-r--r--sample/trick2018/04-colin/remarks.markdown62
-rw-r--r--sample/trick2018/05-tompng/authors.markdown3
-rw-r--r--sample/trick2018/05-tompng/entry.rb41
-rw-r--r--sample/trick2018/05-tompng/preview_of_output.pngbin0 -> 66800 bytes
-rw-r--r--sample/trick2018/05-tompng/remarks.markdown31
-rw-r--r--sample/trick2018/README.md16
-rw-r--r--sample/webrick/demo-app.rb66
-rw-r--r--sample/webrick/demo-multipart.cgi12
-rw-r--r--sample/webrick/demo-servlet.rb6
-rw-r--r--sample/webrick/demo-urlencoded.cgi12
-rw-r--r--sample/webrick/hello.cgi11
-rw-r--r--sample/webrick/hello.rb8
-rw-r--r--sample/webrick/httpd.rb23
-rw-r--r--sample/webrick/httpproxy.rb25
-rw-r--r--sample/webrick/httpsd.rb33
87 files changed, 468 insertions, 777 deletions
diff --git a/sample/README b/sample/README
index 796aba1dc3..b55234a947 100644
--- a/sample/README
+++ b/sample/README
@@ -16,7 +16,6 @@ fib.pl Fibonacci number (Perl)
fib.py Fibonacci number (Python)
fib.rb Fibonacci number (Ruby)
fib.scm Fibonacci number (Scheme)
-freq.rb count word occurrence
from.rb scan mail spool
fullpath.rb convert ls -lR to fullpath format
less.rb front end for less
@@ -29,7 +28,6 @@ mpart.rb split file int multi part
observ.rb observer design pattern sample
occur.pl count word occurrence (Perl)
occur.rb count word occurrence (Ruby)
-occur2.rb count word occurrence - another style
philos.rb famous dining philosophers
pi.rb calculate PI
rcs.awk random character stereogram (AWK)
diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb
index bd7c39f5aa..f5d189014b 100644
--- a/sample/biorhythm.rb
+++ b/sample/biorhythm.rb
@@ -25,7 +25,7 @@
# Environment: basic, dos, os9
include Math
-require "date.rb"
+require "date"
require "optparse"
require "optparse/date"
@@ -36,11 +36,10 @@ def print_header(y, m, d, p, w)
end
def get_position(z)
- pi = Math::PI
z = Integer(z)
- phys = (50.0 * (1.0 + sin((z / 23.0 - (z / 23)) * 360.0 * pi / 180.0))).to_i
- emot = (50.0 * (1.0 + sin((z / 28.0 - (z / 28)) * 360.0 * pi / 180.0))).to_i
- geist =(50.0 * (1.0 + sin((z / 33.0 - (z / 33)) * 360.0 * pi / 180.0))).to_i
+ phys = (50.0 * (1.0 + sin((z / 23.0 - (z / 23)) * 360.0 * PI / 180.0))).to_i
+ emot = (50.0 * (1.0 + sin((z / 28.0 - (z / 28)) * 360.0 * PI / 180.0))).to_i
+ geist =(50.0 * (1.0 + sin((z / 33.0 - (z / 33)) * 360.0 * PI / 180.0))).to_i
return phys, emot, geist
end
diff --git a/sample/cbreak.rb b/sample/cbreak.rb
index c2246846b6..7f1385cce3 100644
--- a/sample/cbreak.rb
+++ b/sample/cbreak.rb
@@ -30,7 +30,7 @@ end
cbreak();
print("this is no-echo line: ");
-readline().print
+readline().display
cooked();
print("this is echo line: ");
readline()
diff --git a/sample/dir.rb b/sample/dir.rb
index b627383946..0c55078973 100644
--- a/sample/dir.rb
+++ b/sample/dir.rb
@@ -3,7 +3,7 @@
dirp = Dir.open(".")
for f in dirp
case f
- when /^\./, /~$/, /\.o/
+ when /\A\./, /~\z/, /\.o\z/
# do not print
else
print f, "\n"
diff --git a/sample/drb/README.ja.rdoc b/sample/drb/README.ja.rdoc
index 3ab70f3369..1697b1b704 100644
--- a/sample/drb/README.ja.rdoc
+++ b/sample/drb/README.ja.rdoc
@@ -50,7 +50,7 @@
* drbssl_s.rb
* drbssl_c.rb
-* DRbProtoclの追加例
+* DRbProtocolの追加例
* http0.rb
* http0serv.rb
diff --git a/sample/drb/README.rdoc b/sample/drb/README.rdoc
index 80ae910a8a..fcb4182410 100644
--- a/sample/drb/README.rdoc
+++ b/sample/drb/README.rdoc
@@ -47,7 +47,7 @@
* drbssl_s.rb
* drbssl_c.rb
-* add DRbProtocl
+* add DRbProtocol
* http0.rb
* http0serv.rb
diff --git a/sample/drb/dchats.rb b/sample/drb/dchats.rb
index c07f748e99..c96486a452 100644
--- a/sample/drb/dchats.rb
+++ b/sample/drb/dchats.rb
@@ -2,7 +2,6 @@
distributed Ruby --- chat server
Copyright (c) 1999-2000 Masatoshi SEKI
=end
-require 'thread'
require 'drb/drb'
class ChatEntry
@@ -29,7 +28,7 @@ end
class ChatServer
def initialize
- @mutex = Mutex.new
+ @mutex = Thread::Mutex.new
@members = {}
end
diff --git a/sample/drb/dhasen.rb b/sample/drb/dhasen.rb
index 9ab8534588..13ff38940e 100644
--- a/sample/drb/dhasen.rb
+++ b/sample/drb/dhasen.rb
@@ -17,7 +17,6 @@
require 'drb/drb'
require 'chasen'
-require 'thread'
class Dhasen
include DRbUndumped
diff --git a/sample/drb/dlogd.rb b/sample/drb/dlogd.rb
index be364511dc..a87e660346 100644
--- a/sample/drb/dlogd.rb
+++ b/sample/drb/dlogd.rb
@@ -4,7 +4,6 @@
=end
require 'drb/drb'
-require 'thread'
class Logger
def initialize(fname)
diff --git a/sample/drb/dqueue.rb b/sample/drb/dqueue.rb
index 1a405f5be5..a9afa8c858 100644
--- a/sample/drb/dqueue.rb
+++ b/sample/drb/dqueue.rb
@@ -3,7 +3,6 @@
Copyright (c) 1999-2000 Masatoshi SEKI
=end
-require 'thread'
require 'drb/drb'
DRb.start_service(nil, Thread::Queue.new)
diff --git a/sample/drb/http0serv.rb b/sample/drb/http0serv.rb
index 049f5a1de5..2e853312e1 100644
--- a/sample/drb/http0serv.rb
+++ b/sample/drb/http0serv.rb
@@ -1,7 +1,6 @@
require 'webrick'
require 'drb/drb'
-require 'drb/http0'
-require 'thread'
+require_relative 'http0'
module DRb
module HTTP0
@@ -62,7 +61,7 @@ module DRb
def accept
client = @queue.pop
- ServerSide.new(client, @config)
+ ServerSide.new(uri, client, @config)
end
def setup_webrick(uri)
@@ -80,12 +79,14 @@ module DRb
end
class ServerSide
- def initialize(callback, config)
+ def initialize(uri, callback, config)
+ @uri = uri
@callback = callback
@config = config
@msg = DRbMessage.new(@config)
@req_stream = StrStream.new(@callback.req_body)
end
+ attr_reader :uri
def close
@callback.close if @callback
diff --git a/sample/drb/name.rb b/sample/drb/name.rb
index 30c902b8f7..6d88186dab 100644
--- a/sample/drb/name.rb
+++ b/sample/drb/name.rb
@@ -35,16 +35,16 @@ How to play.
| 2
=end
-require 'thread.rb'
require 'drb/drb'
module DRbNamedObject
DRbNAMEDICT = {}
+ DRBNAMEMUTEX = Thread::Mutex.new
attr_reader(:drb_name)
def drb_name=(name)
@drb_name = name
- Thread.exclusive do
+ DRBNAMEMUTEX.synchronize do
raise(IndexError, name) if DRbNAMEDICT[name]
DRbNAMEDICT[name] = self
end
diff --git a/sample/drb/old_tuplespace.rb b/sample/drb/old_tuplespace.rb
index 9c10a34527..2d5310086e 100644
--- a/sample/drb/old_tuplespace.rb
+++ b/sample/drb/old_tuplespace.rb
@@ -3,8 +3,6 @@
# Copyright (c) 1999-2000 Masatoshi SEKI
# You can redistribute it and/or modify it under the same terms as Ruby.
-require 'thread'
-
class TupleSpace
class Template
def initialize(list)
@@ -33,7 +31,7 @@ class TupleSpace
def initialize
@que = {}
@waiting = {}
- @que.taint # enable tainted comunication
+ @que.taint # enable tainted communication
@waiting.taint
self.taint
end
diff --git a/sample/drb/ring_echo.rb b/sample/drb/ring_echo.rb
index 3b743cab8e..c54628b54c 100644
--- a/sample/drb/ring_echo.rb
+++ b/sample/drb/ring_echo.rb
@@ -1,7 +1,6 @@
require 'drb/drb'
require 'drb/eq'
require 'rinda/ring'
-require 'thread'
class RingEcho
include DRbUndumped
diff --git a/sample/drb/simpletuple.rb b/sample/drb/simpletuple.rb
index bfbd86e665..4bb4b1cff9 100644
--- a/sample/drb/simpletuple.rb
+++ b/sample/drb/simpletuple.rb
@@ -3,8 +3,6 @@
# Copyright (c) 1999-2000 Masatoshi SEKI
# You can redistribute it and/or modify it under the same terms as Ruby.
-require 'thread'
-
class SimpleTupleSpace
def initialize
@hash = {}
diff --git a/sample/dualstack-httpd.rb b/sample/dualstack-httpd.rb
index a6d4d3a2c2..ab02e17aea 100644
--- a/sample/dualstack-httpd.rb
+++ b/sample/dualstack-httpd.rb
@@ -3,7 +3,6 @@
# The code demonstrates how a multi-protocol daemon should be written.
require "socket"
-require "thread"
port = 8888
res = Socket.getaddrinfo(nil, port, nil, Socket::SOCK_STREAM, nil, Socket::AI_PASSIVE)
diff --git a/sample/exyacc.rb b/sample/exyacc.rb
index 9a9435a0dc..cbcc18d58b 100644
--- a/sample/exyacc.rb
+++ b/sample/exyacc.rb
@@ -8,7 +8,7 @@ ARGF.each(nil) do |source|
grammar = source[sbeg, send-sbeg]
grammar.sub!(/.*\n/, "")
grammar.gsub!(/'\{'/, "'\001'")
- grammar.gsub!(/'\}'/, "'\002'")
+ grammar.gsub!(/["']\}["']/, "'\002'")
grammar.gsub!(%r{\*/}, "\003\003")
grammar.gsub!(%r{/\*[^\003]*\003\003}, '')
while grammar.gsub!(/\{[^{}]*\}/, ''); end
diff --git a/sample/fact.rb b/sample/fact.rb
index d8147a40f1..9f6ca72ca7 100644
--- a/sample/fact.rb
+++ b/sample/fact.rb
@@ -4,6 +4,6 @@ def fact(n)
n.downto(1) do |i|
f *= i
end
- return f
+ f
end
-print fact(ARGV[0].to_i), "\n"
+puts fact(ARGV[0].to_i)
diff --git a/sample/fib.py b/sample/fib.py
index 8318021d24..90dc1e09ed 100644
--- a/sample/fib.py
+++ b/sample/fib.py
@@ -6,5 +6,5 @@ def fib(n):
else:
return fib(n-2)+fib(n-1)
-print fib(20)
+print(fib(20))
diff --git a/sample/freq.rb b/sample/freq.rb
deleted file mode 100644
index 1b2194c69a..0000000000
--- a/sample/freq.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# word occurrence listing
-# usage: ruby freq.rb file..
-freq = Hash.new(0)
-while line = gets()
- line.scan(/\w+/) do |word|
- freq[word] += 1
- end
-end
-
-for word in freq.keys.sort!
- print word, " -- ", freq[word], "\n"
-end
diff --git a/sample/iseq_loader.rb b/sample/iseq_loader.rb
index bb2d92ea77..8c271405d6 100644
--- a/sample/iseq_loader.rb
+++ b/sample/iseq_loader.rb
@@ -41,7 +41,7 @@ class RubyVM::InstructionSequence
at_exit{
STDERR.puts "[ISEQ_LOADER] #{Process.pid} time: #{Time.now - LAUNCHED_TIME}, " +
"loaded: #{$ISEQ_LOADER_LOADED}, " +
- "compied: #{$ISEQ_LOADER_COMPILED}, " +
+ "compiled: #{$ISEQ_LOADER_COMPILED}, " +
"ignored: #{$ISEQ_LOADER_IGNORED}"
} if COMPILE_VERBOSE
@@ -141,11 +141,11 @@ class RubyVM::InstructionSequence
end
def read_compiled_iseq fname, iseq_key
- open(iseq_key, 'rb'){|f| f.read}
+ File.open(iseq_key, 'rb'){|f| f.read}
end
def write_compiled_iseq fname, iseq_key, binary
- open(iseq_key, 'wb'){|f| f.write(binary)}
+ File.open(iseq_key, 'wb'){|f| f.write(binary)}
end
end
diff --git a/sample/list.rb b/sample/list.rb
index b4d1d653e4..7458ba0244 100644
--- a/sample/list.rb
+++ b/sample/list.rb
@@ -5,7 +5,6 @@ class MyElem
# @variables are instance variable, no declaration needed
@data = item
@succ = nil
- @head = nil
end
def data
@@ -23,6 +22,10 @@ class MyElem
end
class MyList
+ def initialize
+ @head = nil
+ end
+
def add_to_list(obj)
elt = MyElem.new(obj)
if @head
diff --git a/sample/list3.rb b/sample/list3.rb
index 1d9f04b710..110e405cf9 100644
--- a/sample/list3.rb
+++ b/sample/list3.rb
@@ -7,7 +7,7 @@ class Point
self
end
- def to_s
+ def inspect
sprintf("%d@%d", @x, @y)
end
end
diff --git a/sample/observ.rb b/sample/observ.rb
index 061e3c6a10..ef4a9f60f5 100644
--- a/sample/observ.rb
+++ b/sample/observ.rb
@@ -1,6 +1,5 @@
#! /usr/local/bin/ruby
-require "thread"
require "observer"
class Tick
@@ -28,5 +27,5 @@ class Clock
end
end
-clock = Clock.new(Tick.new)
+Clock.new(Tick.new)
sleep
diff --git a/sample/occur.rb b/sample/occur.rb
index 42151d85e8..5927ebc889 100644
--- a/sample/occur.rb
+++ b/sample/occur.rb
@@ -2,7 +2,7 @@
# usage: ruby occur.rb file..
freq = Hash.new(0)
while line = gets()
- for word in line.split(/\W+/)
+ line.scan(/\w+/) do |word|
freq[word] += 1
end
end
diff --git a/sample/occur2.rb b/sample/occur2.rb
deleted file mode 100644
index ef8ad2c541..0000000000
--- a/sample/occur2.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# word occurrence listing
-# usage: ruby occur2.rb file..
-freq = {}
-ARGF.each_line do |line|
- for word in line.split(/\W+/)
- freq[word] ||= 0
- freq[word] += 1
- end
-end
-
-for word in freq.keys.sort
- printf("%s -- %d\n", word, freq[word])
-end
diff --git a/sample/openssl/c_rehash.rb b/sample/openssl/c_rehash.rb
index cd6c9d5fd4..de4b66e902 100644
--- a/sample/openssl/c_rehash.rb
+++ b/sample/openssl/c_rehash.rb
@@ -1,7 +1,6 @@
#!/usr/bin/env ruby
require 'openssl'
-require 'digest/md5'
class CHashDir
include Enumerable
@@ -161,7 +160,7 @@ private
end
def fingerprint(der)
- Digest::MD5.hexdigest(der).upcase
+ OpenSSL::Digest.hexdigest('MD5', der).upcase
end
end
diff --git a/sample/openssl/cert2text.rb b/sample/openssl/cert2text.rb
index 50da224e76..fe14e51d3a 100644
--- a/sample/openssl/cert2text.rb
+++ b/sample/openssl/cert2text.rb
@@ -1,10 +1,13 @@
#!/usr/bin/env ruby
require 'openssl'
-include OpenSSL::X509
def cert2text(cert_str)
- [Certificate, CRL, Request].each do |klass|
+ [
+ OpenSSL::X509::Certificate,
+ OpenSSL::X509::CRL,
+ OpenSSL::X509::Request,
+ ].each do |klass|
begin
puts klass.new(cert_str).to_text
return
diff --git a/sample/openssl/certstore.rb b/sample/openssl/certstore.rb
index c6e8f816bc..72e59f6dad 100644
--- a/sample/openssl/certstore.rb
+++ b/sample/openssl/certstore.rb
@@ -3,9 +3,6 @@ require 'crlstore'
class CertStore
- include OpenSSL
- include X509
-
attr_reader :self_signed_ca
attr_reader :other_ca
attr_reader :ee
@@ -17,11 +14,11 @@ class CertStore
@c_store = CHashDir.new(@certs_dir)
@c_store.hash_dir(true)
@crl_store = CrlStore.new(@c_store)
- @x509store = Store.new
+ @x509store = OpenSSL::X509::Store.new
@self_signed_ca = @other_ca = @ee = @crl = nil
# Uncomment this line to let OpenSSL to check CRL for each certs.
- # @x509store.flags = V_FLAG_CRL_CHECK | V_FLAG_CRL_CHECK_ALL
+ # @x509store.flags = OpenSSL::X509::V_FLAG_CRL_CHECK | OpenSSL::X509::V_FLAG_CRL_CHECK_ALL
add_path
scan_certs
diff --git a/sample/openssl/echo_cli.rb b/sample/openssl/echo_cli.rb
index 069a21ec94..3fbadf3361 100644
--- a/sample/openssl/echo_cli.rb
+++ b/sample/openssl/echo_cli.rb
@@ -15,7 +15,7 @@ ca_path = options["C"]
ctx = OpenSSL::SSL::SSLContext.new()
if cert_file && key_file
ctx.cert = OpenSSL::X509::Certificate.new(File::read(cert_file))
- ctx.key = OpenSSL::PKey::RSA.new(File::read(key_file))
+ ctx.key = OpenSSL::PKey.read(File::read(key_file))
end
if ca_path
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
diff --git a/sample/openssl/echo_svr.rb b/sample/openssl/echo_svr.rb
index 719de6be84..f20fb52bf5 100644
--- a/sample/openssl/echo_svr.rb
+++ b/sample/openssl/echo_svr.rb
@@ -13,9 +13,9 @@ ca_path = options["C"]
if cert_file && key_file
cert = OpenSSL::X509::Certificate.new(File::read(cert_file))
- key = OpenSSL::PKey::RSA.new(File::read(key_file))
+ key = OpenSSL::PKey.read(File::read(key_file))
else
- key = OpenSSL::PKey::RSA.new(512){ print "." }
+ key = OpenSSL::PKey::RSA.new(2048){ print "." }
puts
cert = OpenSSL::X509::Certificate.new
cert.version = 2
@@ -25,7 +25,7 @@ else
cert.issuer = name
cert.not_before = Time.now
cert.not_after = Time.now + 3600
- cert.public_key = key.public_key
+ cert.public_key = key
ef = OpenSSL::X509::ExtensionFactory.new(nil,cert)
cert.extensions = [
ef.create_extension("basicConstraints","CA:FALSE"),
@@ -37,7 +37,7 @@ else
ef.issuer_certificate = cert
cert.add_extension ef.create_extension("authorityKeyIdentifier",
"keyid:always,issuer:always")
- cert.sign(key, OpenSSL::Digest::SHA1.new)
+ cert.sign(key, "SHA1")
end
ctx = OpenSSL::SSL::SSLContext.new()
diff --git a/sample/openssl/gen_csr.rb b/sample/openssl/gen_csr.rb
index 4228707fdb..34b23fec1c 100644
--- a/sample/openssl/gen_csr.rb
+++ b/sample/openssl/gen_csr.rb
@@ -3,8 +3,6 @@
require 'optparse'
require 'openssl'
-include OpenSSL
-
def usage
myname = File::basename($0)
$stderr.puts <<EOS
@@ -21,13 +19,13 @@ keyout = options["keyout"] || "keypair.pem"
$stdout.sync = true
name_str = ARGV.shift or usage()
-name = X509::Name.parse(name_str)
+name = OpenSSL::X509::Name.parse(name_str)
keypair = nil
if keypair_file
- keypair = PKey::RSA.new(File.open(keypair_file).read)
+ keypair = OpenSSL::PKey.read(File.read(keypair_file))
else
- keypair = PKey::RSA.new(1024) { putc "." }
+ keypair = OpenSSL::PKey::RSA.new(2048) { putc "." }
puts
puts "Writing #{keyout}..."
File.open(keyout, "w", 0400) do |f|
@@ -37,11 +35,11 @@ end
puts "Generating CSR for #{name_str}"
-req = X509::Request.new
+req = OpenSSL::X509::Request.new
req.version = 0
req.subject = name
-req.public_key = keypair.public_key
-req.sign(keypair, Digest::MD5.new)
+req.public_key = keypair
+req.sign(keypair, "MD5")
puts "Writing #{csrout}..."
File.open(csrout, "w") do |f|
diff --git a/sample/openssl/smime_read.rb b/sample/openssl/smime_read.rb
index 17394f9b8d..b617c6e3a5 100644
--- a/sample/openssl/smime_read.rb
+++ b/sample/openssl/smime_read.rb
@@ -1,6 +1,5 @@
require 'optparse'
require 'openssl'
-include OpenSSL
options = ARGV.getopts("c:k:C:")
@@ -10,14 +9,14 @@ ca_path = options["C"]
data = $stdin.read
-cert = X509::Certificate.new(File::read(cert_file))
-key = PKey::RSA.new(File::read(key_file))
-p7enc = PKCS7::read_smime(data)
+cert = OpenSSL::X509::Certificate.new(File::read(cert_file))
+key = OpenSSL::PKey::read(File::read(key_file))
+p7enc = OpenSSL::PKCS7::read_smime(data)
data = p7enc.decrypt(key, cert)
-store = X509::Store.new
+store = OpenSSL::X509::Store.new
store.add_path(ca_path)
-p7sig = PKCS7::read_smime(data)
+p7sig = OpenSSL::PKCS7::read_smime(data)
if p7sig.verify([], store)
puts p7sig.data
end
diff --git a/sample/openssl/smime_write.rb b/sample/openssl/smime_write.rb
index 5a5236c750..e1254d8748 100644
--- a/sample/openssl/smime_write.rb
+++ b/sample/openssl/smime_write.rb
@@ -1,6 +1,5 @@
require 'openssl'
require 'optparse'
-include OpenSSL
options = ARGV.getopts("c:k:r:")
@@ -8,16 +7,16 @@ cert_file = options["c"]
key_file = options["k"]
rcpt_file = options["r"]
-cert = X509::Certificate.new(File::read(cert_file))
-key = PKey::RSA.new(File::read(key_file))
+cert = OpenSSL::X509::Certificate.new(File::read(cert_file))
+key = OpenSSL::PKey::read(File::read(key_file))
data = "Content-Type: text/plain\r\n"
data << "\r\n"
data << "This is a clear-signed message.\r\n"
-p7sig = PKCS7::sign(cert, key, data, [], PKCS7::DETACHED)
-smime0 = PKCS7::write_smime(p7sig)
+p7sig = OpenSSL::PKCS7::sign(cert, key, data, [], OpenSSL::PKCS7::DETACHED)
+smime0 = OpenSSL::PKCS7::write_smime(p7sig)
-rcpt = X509::Certificate.new(File::read(rcpt_file))
-p7enc = PKCS7::encrypt([rcpt], smime0)
-print PKCS7::write_smime(p7enc)
+rcpt = OpenSSL::X509::Certificate.new(File::read(rcpt_file))
+p7enc = OpenSSL::PKCS7::encrypt([rcpt], smime0)
+print OpenSSL::PKCS7::write_smime(p7enc)
diff --git a/sample/philos.rb b/sample/philos.rb
index 622e58b4bf..c38aa4a1cc 100644
--- a/sample/philos.rb
+++ b/sample/philos.rb
@@ -1,7 +1,6 @@
#
# The Dining Philosophers - thread example
#
-require "thread"
srand
#srand
diff --git a/sample/pty/expect_sample.rb b/sample/pty/expect_sample.rb
index 2f87f21895..199d98b79c 100644
--- a/sample/pty/expect_sample.rb
+++ b/sample/pty/expect_sample.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
#
# sample program of expect.rb
#
@@ -23,8 +24,17 @@ PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
username = 'guest'
end
- r_f.expect(/^(Name).*: |(word):|> /) do
- w_f.puts($1 ? "ftp" : $2 ? "#{username}@" : "cd pub/ruby")
+ r_f.expect(/^Name.*: /) do
+ w_f.puts("ftp")
+ end
+ r_f.expect(/word:/) do
+ w_f.puts("#{username}@")
+ end
+ r_f.expect(/> /) do
+ w_f.puts("cd pub/ruby")
+ end
+ r_f.expect("> ") do
+ w_f.print "pass\n"
end
r_f.expect("> ") do
w_f.print "dir\n"
diff --git a/sample/pty/script.rb b/sample/pty/script.rb
index 903a6f75bd..c6659a4807 100644
--- a/sample/pty/script.rb
+++ b/sample/pty/script.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require 'pty'
if ARGV.size == 0 then
@@ -34,4 +35,3 @@ PTY.spawn("/bin/csh") do |r_pty,w_pty,pid|
end
system "stty echo -raw lnext ^v"
-
diff --git a/sample/ripper/ruby2html.rb b/sample/ripper/ruby2html.rb
index 8f64f5a713..1e6b3bf550 100644
--- a/sample/ripper/ruby2html.rb
+++ b/sample/ripper/ruby2html.rb
@@ -73,7 +73,11 @@ class ERB
end
def ruby2html(f, encoding, css, print_line_number)
- erb = ERB.new(TEMPLATE, nil, '>')
+ if RUBY_VERSION >= '2.6'
+ erb = ERB.new(TEMPLATE, trim_mode: '>')
+ else
+ erb = ERB.new(TEMPLATE, nil, '>')
+ end
erb.filename = __FILE__
erb.lineno = TEMPLATE_LINE
erb.result(binding())
diff --git a/sample/rss/blend.rb b/sample/rss/blend.rb
deleted file mode 100755
index 351f6f373f..0000000000
--- a/sample/rss/blend.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/usr/bin/env ruby
-
-require "rss"
-
-feeds = []
-verbose = false
-encoding = "UTF-8"
-
-def error(exception)
- mark = "=" * 20
- mark = "#{mark} error #{mark}"
- STDERR.puts mark
- STDERR.puts exception.class
- STDERR.puts exception.message
- STDERR.puts exception.backtrace
- STDERR.puts mark
-end
-
-before_time = Time.now
-ARGV.each do |fname|
- if fname == '-v'
- verbose = true
- next
- end
- rss = nil
- f = File.new(fname).read
- begin
- ## do validate parse
- rss = RSS::Parser.parse(f)
- rescue RSS::InvalidRSSError
- error($!) if verbose
- ## do non validate parse for invalid RSS 1.0
- begin
- rss = RSS::Parser.parse(f, false)
- rescue RSS::Error
- ## invalid RSS.
- error($!) if verbose
- end
- rescue RSS::Error
- error($!) if verbose
- end
- if rss.nil?
- STDERR.puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
- else
- begin
- rss.output_encoding = encoding
- rescue RSS::UnknownConversionMethodError
- error($!) if verbose
- end
- feeds << rss
- end
-end
-processing_time = Time.now - before_time
-
-rss = RSS::Maker.make("1.0") do |maker|
- maker.encoding = encoding
- maker.channel.about = "http://example.com/blend.rdf"
- maker.channel.title = "blended feeds"
- maker.channel.link = "http://example.com/"
- maker.channel.description = "blended feeds generated by RSS Parser"
-
- feeds.each do |feed|
- feed.items.each do |item|
- item.setup_maker(maker.items)
- end
- end
-
- maker.items.each do |item|
- item.title ||= "UNKNOWN"
- item.link ||= "UNKNOWN"
- end
-
- maker.items.do_sort = true
- maker.items.max_size = 15
-end
-puts rss
-
-STDERR.puts "Used XML parser: #{RSS::Parser.default_parser}"
-STDERR.puts "Processing time: #{processing_time}s"
diff --git a/sample/rss/convert.rb b/sample/rss/convert.rb
deleted file mode 100755
index e6bff4c623..0000000000
--- a/sample/rss/convert.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/env ruby
-
-require "rss"
-
-feeds = []
-verbose = false
-encoding = "UTF-8"
-to_version = "1.0"
-
-def error(exception)
- mark = "=" * 20
- mark = "#{mark} error #{mark}"
- STDERR.puts mark
- STDERR.puts exception.class
- STDERR.puts exception.message
- STDERR.puts exception.backtrace
- STDERR.puts mark
-end
-
-before_time = Time.now
-ARGV.each do |fname|
- case fname
- when '-v'
- verbose = true
- next
- when /^-t(0\.91|1\.0|2\.0|atom)$/
- to_version = $1
- next
- end
- rss = nil
- f = File.read(fname)
- begin
- ## do validate parse
- rss = RSS::Parser.parse(f)
- rescue RSS::InvalidRSSError
- error($!) if verbose
- ## do non validate parse for invalid RSS 1.0
- begin
- rss = RSS::Parser.parse(f, false)
- rescue RSS::Error
- ## invalid RSS.
- error($!) if verbose
- end
- rescue RSS::Error
- error($!) if verbose
- end
- if rss.nil?
- STDERR.puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
- else
- begin
- rss.output_encoding = encoding
- rescue RSS::UnknownConversionMethodError
- error($!) if verbose
- end
- feeds << [fname, rss]
- end
-end
-processing_time = Time.now - before_time
-
-feeds.each do |fname, rss|
- converted_rss = rss.to_xml(to_version)
- output_name = fname.sub(/(\.[^\.]+)$/, "-#{to_version}\\1")
- File.open(output_name, "w") do |output|
- output.print(converted_rss)
- end
-end
-
-STDERR.puts "Used XML parser: #{RSS::Parser.default_parser}"
-STDERR.puts "Processing time: #{processing_time}s"
diff --git a/sample/rss/list_description.rb b/sample/rss/list_description.rb
deleted file mode 100755
index 990974d8f5..0000000000
--- a/sample/rss/list_description.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/usr/bin/env ruby
-
-require "nkf"
-class String
- # From tdiary.rb
- def shorten( len = 120 )
- lines = NKF::nkf( "-t -m0 -f#{len}", self.gsub( /\n/, ' ' ) ).split( /\n/ )
- lines[0].concat( '...' ) if lines[0] and lines[1]
- lines[0]
- end
-end
-
-require "rss"
-
-channels = {}
-verbose = false
-
-def error(exception)
- mark = "=" * 20
- mark = "#{mark} error #{mark}"
- puts mark
- puts exception.class
- puts exception.message
- puts exception.backtrace
- puts mark
-end
-
-before_time = Time.now
-ARGV.each do |fname|
- if fname == '-v'
- verbose = true
- next
- end
- rss = nil
- f = File.new(fname).read
- begin
- ## do validate parse
- rss = RSS::Parser.parse(f)
- rescue RSS::InvalidRSSError
- error($!) if verbose
- ## do non validate parse for invalid RSS 1.0
- begin
- rss = RSS::Parser.parse(f, false)
- rescue RSS::Error
- ## invalid RSS.
- error($!) if verbose
- end
- rescue RSS::Error
- error($!) if verbose
- end
- if rss.nil?
- puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
- else
- begin
- rss.output_encoding = "utf-8"
- rescue RSS::UnknownConversionMethodError
- error($!) if verbose
- end
-
- rss = rss.to_rss("1.0") do |maker|
- maker.channel.about ||= maker.channel.link
- maker.channel.description ||= "No description"
- maker.items.each do |item|
- item.title ||= "No title"
- item.link ||= "UNKNOWN"
- end
- end
- next if rss.nil?
-
- rss.items.each do |item|
- channels[rss.channel.title] ||= []
- channels[rss.channel.title] << item if item.description
- end
- end
-end
-processing_time = Time.now - before_time
-
-channels.sort do |x, y|
- x[0] <=> y[0]
-end[0..20].each do |title, items|
- puts "Channel: #{title}" unless items.empty?
- items.sort do |x, y|
- x.title <=> y.title
- end[0..10].each do |item|
- puts " Item: #{item.title.shorten(50)}"
- puts " Description: #{item.description.shorten(50)}"
- end
-end
-
-puts "Used XML parser: #{RSS::Parser.default_parser}"
-puts "Processing time: #{processing_time}s"
diff --git a/sample/rss/re_read.rb b/sample/rss/re_read.rb
deleted file mode 100755
index c386ab20f6..0000000000
--- a/sample/rss/re_read.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env ruby
-
-require "rss"
-
-def error(exception)
- mark = "=" * 20
- mark = "#{mark} error #{mark}"
- puts mark
- puts exception.class
- puts exception.message
- puts exception.backtrace
- puts mark
-end
-
-verbose = false
-before_time = Time.now
-
-ARGV.each do |fname|
- if fname == '-v'
- verbose = true
- next
- end
- source = nil
- File.open(fname) do |f|
- source = f.read
- end
-
- rss = nil
- read = false
- begin
- rss = RSS::Parser.parse(source)
- puts "Re-read valid feed: #{fname}"
- RSS::Parser.parse(rss.to_s)
- read = true
- rescue RSS::InvalidRSSError
- error($!) if verbose
- ## do non validate parse for invalid feed
- begin
- rss = RSS::Parser.parse(source, false)
- rescue RSS::Error
- ## invalid feed
- error($!) if verbose
- end
- rescue RSS::Error
- error($!) if verbose
- end
-
- if rss.nil?
- puts "Invalid feed: #{fname}"
- elsif !read
- puts "Re-read invalid feed: #{fname}"
- begin
- RSS::Parser.parse(rss.to_s)
- rescue RSS::Error
- puts " Error occurred: #{fname}"
- error($!) if verbose
- end
- end
-end
-
-processing_time = Time.now - before_time
-
-puts "Used XML parser: #{RSS::Parser.default_parser}"
-puts "Processing time: #{processing_time}s"
diff --git a/sample/rss/rss_recent.rb b/sample/rss/rss_recent.rb
deleted file mode 100755
index 14c861284e..0000000000
--- a/sample/rss/rss_recent.rb
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/env ruby
-
-require "nkf"
-class String
- # From tdiary.rb
- def shorten( len = 120 )
- lines = NKF::nkf( "-t -m0 -f#{len}", self.gsub( /\n/, ' ' ) ).split( /\n/ )
- lines[0].concat( '...' ) if lines[0] and lines[1]
- lines[0]
- end
-end
-
-require "rss"
-
-items = []
-verbose = false
-
-def error(exception)
- mark = "=" * 20
- mark = "#{mark} error #{mark}"
- puts mark
- puts exception.class
- puts exception.message
- puts exception.backtrace
- puts mark
-end
-before_time = Time.now
-ARGV.each do |fname|
- if fname == '-v'
- verbose = true
- next
- end
- rss = nil
- f = File.new(fname).read
- begin
- ## do validate parse
- rss = RSS::Parser.parse(f)
- rescue RSS::InvalidRSSError
- error($!) if verbose
- ## do non validate parse for invalid RSS 1.0
- begin
- rss = RSS::Parser.parse(f, false)
- rescue RSS::Error
- ## invalid RSS.
- error($!) if verbose
- end
- rescue RSS::Error
- error($!) if verbose
- end
- if rss.nil?
- puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
- else
- begin
- rss.output_encoding = "utf-8"
- rescue RSS::UnknownConversionMethodError
- error($!) if verbose
- end
-
- rss = rss.to_rss("1.0") do |maker|
- maker.channel.about ||= maker.channel.link
- maker.channel.description ||= "No description"
- maker.items.each do |item|
- item.title ||= "UNKNOWN"
- item.link ||= "UNKNOWN"
- end
- end
- next if rss.nil?
-
- rss.items.each do |item|
- items << [rss.channel, item] if item.dc_date
- end
- end
-end
-processing_time = Time.now - before_time
-
-items.sort do |x, y|
- y[1].dc_date <=> x[1].dc_date
-end[0..20].each do |channel, item|
- puts "#{item.dc_date.localtime.iso8601}: " <<
- "#{channel.title}: #{item.title}"
- puts " Description: #{item.description.shorten(50)}" if item.description
-end
-
-puts "Used XML parser: #{RSS::Parser.default_parser}"
-puts "Processing time: #{processing_time}s"
diff --git a/sample/test.rb b/sample/test.rb
index 65dd9abd10..65dd9abd10 100755..100644
--- a/sample/test.rb
+++ b/sample/test.rb
diff --git a/sample/testunit/adder.rb b/sample/testunit/adder.rb
deleted file mode 100644
index aa5c88cc7b..0000000000
--- a/sample/testunit/adder.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# Author:: Nathaniel Talbott.
-# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
-# License:: Ruby license.
-
-class Adder
- def initialize(number)
- @number = number
- end
- def add(number)
- return @number + number
- end
-end
-
diff --git a/sample/testunit/subtracter.rb b/sample/testunit/subtracter.rb
deleted file mode 100644
index 2c08247805..0000000000
--- a/sample/testunit/subtracter.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# Author:: Nathaniel Talbott.
-# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
-# License:: Ruby license.
-
-class Subtracter
- def initialize(number)
- @number = number
- end
- def subtract(number)
- return @number - number
- end
-end
diff --git a/sample/testunit/tc_adder.rb b/sample/testunit/tc_adder.rb
deleted file mode 100644
index 8453beb20a..0000000000
--- a/sample/testunit/tc_adder.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# Author:: Nathaniel Talbott.
-# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
-# License:: Ruby license.
-
-require 'test/unit'
-require 'adder'
-
-class TC_Adder < Test::Unit::TestCase
- def setup
- @adder = Adder.new(5)
- end
- def test_add
- assert_equal(7, @adder.add(2), "Should have added correctly")
- end
- def teardown
- @adder = nil
- end
-end
diff --git a/sample/testunit/tc_subtracter.rb b/sample/testunit/tc_subtracter.rb
deleted file mode 100644
index d2c8313350..0000000000
--- a/sample/testunit/tc_subtracter.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# Author:: Nathaniel Talbott.
-# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
-# License:: Ruby license.
-
-require 'test/unit'
-require 'subtracter'
-
-class TC_Subtracter < Test::Unit::TestCase
- def setup
- @subtracter = Subtracter.new(5)
- end
- def test_subtract
- assert_equal(3, @subtracter.subtract(2), "Should have subtracted correctly")
- end
- def teardown
- @subtracter = nil
- end
-end
diff --git a/sample/testunit/ts_examples.rb b/sample/testunit/ts_examples.rb
deleted file mode 100644
index 3d24dd6522..0000000000
--- a/sample/testunit/ts_examples.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-# Author:: Nathaniel Talbott.
-# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
-# License:: Ruby license.
-
-require 'test/unit'
-require 'tc_adder'
-require 'tc_subtracter'
diff --git a/sample/timeout.rb b/sample/timeout.rb
index 8d25d72a76..ad4459aff0 100644
--- a/sample/timeout.rb
+++ b/sample/timeout.rb
@@ -1,31 +1,31 @@
require 'timeout'
def progress(n = 5)
- n.times {|i| print i; STDOUT.flush; sleep 1; i+= 1}
+ n.times {|i| print i; STDOUT.flush; sleep 1}
puts "never reach"
end
-p timeout(5) {
+p Timeout.timeout(5) {
45
}
-p timeout(5, Timeout::Error) {
+p Timeout.timeout(5, Timeout::Error) {
45
}
-p timeout(nil) {
+p Timeout.timeout(nil) {
54
}
-p timeout(0) {
+p Timeout.timeout(0) {
54
}
begin
- timeout(5) {progress}
+ Timeout.timeout(5) {progress}
rescue => e
puts e.message
end
begin
- timeout(3) {
+ Timeout.timeout(3) {
begin
- timeout(5) {progress}
+ Timeout.timeout(5) {progress}
rescue => e
puts "never reach"
end
@@ -36,7 +36,7 @@ end
class MyTimeout < StandardError
end
begin
- timeout(2, MyTimeout) {progress}
+ Timeout.timeout(2, MyTimeout) {progress}
rescue MyTimeout => e
puts e.message
end
diff --git a/sample/trick2013/kinaba/remarks.markdown b/sample/trick2013/kinaba/remarks.markdown
index a454a5f0a1..dcdce7e9ae 100644
--- a/sample/trick2013/kinaba/remarks.markdown
+++ b/sample/trick2013/kinaba/remarks.markdown
@@ -16,11 +16,11 @@ The program contains each ASCII character from 0x20 ' ' to 0x7e '~' exactly once
### Internals
-The algorthim is the obvious loop "32.upto(126){|x| putc x}".
+The algorithm is the obvious loop "32.upto(126){|x| putc x}".
It is not so hard to transform it to use each character *at most once*. The only slight difficulty comes from the constraint that we cannot "declare and then use" variables, because then the code will contain the variable name twice. This restriction is worked around by the $. global variable, the best friend of Ruby golfers.
-The relatively interesting part is to use all the charcters *at least once*. Of course, this is easily accomplished by putting everything into a comment (i.e., #unused...) or to a string literal (%(unused...), note that normal string literals are forbidden since they use quotation marks twice). Hey, but that's not fun at all! I tried to minimize the escapeway.
+The relatively interesting part is to use all the characters *at least once*. Of course, this is easily accomplished by putting everything into a comment (i.e., #unused...) or to a string literal (%(unused...), note that normal string literals are forbidden since they use quotation marks twice). Hey, but that's not fun at all! I tried to minimize the escapeway.
* "@THEqQUICKbBROWNfFXjJMPSvVLAZYDGgkyz". Trash box of unused alphabet. I wish I could have used "gkyz" somewhere else.
diff --git a/sample/trick2013/mame/music-box.mp4 b/sample/trick2013/mame/music-box.mp4
deleted file mode 100644
index 6d1e87c01c..0000000000
--- a/sample/trick2013/mame/music-box.mp4
+++ /dev/null
Binary files differ
diff --git a/sample/trick2013/mame/remarks.markdown b/sample/trick2013/mame/remarks.markdown
index 8c1988c809..488681d88d 100644
--- a/sample/trick2013/mame/remarks.markdown
+++ b/sample/trick2013/mame/remarks.markdown
@@ -27,7 +27,7 @@ In the piano roll, `#` represents a pin that hits a note, and `|` represents a s
The leftmost column corresponds 110Hz (low A).
Every column corresponds a semitone higher than the left one.
-This program uses [the frequency modulation synthesis](http://en.wikipedia.org/wiki/Frequency_modulation_synthesis) to play the sound like a music-box.
+This program uses [the frequency modulation synthesis](https://en.wikipedia.org/wiki/Frequency_modulation_synthesis) to play the sound like a music-box.
You can create a different-sounding tone by changing the parameter.
For example, the following will play the sound like a harpsichord.
@@ -44,4 +44,4 @@ You have to use sox by replacing the following part:
with:
- IO.popen("./pl","wb") \ No newline at end of file
+ IO.popen("./pl","wb")
diff --git a/sample/trick2013/yhara/entry.rb b/sample/trick2013/yhara/entry.rb
index a2deb54399..3666f271fa 100644
--- a/sample/trick2013/yhara/entry.rb
+++ b/sample/trick2013/yhara/entry.rb
@@ -2,7 +2,7 @@ def _(&b)$><<->(x){x ? (String===x ?x.upcase:
(Class===x ? x : x.class).name[$a?0:($a=5)]):
" "}[ begin b[];rescue Exception;$!;end ] end
-_ { return }
+_ { 1.tap }
_ { method(:p).unbind }
_ { eval "{ " }
_ { Thread.current.join }
diff --git a/sample/trick2015/kinaba/entry.rb b/sample/trick2015/kinaba/entry.rb
index 18923a6a9f..aa077dc240 100644
--- a/sample/trick2015/kinaba/entry.rb
+++ b/sample/trick2015/kinaba/entry.rb
@@ -62,7 +62,7 @@ while 0x00012345 >= $counter
TrueClass
Dir
Encoding
- Data
+ Proc
Hash
Method
Enumerator
diff --git a/sample/trick2015/ksk_1/remarks.markdown b/sample/trick2015/ksk_1/remarks.markdown
index b822dc55c8..a0b8bbcdcc 100644
--- a/sample/trick2015/ksk_1/remarks.markdown
+++ b/sample/trick2015/ksk_1/remarks.markdown
@@ -110,7 +110,7 @@ is simply `/=/` and removing a padding `",,,,,"`. The program no
longer terminates, though.
-### Limination
+### Limitation
The implementation requires to manipulate long strings even for some
small starting numbers. For example, starting from 1,819, the number
diff --git a/sample/trick2015/ksk_2/remarks.markdown b/sample/trick2015/ksk_2/remarks.markdown
index bb9b705773..187a6804d2 100644
--- a/sample/trick2015/ksk_2/remarks.markdown
+++ b/sample/trick2015/ksk_2/remarks.markdown
@@ -199,6 +199,6 @@ succeed to return 0. The meaning of ``\1nn`` in regular expression
seems to depend on the existence of capturing expressions.
In spite of these Ruby's behaviors, we have a good news! The present
-SAT sover does not suffer from the issues because the program cannot
+SAT solver does not suffer from the issues because the program cannot
return solutions in practical time for inputs with variables more than
-40. \ No newline at end of file
+40.
diff --git a/sample/trick2018/01-kinaba/authors.markdown b/sample/trick2018/01-kinaba/authors.markdown
new file mode 100644
index 0000000000..d0df0b379d
--- /dev/null
+++ b/sample/trick2018/01-kinaba/authors.markdown
@@ -0,0 +1,3 @@
+* kinaba
+ * twitter.com/kinaba
+ * cctld: jp
diff --git a/sample/trick2018/01-kinaba/entry.rb b/sample/trick2018/01-kinaba/entry.rb
new file mode 100644
index 0000000000..eb8284d5ab
--- /dev/null
+++ b/sample/trick2018/01-kinaba/entry.rb
@@ -0,0 +1,8 @@
+alias BEGIN for unless def class
+super true or return defined? next
+break while begin undef do end
+rescue then retry else undef module
+nil ensure case if yield __LINE__
+self and redo elsif not __FILE__
+alias END in end when __ENCODING__
+end until false end
diff --git a/sample/trick2018/01-kinaba/remarks.markdown b/sample/trick2018/01-kinaba/remarks.markdown
new file mode 100644
index 0000000000..d0b9fdffde
--- /dev/null
+++ b/sample/trick2018/01-kinaba/remarks.markdown
@@ -0,0 +1,55 @@
+### Remarks
+
+Just run it with no argument:
+
+ ruby entry.rb
+
+(Anyway it is just a no-op program. The above command only verifies
+that entry.rb is a valid Ruby program.)
+
+I confirmed the following implementations/platforms:
+
+* ruby 2.5.0p0 (2017-12-25 revision 61468) [x64-mingw32]
+
+### Description
+
+First, look at
+
+https://docs.ruby-lang.org/ja/latest/doc/spec=2flexical.html#reserved
+
+and then, look at entry.rb.
+
+The source code of entry.rb consists only of reserved words of Ruby,
+and all the reserved words are used in the code, in a way that the code
+forms a valid Ruby program. No compile error, no warning, or no runtime error.
+
+
+### Internals
+
+Difficult (and interesting) points of the theme are:
+
+* Since many of the reserved words define program structures, we cannot
+ use them independently. For instance, `retry` must be inside `rescue`,
+ or `break`/`next`/`redo` must be inside a looping construct.
+ Or, jump-out statements cannot occur at a position that requires a
+ value; `if return then true end` is a "void value expression" syntax error.
+* Inserting newlines for each 6 word (to match with the spec html) is also
+ an interesting challenge, since Ruby is sensitive to newlines.
+
+Tricks used in the code are:
+
+* def/alias/undef can take even reserved words as parameters.
+ That is, `def class ... end` defines a method named `class`.
+ The feature is crucial since otherwise `BEGIN` etc inevitably
+ introduces non-reserved tokens (like `{}`).
+* `defined?` can take some reserved words too (which I didn't know
+ until trying to write this program.)
+* "void value expression" can be avoided by using `or` or `and`.
+ `if begin return end then true end` is a syntax error, but
+ `if begin false or return end then true end` is not.
+
+
+### Limitation
+
+Sad to say that it's not a "perfect pangram".
+It uses 'alias' and 'undef' twice, and 'end' 4 times.
diff --git a/sample/trick2018/02-mame/authors.markdown b/sample/trick2018/02-mame/authors.markdown
new file mode 100644
index 0000000000..0e420fdf5d
--- /dev/null
+++ b/sample/trick2018/02-mame/authors.markdown
@@ -0,0 +1,3 @@
+* Yusuke Endoh
+ * mame@ruby-lang.org
+ * cctld: jp
diff --git a/sample/trick2018/02-mame/entry.rb b/sample/trick2018/02-mame/entry.rb
new file mode 100644
index 0000000000..cc4ef9cbc4
--- /dev/null
+++ b/sample/trick2018/02-mame/entry.rb
@@ -0,0 +1,15 @@
+'';eval(r=%q(->z{r="'';eval(r=\
+%q(#{r}))[%q`#{z}`]";i=-040;30.
+times{|n|(15+n%2*15-n/2).times{
+r<<r[i+=(1.-n&2)*(32-n%2*31)]}}
+i=r[524,0]=?\0;eval(r[479..-1])
+c['"']}))[%q`GFEDCBA"+"[e\"'"'t
+kE*;;\";" TRICK2018 ";tb,;{{r
+2E0$ob[us@*0)[90,336])_#i\n}s#i
+0H}>["t]];};o[1,?\n*8];ex"-}eac
+1Hl<1[-1]*2*t=n%2];o[14-n,0)mvk
+8M$<4,?\n];15.times{|n|;o[35ie2
+!Pss.slice!(0,1)+x;sleep(0.0t;0
+'W=%q"<<95<<$s<<95;o=->n,x{n.'1
+;@[2]}|\e../,%@s="'%trick2018!8
+eval$s=%q_eval($s.gsub!(/#{%@`]
diff --git a/sample/trick2018/02-mame/remarks.markdown b/sample/trick2018/02-mame/remarks.markdown
new file mode 100644
index 0000000000..88b32c205a
--- /dev/null
+++ b/sample/trick2018/02-mame/remarks.markdown
@@ -0,0 +1,16 @@
+This program quines with animation.
+
+```
+$ ruby entry.rb
+```
+
+Of course, the output is executable.
+
+```
+$ ruby entry.rb > output
+$ ruby output
+```
+
+Note, we don't cheat. This program uses escape sequences just for moving the cursor. It doesn't use attribution change nor overwrite to hide any code.
+
+The program is crafted so that it works in two ways; it works as a normal program text, and, it also works when it is rearranged in a spiral order. Some parts of the code are actually overlapped.
diff --git a/sample/trick2018/03-tompng/Gemfile b/sample/trick2018/03-tompng/Gemfile
new file mode 100644
index 0000000000..a24ff779dc
--- /dev/null
+++ b/sample/trick2018/03-tompng/Gemfile
@@ -0,0 +1,2 @@
+source 'https://rubygems.org'
+gem 'chunky_png'
diff --git a/sample/trick2018/03-tompng/Gemfile.lock b/sample/trick2018/03-tompng/Gemfile.lock
new file mode 100644
index 0000000000..467f5c3495
--- /dev/null
+++ b/sample/trick2018/03-tompng/Gemfile.lock
@@ -0,0 +1,13 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ chunky_png (1.3.8)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ chunky_png
+
+BUNDLED WITH
+ 1.16.1
diff --git a/sample/trick2018/03-tompng/authors.markdown b/sample/trick2018/03-tompng/authors.markdown
new file mode 100644
index 0000000000..26ebe24da6
--- /dev/null
+++ b/sample/trick2018/03-tompng/authors.markdown
@@ -0,0 +1,3 @@
+* Tomoya Ishida (tompng)
+ * tomoyapenguin@gmail.com
+ * cctld: jp
diff --git a/sample/trick2018/03-tompng/entry.rb b/sample/trick2018/03-tompng/entry.rb
new file mode 100644
index 0000000000..26416c7019
--- /dev/null
+++ b/sample/trick2018/03-tompng/entry.rb
@@ -0,0 +1,31 @@
+X=[];class String def-@;replace ?-+self end;def-a;X.reject!{|x|x.
+__id__==__id__};a.replace(self+?-+a) end end;at_exit{eval C=(Zlib
+.inflate((X*?-).tr(?-,'').tr('q-z','0-9').to_i(26).digits(0x100).
+pack'C*'))};def method_missing n;(X<<n.to_s)[-1]end;require'zlib'
+fzygtoxyzgntmdmuwvfoffbpmvzojpkhczvjvjdbtscnldwbdoprackddovivvmkz
+ponzmosvtjciwkgaslscxxxwudeesmmqpfhislxuxnnypulxstzgobyaekqqhbjcg
+mvko------------ddkeys----eivhnccaqyiw---bzyccmt-----------ymtnge
+jwhi--------------pjxf------mdarbtumnv---qasda--------------gmwdt
+wrtk---qtpzgnce----fsl-------fkgzgtbpp---gwnm----pxkpqkdiw---owga
+momz---yjjvpnvar---zeo---v-----duvalwu---nsqt---waofemwakivnyqkjd
+fzag---uhvusmkl----kzb---rhc----iutzjr---mqlh---ayijpwativpweaato
+xexs--------------rvgv---pjdz-----lkkg---uiaw---lovitupw-----fwmn
+kfru------------jvjpgv---jskycf----pal---gbuf---hfdnywog-----iuca
+pntn---apmkqroeuzwuwkw---gqnmgof-----b---hlpl---vkkyhfyrqfr--jwrl
+kmdb---dhspujhmtgrkccu---uonfummdt-------rqfw----bpiactehwp--fncq
+yzvz---gdaxebplhfndran---ytfmviryeh------hqwkl---------------nced
+bibu---fnkdthgldhkxxjg---rwnmpudhbqin----gucoyki------------hfura
+cqdgqpyzqfzknvdjoxxhpjulwwyebtocxdrvklbuviwwcatlmdosxfvwntzbijguy
+iglrvvzlxerflupxvsyujfacuwhrvmnecgtewtqkhtdggcltejiyqcluclkycwvzg
+vvxfysvttfbeglvrlngntdngzyhqrmltazwdydxrsvjploembhgxdvfmmhepbschm
+brn--iqrcdb--evv----tqp------lg--uein-wzut--mr------wkh------foqz
+zsf--srjnjp--ampb--pfio--hgtekx--rrr---fwd--jn--xqkezcz--vsb--nya
+khrc--evlr--oioxs--mqce--bqfmag--bwz---xda--qw--jnuzelr--qzi--itx
+mdxd--duso--wxbot--nmon--ugnbdpc--a--c--e--hlg--twxndre--tby--rhg
+evhbn--zb--dtxmiz--dpia------vie--h--i--t--shh------kfn------owna
+ealmt--kb--scxdjy--smvl--dqmgebk--t--s--t--gfd--updcbnc--rh--dwwp
+dvpnxb----wpljjdy--kolc--qflyleok---xkv---usbj--jhrawbn--ewx--bgf
+eaqwrw----ejwxhet--dice--eoczconm---urz---rqyp--hovvvfc--bskj--el
+aocjcts--jtumwxm----mgy------xpaoq-jtwqr-aipay------dhy--iync--hk
+sckddmvuvvuhhqstumaykvczaaujrumqbbqsdvdycplyrlkkojlxnkrhbbrmnjxyf
+cdtcmpfmjvthwkpzucbblttgumomlxnxwjeypfeagaukfzeokzxjebkpigcvlqnso
diff --git a/sample/trick2018/03-tompng/output.txt b/sample/trick2018/03-tompng/output.txt
new file mode 100644
index 0000000000..ed9a4079cc
--- /dev/null
+++ b/sample/trick2018/03-tompng/output.txt
@@ -0,0 +1,44 @@
+undef p;X=[];class String def-@;replace ?-+dup end;def-a;X.reject!{|x|x.__id__==__id__};a.replace(self+?-+a) end end;at_exit{eval C=
+(Zlib.inflate (X*?-).tr(?-,'').tr('q-z','0-9').to_i(26).digits(256).pack'C*')};def method_missing n;(X<<n.to_s)[-1]end;require'zlib'
+gmlztzdculbtzgtjfetuh---k--htf----d-----------------------------------------------------g-b-----s--t-g--------jmuwescmgchftikfjafccs
+ivchcveidpvxdabnvwyga-f--v-------xf----------------------------------------------------q-v---l-------q---------liiNeawriayymwooxgxqw
+rfosepqsmojseyezmwbhi--------------ew--------------------------------------------------m---k-r-----------vwu--hiotltdmczwyjmlvbyfqwq
+uvvykqdjednoqgtcmtfbzs---------f----o--------------------------------------------------t--a------m----x---f-----dldzsakyofetfozfpmrq
+geusutariiiNiulkjbwlm-----d------------------------------------------------------------j---------o---------x--j-uitzrgwpupwhvendhyno
+uubvnssiywkklwwdufhhi-rw----k---v-------------------------------------------------------sty-----yg---l---c-v----wkffpskpumolqmkeryzg
+zrxdaiposwybbzgxdnegh-----g-----ma--n---------------------------------------------------------j----n--b-n-------yqavmscswdogpcgopygt
+axiqfswlhzeamvymdnteo---q-q-w--------------------------fhrmj-----------------hkou-----------f-----d----u-o------evcuxxegekfgivzzujan
+nslioftsvqvtkeigvfgwr-------------lyco-----------------igyvg-----------------okuk---------m--b-u--d--y------s---dadjrlykfhtermzfyktu
+btoxzfpPicxxfligbivvf--------h----yrat---------------------------------------vjwd---------------------d-ki--o--tyqosehopkwttigwwfskp
+komzvnyrvkjcjwbmdwdkp----------vxphiNdtawn--xms-saketo--jnld----ezulntdaz----nzna-----vhjwt------h----x--x--o--saxxsrkgktqotaluylbkk
+sclegratyaarmgmepheml----------hwgglhlrfcx--znvmpfsgjx-onhju---gtxsmzqprlt---mjzy---frhdk-------------v---mj----dzjujmbgldfwoybgicwu
+tfhgnhlzxlwtdtkgzlaca-------------gmex------arlm--------rvmh-ajtgf-----pqal--wcux-zatyi-------------------------xnluwybcugjclmablshn
+tnjohqtqzivgmyutrssil-------------lcwq------jrf--------gcaii-maie------------vvnfjfqwo--------------------------filivosyhkxcvuwdibwj
+tyxjiopiFqypvwdzoatuq-------------tdln------cnx---------ffuf-ajvq------------tyyypglpzmj------------------------vtqzwewqdsijrbymvpwn
+niNffphoehukpvvmzvhyd-------------ahqd------nfr---------jeqk--toap-----mxhyg-tedv---otrwy-----------------------mjxnrktackwxwiajdnuc
+kkxhuwbvibpvgvcampadi-------------ebmencqz--obf--------wfprz---qmrotkijiqv---ggfp-----hlzw----------------------kastwdpxiyftmypuxbtu
+xetudmwzpomktgnjkcsyc---------------fwpdx---xb----j-----se-k------tllakc-----gjoo-------we------mic---lktk------ubtnrxvrjzuqlrfrsnmf
+okdvfvcdbdqkckjialskk---------------------------v---u-------l----------------------------------z--q--qfg--------aaliNbxbjjpxebboneye
+kcbkjmdclwnfawtfnwkeq----------------------------------j---y-------------------------------a---jmbyo-sgef--gf---extljbozuoofgyvsilct
+xzoqmsqgzjxxpjqwkjkdd------------------------o--------m-------f---------------------------------n--de-ajz-rzv---fhnpbkrwdxoozpxeaxaf
+mbcwxuiqdwcmadheiykaa-----------------------q-f------l---i---------------------------------r----zf---k--y---fi--dcnycheytylcgnioauee
+yekiNacriqoevtdjerqbp----------------------------w---yy-----my----------------------------ko--mnbpskr--c-----j--ozyqpbfovhbhyoprzgqr
+czwtuopxkdbphocfawvbk--------------------------q-s----j--b---------------------------------hd-xsb----bfiNp--w---fmwuvfambdqvxtzldwmh
+xysnyrseydlkjcwfbsjnr-------------------------d-d-------------------------------------------f-enpss---qllpwr----almsdidvjwoigvldfqoa
+lrpbixjpofxocxlflscpo------------------------------q-fyu--z-------------------------------------kfd-z---n-------bqxurujnxzurrdgcojks
+jetyfdkcekckxbyosbfws-------------wdfhgwuvejjmf-----sxjubpvgcsl-------tnmixpv---------eurabjsdvstfv-------------qcyiqhonwoyixqeonfvp
+mopPhywsozohitutgmmrb------------zxwtxe--riedeo---mspgpnv--pimlh------jhtzajk--------qqovvq---ldbrh-------------xtooxpayonpcvvtmvpra
+vvuyiunpoeagdzqjecsub------------klrw------snrc---rrct------aajom--------nsyk--------peea-------azq-------------iNjefdkfhnagjicqwmsm
+mbwwbfgehhbdmvvlflmee---------------------hkejn---jtbo-------jdtje-------jcei---------afyz-----smtc-------------kksvfjyuaqtohxiohhlz
+dvfmfrzcmnsfruhqgjuxz------------------dfxdnlk----kkra-------xmmtf-------jwkw----------rdoozxtcho---------------bbwwferxwnnmdzcniicv
+mfneisdlyeqwynldjgonj----------------jgrjvc-------uxga-------ghnpr-------sers--------scbknx----gmjo-------------moedtnlbflhtlkjibrqk
+gobwqshnpbdcpjmjaeczr--------------iscsxs---------zfpo-------hhfwy-------qbba-------vhlxc-------ntod------------ndwzdomaptumzejiwqbn
+snucynymvfpnadyqkzfcv-------------ggze------------kuvfs-----zuhod--------mylo-------jhwyp-----z-pywd------------dqfmpnevmtqcikbrilto
+aotyxkipebdkassogpcbl-----------wgackesmvvsrihhd---orzndjndlzpb----------eobf-------kkayixzyotqfafa-w-----------mjjxoomwdglwvccozzut
+rthesuszfwycsqqrtxlot-----------ejcqlhriilqbtrys------lwbkzmvp-----------zzwm-------l--qijwfllndzb-ik-----------mmokqomjepdcotnsiNig
+nloryyoswwdmefywnnuhph------------------------------------------------------r--r-nd-----h--x--------------------hlgzeqqslwxgtjgghquf
+nssngjtiudsrvfuxjzclhjhj----------------------------------------------------------t----------------k-f-mp-------obhyehqebtpjbkeepqzt
+ezogzsimfynqmkteaipejo-g-yser-----------------------------------------------e------h-------------i---y----------qpgcqnltivmmsximbbsy
+wtjjolwyoselcumgklqwpldkl-ulm-m---------------------------------------------------------------q---u-f--l--------buixfiitufktsqdtnrei
+tgrtitcewseetlpeuuujb-osdokjozc------------------------------------------n---d-----f--------g--------q--g-------jyyqtezuzmcxgpcwuwfx
+dpPayqmzxrwhbswwalygfurtkruw-u-k---------------------------------------------d---h------i----------c----i-------ulowcddvjbxthqlxjzbe
diff --git a/sample/trick2018/03-tompng/remarks.markdown b/sample/trick2018/03-tompng/remarks.markdown
new file mode 100644
index 0000000000..fe9eec5989
--- /dev/null
+++ b/sample/trick2018/03-tompng/remarks.markdown
@@ -0,0 +1,19 @@
+### Remarks
+
+Bundle install
+ this program depends on `gem chunky_png`
+
+Run it with the following command:
+ bundle exec ruby entry.rb trick.png
+ bundle exec ruby entry.rb [other png file]
+
+I confirmed the following implementations/platforms:
+
+* ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin16]
+* ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
+
+### Description
+
+This program is a png image viewer.
+The output is an asciiart of the given png file,
+and it is also a source code of the png viewer itself.
diff --git a/sample/trick2018/03-tompng/trick.png b/sample/trick2018/03-tompng/trick.png
new file mode 100644
index 0000000000..d4bb0bd7c3
--- /dev/null
+++ b/sample/trick2018/03-tompng/trick.png
Binary files differ
diff --git a/sample/trick2018/04-colin/authors.markdown b/sample/trick2018/04-colin/authors.markdown
new file mode 100644
index 0000000000..a846d12535
--- /dev/null
+++ b/sample/trick2018/04-colin/authors.markdown
@@ -0,0 +1,3 @@
+* Colin Fulton
+ * justcolin@gmail.com
+ * cctld: us
diff --git a/sample/trick2018/04-colin/entry.rb b/sample/trick2018/04-colin/entry.rb
new file mode 100644
index 0000000000..442a8ea3a8
--- /dev/null
+++ b/sample/trick2018/04-colin/entry.rb
@@ -0,0 +1,2 @@
+# Copyright 2018. Available for use under the terms of the MIT License.
+$🚀=0;def 🤔 🏷,🤔=0,&b;puts ' '*$🚀+(🤔 ?"":"🚫 ")+🏷;$🚀+=4;b&.[];$🚀-=4;end
diff --git a/sample/trick2018/04-colin/remarks.markdown b/sample/trick2018/04-colin/remarks.markdown
new file mode 100644
index 0000000000..5f4f1a8dfe
--- /dev/null
+++ b/sample/trick2018/04-colin/remarks.markdown
@@ -0,0 +1,62 @@
+### Remarks
+
+Create a Ruby file that requires entry.rb with a series of test in it the run the file using ruby:
+
+```
+ruby name_of_test_file.rb
+```
+
+To create a test, call 🤔 with two arguments. The first is a string describing what this tests, the second argument is the test assertion. If the assertion is truthy, the test passes. If the assertion is falsy, the test fails.
+
+```
+string_1 = "Hello world!"
+string_2 = "This is not the same!"
+
+🤔 "The two strings are equal",
+ string_1 == string_2
+```
+
+To create a group of tests under a label, call 🤔 with a string describing the group and a block containing the tests in that group.
+
+```
+🤔 "This is a group of tests" do
+ # Add other groups and/or tests here.
+end
+```
+
+Here is an example:
+
+```
+require './entry'
+
+🤔 "Math" do
+ 🤔 "Addition" do
+ 🤔 "One plus one equals two.",
+ 1+1 == 2
+ 🤔 "One plus one equals eleven. (This should fail.)",
+ 1+1 == 11
+ end
+
+ 🤔 "Subtraction" do
+ 🤔 "One minus one equals zero.",
+ 1-1 == 0
+ 🤔 "Ten minus one equal nine.",
+ 10-1 == 9
+ end
+end
+```
+
+It has been tested with the following Ruby versions:
+
+* ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
+* ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
+* If you replace `b&.[]` with `b&&b[]` it will work with ruby 2.0.0 as well, but it will be one character longer.
+
+
+### Description
+
+The goal was to create a testing library where the test files looked good and the output looked good in as few characters as possible. The result is 68 characters and has one method to handle everything.
+
+### Limitation
+
+Your terminal program must support Unicode characters for the test output to look correct. If your terminal does not support Unicode, simply replace the 🚫 in the code with whatever character you want to prefix failing tests.
diff --git a/sample/trick2018/05-tompng/authors.markdown b/sample/trick2018/05-tompng/authors.markdown
new file mode 100644
index 0000000000..26ebe24da6
--- /dev/null
+++ b/sample/trick2018/05-tompng/authors.markdown
@@ -0,0 +1,3 @@
+* Tomoya Ishida (tompng)
+ * tomoyapenguin@gmail.com
+ * cctld: jp
diff --git a/sample/trick2018/05-tompng/entry.rb b/sample/trick2018/05-tompng/entry.rb
new file mode 100644
index 0000000000..31522b6de2
--- /dev/null
+++ b/sample/trick2018/05-tompng/entry.rb
@@ -0,0 +1,41 @@
+ X=[];def self.method_missing n;n.to_s.chars;end
+ l=[];def l.-a;X<<a=[nil,*a];a;end;def l.+a;self-a;end
+ class Array;def-@;[]-self;end;def-a;replace [*self,nil,*a
+ ]end;alias +@ -@;alias + -;end;def gen3d f;yield;b=['solid obj'];w,
+ h=X[0].size,X.size;X<<[];a=->r,z,dr,dz{;r-=w/2.0;z*=2;r2,z2=r+dr,z+dz*2;if r>0||r2>
+ 0;r=[0,r].max;r2=[0,r2].max;16.times{|i|m=Math;p=m::PI/8;;c,s=m.cos(t=i*p),m.sin(t)
+ c2,s2=m.cos(t=(i+1)*p),m.sin(t);t-=p/2;[[0,1,2],[0,2,3]].map{|a|b.push [:facet,'n'+
+ + 'ormal',dz*m.cos(t),dz*m.sin(t),-dr]*' ','outer loop',a.map{|i|'v'+
+ ++ "ertex #{[[r*c,r*s,z],[r*c2,r*s2,z],[r2*c2,r2*s2,z2],[r2*
+ +c, r2*s,z2]][i]*' '}"},:endloop,:endfacet}}end};(0...h).
+ map{| y|w.times{|x|[X[y-1][x]||a[x,y,1,0],X[y+1][x]||
+ a[x+1,y+
+ 1,-1,0],X[
+ y][x-+1]||a[
+ x,y+1,0,-1],X[y
+ ][x++1]||a[x+1,y,
+ 0,1]]if X[y][x]}}
+ s=[b,'end'+b[0]]*
+ $/;File.write(f,
+ s);X.replace(
+ []);end
+
+gen3d 'wine_glass.stl' do
+ l--ww------------------ww--l
+ l--ww------------------ww--l
+ l--ww++++++++++++++++++ww--l
+ l--ww++++++++++++++++++ww--l
+ l--ww++++++++++++++++++ww--l
+ l--ww++++++++++++++++++ww--l
+ l---ww++++++++++++++++ww---l
+ l----www++++++++++++www----l
+ l------www++++++++www------l
+ l--------wwwwwwwwww--------l
+ l-----------wwww-----------l
+ l------------ww------------l
+ l------------ww------------l
+ l------------ww------------l
+ l-----------wwww-----------l
+ l---------wwwwwwww---------l
+ l----wwwwwwwwwwwwwwwwww----l
+end
diff --git a/sample/trick2018/05-tompng/preview_of_output.png b/sample/trick2018/05-tompng/preview_of_output.png
new file mode 100644
index 0000000000..db511ee2f3
--- /dev/null
+++ b/sample/trick2018/05-tompng/preview_of_output.png
Binary files differ
diff --git a/sample/trick2018/05-tompng/remarks.markdown b/sample/trick2018/05-tompng/remarks.markdown
new file mode 100644
index 0000000000..b4e5708a43
--- /dev/null
+++ b/sample/trick2018/05-tompng/remarks.markdown
@@ -0,0 +1,31 @@
+### Remarks
+
+Just run it with no argument:
+
+ ruby entry.rb
+
+I confirmed the following implementations/platforms:
+
+* ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin16]
+* ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
+* ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
+
+### Description
+
+This program will generate `wine_glass.stl`, a 3D data file(STL format) of a wine glass.
+You can change the shape by modifying the DSL part.
+For sake cup:
+```ruby
+gen3d 'ochoko.stl' do
+ l------------------------l
+ l-ww------------------ww-l
+ l-ww------------------ww-l
+ l-ww++++++++++++++++++ww-l
+ l-ww++++++++++++++++++ww-l
+ l--ww++++++++++++++++ww--l
+ l---wwww++++++++++wwww---l
+ l----wwwwwwwwwwwwwwww----l
+ l----www----------www----l
+end
+```
+`+` and `-` are the same meaning(just for appearance)
diff --git a/sample/trick2018/README.md b/sample/trick2018/README.md
new file mode 100644
index 0000000000..345500b00a
--- /dev/null
+++ b/sample/trick2018/README.md
@@ -0,0 +1,16 @@
+This directory contains the award-winning entries of
+the 3rd Transcendental Ruby Imbroglio Contest for rubyKaigi (TRICK 2018).
+
+THESE ARE BAD EXAMPLES! You must NOT use them as a sample code.
+
+* 01-kinaba/entry.rb: "Most reserved" - **Gold award**
+* 02-mame/entry.rb: "Best spiral" - **Silver award**
+* 03-tompng/entry.rb: "Best png viewer" - **Bronze award**
+* 04-colin/entry.rb: "Best one-liner" - 4th prize
+* 05-tompng/entry.rb: "Most three-dimensional" - 5th prize
+
+These files are licensed under MIT license.
+
+For the contest outline and other winning entries, see:
+
+https://github.com/tric/trick2018
diff --git a/sample/webrick/demo-app.rb b/sample/webrick/demo-app.rb
deleted file mode 100644
index c7a2a0a6a4..0000000000
--- a/sample/webrick/demo-app.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-require "pp"
-
-module DemoApplication
- def initialize(config, enctype)
- super
- @enctype = enctype
- end
-
- def do_GET(req, res)
- if req.path_info != "/"
- res.set_redirect(WEBrick::HTTPStatus::Found, req.script_name + "/")
- end
- res.body =<<-_end_of_html_
- <HTML>
- <FORM method="POST" enctype=#{@enctype}>
- text: <INPUT type="text" name="text"><BR>
- file: <INPUT type="file" name="file"><BR>
- check:
- <INPUT type="checkbox" name="check" value="a">a,
- <INPUT type="checkbox" name="check" value="b">b,
- <INPUT type="checkbox" name="check" value="c">c,
- <BR>
- <INPUT type="submit">
- </FORM>
- </HTML>
- _end_of_html_
- res['content-type'] = 'text/html; charset=iso-8859-1'
- end
-
- def do_POST(req, res)
- if req["content-length"].to_i > 1024*10
- raise WEBrick::HTTPStatus::Forbidden, "file size too large"
- end
- res.body =<<-_end_of_html_
- <HTML>
- <H2>Query Parameters</H2>
- #{display_query(req.query)}
- <A href="#{req.path}">return</A>
- <H2>Request</H2>
- <PRE>#{WEBrick::HTMLUtils::escape(PP::pp(req, "", 80))}</PRE>
- <H2>Response</H2>
- <PRE>#{WEBrick::HTMLUtils::escape(PP::pp(res, "", 80))}</PRE>
- </HTML>
- _end_of_html_
- res['content-type'] = 'text/html; charset=iso-8859-1'
- end
-
- private
-
- def display_query(q)
- ret = ""
- q.each{|key, val|
- ret << "<H3>#{WEBrick::HTMLUtils::escape(key)}</H3>"
- ret << "<TABLE border=1>"
- ret << make_tr("val", val.inspect)
- ret << make_tr("val.to_a", val.to_a.inspect)
- ret << make_tr("val.to_ary", val.to_ary.inspect)
- ret << "</TABLE>"
- }
- ret
- end
-
- def make_tr(arg0, arg1)
- "<TR><TD>#{arg0}</TD><TD>#{WEBrick::HTMLUtils::escape(arg1)}</TD></TR>"
- end
-end
diff --git a/sample/webrick/demo-multipart.cgi b/sample/webrick/demo-multipart.cgi
deleted file mode 100644
index 0893fadadf..0000000000
--- a/sample/webrick/demo-multipart.cgi
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/env ruby
-require "webrick/cgi"
-require "webrick/https" # should load if it runs on HTTPS server
-require "./demo-app"
-
-class DemoCGI < WEBrick::CGI
- include DemoApplication
-end
-
-config = { :NPH => false }
-cgi = DemoCGI.new(config, "multipart/form-data")
-cgi.start
diff --git a/sample/webrick/demo-servlet.rb b/sample/webrick/demo-servlet.rb
deleted file mode 100644
index 9c18cc65d1..0000000000
--- a/sample/webrick/demo-servlet.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require "webrick"
-require "./demo-app"
-
-class DemoServlet < WEBrick::HTTPServlet::AbstractServlet
- include DemoApplication
-end
diff --git a/sample/webrick/demo-urlencoded.cgi b/sample/webrick/demo-urlencoded.cgi
deleted file mode 100644
index e4706f8b59..0000000000
--- a/sample/webrick/demo-urlencoded.cgi
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/env ruby
-require "webrick/cgi"
-require "webrick/https" # should load if it runs on HTTPS server
-require "./demo-app"
-
-class DemoCGI < WEBrick::CGI
- include DemoApplication
-end
-
-config = { :NPH => false }
-cgi = DemoCGI.new(config, "application/x-www-form-urlencoded")
-cgi.start
diff --git a/sample/webrick/hello.cgi b/sample/webrick/hello.cgi
deleted file mode 100644
index 35d2240df0..0000000000
--- a/sample/webrick/hello.cgi
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env ruby
-require "webrick/cgi"
-
-class HelloCGI < WEBrick::CGI
- def do_GET(req, res)
- res["content-type"] = "text/plain"
- res.body = "Hello, world.\n"
- end
-end
-
-HelloCGI.new.start
diff --git a/sample/webrick/hello.rb b/sample/webrick/hello.rb
deleted file mode 100644
index 4d02676818..0000000000
--- a/sample/webrick/hello.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require "webrick"
-
-class HelloServlet < WEBrick::HTTPServlet::AbstractServlet
- def do_GET(req, res)
- res["content-type"] = "text/plain"
- res.body = "Hello, world.\n"
- end
-end
diff --git a/sample/webrick/httpd.rb b/sample/webrick/httpd.rb
deleted file mode 100644
index b0edf47582..0000000000
--- a/sample/webrick/httpd.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require "webrick"
-
-httpd = WEBrick::HTTPServer.new(
- :DocumentRoot => File::dirname(__FILE__),
- :Port => 10080,
- :Logger => WEBrick::Log.new($stderr, WEBrick::Log::DEBUG),
- :AccessLog => [
- [ $stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
- [ $stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT ],
- [ $stderr, WEBrick::AccessLog::AGENT_LOG_FORMAT ],
- ],
- :CGIPathEnv => ENV["PATH"] # PATH environment variable for CGI.
-)
-
-require "./hello"
-httpd.mount("/hello", HelloServlet)
-
-require "./demo-servlet"
-httpd.mount("/urlencoded", DemoServlet, "application/x-www-form-urlencoded")
-httpd.mount("/multipart", DemoServlet, "multipart/form-data")
-
-trap(:INT){ httpd.shutdown }
-httpd.start
diff --git a/sample/webrick/httpproxy.rb b/sample/webrick/httpproxy.rb
deleted file mode 100644
index c84457ece7..0000000000
--- a/sample/webrick/httpproxy.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require "webrick"
-require "webrick/httpproxy"
-
-# The :ProxyContentHandler proc will be invoked before sending a response to
-# the User-Agent. You can inspect the pair of request and response messages
-# (or edit the response message if necessary).
-
-pch = Proc.new{|req, res|
- p [ req.request_line, res.status_line ]
-}
-
-def upstream_proxy
- if prx = ENV["http_proxy"]
- return URI.parse(prx)
- end
- return nil
-end
-
-httpd = WEBrick::HTTPProxyServer.new(
- :Port => 10080,
- :ProxyContentHandler => pch,
- :ProxyURI => upstream_proxy
-)
-Signal.trap(:INT){ httpd.shutdown }
-httpd.start
diff --git a/sample/webrick/httpsd.rb b/sample/webrick/httpsd.rb
deleted file mode 100644
index a120782c3c..0000000000
--- a/sample/webrick/httpsd.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-require "webrick"
-require "webrick/https"
-
-hostname = WEBrick::Utils::getservername
-subject = [["O", "ruby-lang.org"], ["OU", "sample"], ["CN", hostname]]
-comment = "Comment for self-signed certificate"
-
-httpd = WEBrick::HTTPServer.new(
- :DocumentRoot => File::dirname(__FILE__),
- :Port => 10443,
- :SSLEnable => true,
-
- # Specify key pair and server certificate.
- # :SSLPrivateKey => OpenSSL::PKey::RSA.new(File.read("server.key")),
- # :SSLCertificate => OpenSSL::X509::Certificate.new(File.read("server.crt")),
-
- # specify the following SSL options if you want to use auto
- # generated self-signed certificate.
- :SSLCertName => subject,
- :SSLComment => comment,
-
- :CGIPathEnv => ENV["PATH"] # PATH environment variable for CGI.
-)
-
-require "./hello"
-httpd.mount("/hello", HelloServlet)
-
-require "./demo-servlet"
-httpd.mount("/urlencoded", DemoServlet, "application/x-www-form-urlencoded")
-httpd.mount("/multipart", DemoServlet, "multipart/form-data")
-
-trap(:INT){ httpd.shutdown }
-httpd.start