quine web server

ramaze 版

# quine-web-service-on-ramaze.rb (c) Yusuke Endoh 2009
require "rubygems"
require "ramaze"
class C < Ramaze::Controller
  def index
    e = "END" << 10
    t = "    s << ((e + <<END) * 2)[4..-1]" << 10
    s = <<END * 2 << e << t
# quine-web-service-on-ramaze.rb (c) Yusuke Endoh 2009
require "rubygems"
require "ramaze"
class C < Ramaze::Controller
  def index
    e = "END" << 10
    t = "    s << ((e + <<END) * 2)[4..-1]" << 10
    s = <<END * 2 << e << t
END
    s << ((e + <<END) * 2)[4..-1]
    "<pre>" + h(s) + "</pre>"
  end
end
Ramaze.start
END
    "<pre>" + h(s) + "</pre>"
  end
end
Ramaze.start
$ gem install ramaze
$ ruby quine-web-service-on-ramaze.rb

そして http://localhost:7000/ を開く。

socket + ajax

eval$e=%q(puts'open http://localhost:18463';require'socket'
s=TCPServer.new 18463;c=(/GET +\/(\d*)/i=~c.gets;c<<%(HTTP\
/1.0 200 OK\nContent-Type:text/html\n\n)+(eval(%(#$1% 60>0?
%(leval$e=%q(\#$e)#)[#$1,1].sub('&','&amp;').sub('>','&gt;'
).sub('<','&lt;'):'<br>'# ;nil))||%(<title>quine web server
</title>The source code of this web server is:<pre id='p'>\
</pre><script type='text/javascript'>a=i=0;f=function(){a!=
0&&a.readyState<4||(a!=0&&(document.getElementById('p').in\
nerHTML+=a.responseText),i++<719&&(a=new XMLHttpRequest() ,
a.open('GET','/'+i,true),a.onreadystatechange=f,a.send(null
)))};f()</script>));puts$_;c.shutdown;c.read;c.close)while\
c=s.accept ## quine-web-server.rb (c) Yusuke Endoh 2009 #)#
$ ruby quine-web-server.rb
open http://localhost:18463/