Skip to content

Instantly share code, notes, and snippets.

@mame

mame/README.md Secret

Last active October 28, 2023 09:42
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mame/9833a830b08afb5fa36917f58cd4fbe3 to your computer and use it in GitHub Desktop.
Save mame/9833a830b08afb5fa36917f58cd4fbe3 to your computer and use it in GitHub Desktop.
$ curl -O https://gist.githubusercontent.com/mame/9833a830b08afb5fa36917f58cd4fbe3/raw/b821e491070580f49ff9c420c73f5e6f6dc5953a/kaigi-on-rails-quine.rb

$ ruby kaigi-on-rails-quine.rb
Run this again!

$ ruby kaigi-on-rails-quine.rb

+----------------------------+
| open http://localhost:3000 |
+----------------------------+

Puma starting in single mode...
* Puma version: 6.4.0 (ruby 3.2.2-p53) ("The Eagle of Durango")
*  Min threads: 0
*  Max threads: 5
*  Environment: development
*          PID: 49524
* Listening on http://0.0.0.0:3000
Use Ctrl-C to stop
require "bundler/inline"
begin
gemfile do
source "https://rubygems.org"
gem "rails"
gem "turbo-rails"
gem "rack", "~>2.0"
gem "puma"
end
rescue Gem::LoadError
if $!.message =~ /You have already activated/
puts "Run this again!"
exit
end
raise
end
eval$s=%q!eval((%w\requ
ire"action_controller/railtie";class~A<Rails:
:Application;Rails.logger=Logger.new(STDOUT);routes.draw{ge
t"/"=>redirect("/1");get"/:q"=>"c#i";get"/:q/:x"=>"c#u"}end;n=0;"V7j:
lmHp&2SJ=_Q$bECj5Aab<E4E9?L{OHqU>{:f'-l%uNMeeAs(HRc;31IBMjPNbPF$A2*UYF}#eT_pr
[2n,yZ2[Wx#oV>.'etU=>F=lkX3VMn$seur*{hsMrnhMaKm8(bP,$da44n],XwZJzp95<([Qx@ShMoa:w3,$P
3Ba;6<%o?p5/fK9NL''XcdsO;PmCLD93PjLpf/8.jsM6I$@,?pyvO?.%9YT_7$KA*PNw^|s??=0WA%C^Bk'TYZRSfn#
hJ0,D$#EN&B$-ACd&'<zC@V]NpuSvuO5x;-<'j,G5w7cUh^DvSbUvayPcV)qk+`4]j|2/N`,[}i,i:XT,cHM0Jym([-nO,x|n
W=ZVtJIVYl-b6f%I==%$7PAdD^$91qSE{gF=tL1e>JN(NO]N:X zb`j*=0U>VYjphZhSiR?I5<6x1.,-%{I'C".bytes{|m|n=n*9
0+-m%91};f=->{n%(n/=2;2)>0?1:f[]*2+n%(n/=2;2)};g=- >{x=f[];x/2*(1-x%2*2)};x=0;P,Q,R,S,*M=(0..220).map
{x+=g[]}.pack("U*").split(B=33.chr);D=M.map{|s|s.bytes};F="turbo-frame";s="GrE:iWePFMidNWfonYmat:8TthtUdiigan
:1orV;iovXn:Zntemi@keyframes~r{0%{trQsfSm:rotaY(- 90deg)}100%{trQsfSm:rotaY(0deg)}}*{padOng:0;JrgC0
}html{touch-acGmQipulaNn}body{background:whiY;Hnt-size:3TcolS:#333;Yxt-alPWceIr;hDhtR00vh}HoYr{posiGsticky;topR00vh}p
re{JrgC3TYxt-alPWleft;Hnt-sizeRV}Ov.b{JrgC8V~0}Ov.r{Osplay:flex;flex-OrecAow;justify-coInKceIr}a.c{hDhKLtrQsfSm-SPC4V~4
TbSderRpx~solF~#333}svg{wBLhDhKLQiJA~0.3s~bo M}img{wB90T}";(?A..?Z).map{|x|s=s[2..].gsub(
x,s[0,2])};U=s;class~CController<ActionCon troller::Base;def~g(t,k={})"<#{t}~#{k.map{
|k,v|"#{k}='#{v}'"}*""}>#{yield}</#{t}>"end;def~q;(params[:q].to_i-1).clamp(0,3)end;def~i;render~inline:"<#{B}DOCTYPE~html>"+
g(:html,lang:"ja"){g(:head){g(:title){"Kaigi~on~Rails~Quine"}+g(:style){U}+g(:script,type:"module"){"import~h~from~'https://c
dn.jsdelivr.net/npm/@hotwired/turbo@7.3.0/+esm'"}}+g(:body){params[:q]==?q?g(:pre){Rack::Utils.escape_html('require~"bundler/in
line"CCbeginCSgemfile~doCSSsourc e~"https://rubygems.org"CSSgem~"
rails"CSSgem~"turbo-rails"CSS gem~"rack",~"T>2.0"CSSgem~"pu
ma"~CSendCrescue~Gem::Load ErrorCSif~$B.message~=T~/Y
ou~have~already~activated/CSS puts~"Run~this~againB"CSSexit
CSendCSraiseCendCC'.tr("BCT",B+1 0.chr<<126).gsub(?S,"~~")+"~"*52
+"eval$s=%q"+B+$s+B+"#Y.E.")}:g(:h1 ){"Rails~Game"}+g(:h2){"Stage~#{q<3
?q+1:??}"}+g(:div,class:?b){w,h=D[q]; (0...h).map{|y|g(:div,class:?r){(0...
w).map{|x|s=s(x+y*w);0<x&&x<w-1?g(:a,cla ss:?c,href:"/#{q+1}/#{x+y*w}","data-turb
o-stream":true){g(F,id:"x#{x+y*w}"){s}}:s} *""}}*""}+g(F,id:?m,"data-turbo":false){P}
}+g(:footer){"#~(C)~2023~STORES,~Inc.~/~Powe red~by~Ruby~on~Rails~and~Hotwire"}}end;def~s
(x)w,h=D[q];a=D[q][x+2];g(:svg,viewBox:"0~0~10 ~10",xmlns:"http://www.w3.org/2000/svg"){g(:g,
transform:"rotate(#{a%4*90},5,5)"){g(t=:path,d:( 0..3).map{|i|a<4?(c,s=Complex.polar(1,Math::PI/8
*(i+0.5)).rect;"M#{c*3},#{s*3}L#{c*7},#{s*7}"):a< 8?"M3,#{(i+0.5)*2.5}L7,#{(i+0.5)*2.5}":""}*"",str
oke:'brown'){}+g(t,d:a<4?"M6,0A6,6,0,0,1,0,6M4,0A4 ,4,0,0,1,0,4":a<8?"M4,0L4,10M6,0L6,10":"",stroke:'
gray',"stroke-width":0.6,fill:'transparent'){}}}end ;def~u;x=params[:x].to_i;w,h=f=D[q];s=f[x+2];f[x+2]
=s&12|(s+1)%4;s=2;s+=w~while~f[s]==8;d=0;(v=f[s+=(t=1-d)%2*t+d%2*(2-d)*w];d=v&&(v<4?(d-v)%4/2==0&&3[d
-v*2&3]*2+1-d%2:v<8&&(v^d)&1>0&&d))while~d&&(s-1)%w>0;g=->t,&b{g("turbo-stream",action:"update",t
arget:t){g(:template,&b)}};render~inline:g.("x#{x}"){s(x)}+(d~?g.(?m){q<2?g(:p){Q+g(:a,href
:"/#{2+q}"){R}}:q<3?S+"<img~src='https://user-images.githubusercontent.com/21557/2765
81952-58e8b644-47c7-4537-8c61-74c050d7b950.png'>":~"<a~href='/q'>Welcome~to~Q
uine</a>"}:""),content_type:"text/vnd.turbo-stream.html"end;end;puts"
",v=?++?-*28+?+,"|~open~http://localhost:3000~|",v,"";Rack:
:Server.start~app:Rails.application,Port:3000
\*'').tr(?~,?\s))!#Y.E.
# (C) 2023 STORES, Inc. / Powered by Ruby on Rails and Hotwire
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment