Skip to content

Instantly share code, notes, and snippets.

@tompng
Last active June 30, 2019 13:52
Show Gist options
  • Save tompng/1b562cd62b56546cf3e8069cb7c6d239 to your computer and use it in GitHub Desktop.
Save tompng/1b562cd62b56546cf3e8069cb7c6d239 to your computer and use it in GitHub Desktop.

Hackers Champloo 2019 LT資料

発表スライドはこちら https://www.slideshare.net/tomoyaishida1238/hcmpl2019lt-152588196

自己紹介コード

https://github.com/tompng/tompng

「意味不明で楽しい」用コード

tanosii.rb

Quineとは

quine3.rb

Quineの書き方・アスキーアート化

quine1.rb quine2.rb quineaa.rb

変化するQuine

htag_generator.rb htag_out.rb

動くイカのQuine

https://twitter.com/tompng/status/1134841262165544960 https://gist.github.com/tompng/842616aa61b2b2cb6af52b0389ef3799

遊べるQuine

https://twitter.com/tompng/status/711904121880596480 https://gist.github.com/tompng/989e46a2c36037eaf2b9

記号プログラミング

kigou.rb

ランダムに作った文字列のeval

srand_gen.rb srand_out.rb

ワイングラス3Dデータ生成コード

https://gist.github.com/tompng/c87ff0b298867491ce47343fe9a5a4e2

実行可能な画像

https://github.com/tompng/hcmpl_img_gen

アスキーアートQuineの説明に使う予定だったコード

logo_generator.rb logo_out.rb

スライド背景に使う予定だった記号だらけのコードを生成するコード

randcode.rb

nums = DATA.read.split(/\n\n/).map{|a|
lines = a.lines.map{|a|a.delete("\n")}.reject(&:empty?)
lines.map{|a|(a+' '*8)[0,8]}.join.chars.map{|a|
a==' '?0:1
}.join.reverse.to_i(2)
}
res=4
code = %(
c=%w(
s=("c=%%w(%s);n=%d;eval(c*='')"%[c,(n+1)%6]).chars;
(0..#{res*5-1}).each{|y|
puts((0..#{res*8-1}).map{|x|
#{nums}[n][y/#{res}*8+x/#{res}]>(n>4&&(x<10||y>14)?-1:0)?(s.shift||?#):32.chr
}.join.gsub(/#[#]+/){|a|('#hcmpl'*9)[0...a.size]})
}
);n=0;eval(c*='')
)
7.times do
puts code
puts
code = IO.popen(['ruby', '-e', code], &:read)
rescue => e
puts code
p e
end
File.write 'htag_out.rb', code
__END__
## ##
########
## ##
########
## ##
## ##
## ##
########
## ##
## ##
######
## ##
##
## ##
######
## ##
### ###
########
## ## ##
## ##
#######
## ##
#######
##
##
##
##
##
##
########
c=%w(s=( "c=%%w(%
s);n=%d; eval(c*=
'')"%[c, (n+1)%6]
).chars; (0..19).
each{|y|puts((0..31).map{|x|[442
371604326,840806941635,544437683
070,841209604035,12943606655,109
5267189507][n][y/4*8+x/4]>(n>4&&
(x<10||y >14)?-1:
0)?(s.sh ift||?#)
:32.chr} .join.gs
ub(/#[#] +/){|a|(
'#hcmpl'*9)[0...a.size]})});n=1;
eval(c*='')#hcmpl#hcmpl#hcmpl#hc
#hcmpl#hcmpl#hcmpl#hcmpl#hcmpl#h
#hcmpl#hcmpl#hcmpl#hcmpl#hcmpl#h
#hcmpl#h #hcmpl#h
#hcmpl#h #hcmpl#h
#hcmpl#h #hcmpl#h
#hcmpl#h #hcmpl#h
____=[*%= =..?~];_=-~-~$$-$$;___=_*__=_+_;_____=__*__+___**_
_=[____[_____+_],____[_____+__+_/_],____[___*___+_],____[+_/
_+_____+___],____[_-_],____[_____/(_+__)],____[___*___+__+_/
_],____[_-_],____[_],____[_____],____[_____+__+_/_],____[__+
_____],____[_____+_+_/_],____[_-_],____[___-_/_],____[~-__],
____[_____-___],____[___*___+_+_/_],____[_____-__+_/_],____[
_____],____[_____-__],____[___-_/_],____[_]]*%>>;$>.<<`#{_}`
require 'chunky_png'
require 'pry'
img = ChunkyPNG::Image.from_file 'logo_input.png'
h = 24
w = 48
a = []
h.times do |y|
line = w.times.map do |x|
col = img[x * img.height / w+40, y * img.height / h]
col & 0xff00 == 0 ? ' ' : '#'
end.join
line.gsub!(/# +#/) { |a| '#' * a.size }
next unless line.include? '#'
a << [line.scan(/^ */).first.size, line.scan(/#+/).first.size]
puts line
end
QUINE_STR = %(c=%(s='c=%('+c+');eval c';puts s);eval c)
QUINE_ARR = %(c=%w(s='c=%w('+c+').join;eval(c)';puts(s)).join;eval(c))
a.push a.pop.tap {|a|a[1]-=15}
a[0]=[0,10]
QUINE_FMT = %(
c=%w(
s=('c=%w(' + c + '%(' + 'HackersChamploo' * 99).chars;
lines = #{a}.map { |num_spaces, num_chars|
32.chr * num_spaces + s.shift(num_chars).join
};
lines[-1] += ')).join;eval(c)';
puts(lines);
).join;
eval(c)
)
code = IO.popen(['ruby', '-e', QUINE_FMT], &:read)
File.write 'logo_out.rb', code
raise if File.read('logo_out.rb') != `ruby logo_out.rb`
c=%w(s=('c
=%w('+c+'%('+'H
ackersChamploo'*9
9).chars;lines=[[0,10],[
0,15],[0,17],[0,24],[0,26]
,[0,27],[0,31],[0,34],[0,35
],[0,36],[0,38],[0,40],[0,40],[
0,40],[0,41],[4,38],[8,35],[11,33]
,[13,31],[13,30],[14,30],[15,30],[1
5,15]].map{|num_spaces,num_chars|32.
chr*num_spaces+s.shift(num_chars).join
};lines[-1]+=')).join;eval(c)';puts(line
s);%(HackersChamplooHackersChamplooHacke
rsChamplooHackersChamplooHackersChamploo
HackersChamplooHackersChamplooHackersCham
plooHackersChamplooHackersChamplooHack
ersChamplooHackersChamplooHackersCh
amplooHackersChamplooHackersChamp
looHackersChamplooHackersChampl
ooHackersChamplooHackersChampl
ooHackersChamplooHackersChampl
ooHackersChamplooHackersChampl
ooHackersChampl)).join;eval(c)
code=%(puts "code=%(" + code + ");eval code");eval code
c=%(puts'c=%('+c+');eval(c.split.join)');eval(c.split.join)
$><<((p=%($><<((p=%%(%s)) %% p)
STDOUT.write ')) % p)
STDOUT.write 'Hello World'
puts((p=%('
puts((p=%%(%s)) %% p))) % p)
c=%(;;;;puts'c=%('+c
+ '
) ; e val (
c .sp l i
t . j oin )
' ;
);eval(c.split.join)
def str
a = '%!/()+-'.chars.sample
return '?'+a if rand<0.2
b = a=='(' ? ')' : a
s = rand(4).times.map{('%!()+-'.chars-[a,b]).sample}.join
'%'+a+s+b
end
def reg
'/'+rand(4).times.map{'%!-'.chars.sample}.join+'/'
end
def three(level)
ex(rand(0..level), true)+'?'+ex(rand(0..level))+':'+ex(rand(0..level))
end
def fmt(level)
a=nil
loop do
a=ex(rand(0..level));
break unless eval(a)=~/%/
rescue
end
a+'%'+ex(rand(0..level))
end
def ex(level, r=false)
return r && rand < 0.2 ? reg : str if level <= 0
rand < 0.5 ? three(level-1) : fmt(level - 1)
end
codes = 1000.times.map{|i|ex rand(6)}.group_by(&:size);
(2..64).each do |i|
puts codes[i].first if codes[i]
end
s=File.read('srand_out.rb').chars.uniq.sort.map(&:ord)
ts = [' 2019', ':cham', ':ploo', ':cmpl'].map{|s|
[s.chars.map(&:ord), 1]
}.to_h
[0,1,2,3].each do |i|
fork{
n=80000000+i;
while true
n+=4
puts n if n/4 % 1000000 == 0
srand n
next if s.sample != 112
c2 = s.sample
next if c2 != 32 && c2 != 58
t = [c2, s.sample, s.sample, s.sample, s.sample]
puts "#{n}: p#{t.map(&:chr).join}" if ts[t]
end
p :done
}
end
sleep
4400712323 # p 2019
10408177576 # p:cham
10151102579 # p:ploo
10600000000
[10408177576,10151102579,
4400712323].map{|s|srand(
s);send :eval,(1..6).map{
File.read(__FILE__).chars
.uniq.sort.sample;}.join}
def self.method_missing(a,*b)(!b[0]&&$a)?
(puts(($a*'').upcase);exit):$a=[a,*b];end
imi fumei
imi fume ifum
imi fum eif
imi fum
imi eif
imi ume
imi ifu
imi mei #=> IMIFUMEI
def self.method_missing(a,*b)(!b[0]&&$a)?
(puts(($a*'').upcase);exit):$a=[a,*b];end
ta no si i
tatatata nononon si ii ii
ta no no no si ii ii
ta tata no no no si ii ii
ta no no no si si ii i ii
ta tata no no sisis iii
#=> TANOSII
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment