Rabbit Slide Show

My Ruby tools for AtCoder

Description

自作のAtCoder用Rubyツールの紹介スライドです。

Text

Page: 1

My Ruby tools for
AtCoder
QWYNG(大澤広朗)
SmartHR LT会 May, 2024
Powered by Rabbit 3.0.3 and COZMIXNG

Page: 2

AtCoderにRubyで参加する
AtCoder: 競技プログラミングのコンテストを
開催しているサービス
https://atcoder.jp
Rubyで参加する際に利用している自作ツール
の自慢をします
Rubyを使ったアルゴリズムの解説はしません

Page: 3

AtCoderに参加するときの流れ
1. サンプル入出力からテストを生成する
2. 問題を解く
3. デバックする
4. テストを通す
5. 提出
1 と 3 で自作ツールを使っています

Page: 4

サンプル入出力からテストを生成する
green_day
https://github.com/QWYNG/green_day
自作のスクレイピングツール
問題の入出力からテストを自動生成してくれます
コンテスト開催中等クッキーが必要な場合にも対応し
ています

Page: 5

green_dayのデモ(1)
abc150a

Page: 6

green_dayのデモ(2)
$ bundle exec green_day new abc150
abc150
├── A.rb
├── B.rb
├── C.rb
├── D.rb
├── E.rb
├── F.rb
└── spec
├── A_spec.rb
├── B_spec.rb
├── C_spec.rb
├── D_spec.rb
├── E_spec.rb
└── F_spec.rb

Page: 7

green_dayのデモ(3)
RSpec.describe 'abc150/A.rb' do
it 'test with "2 900\n"' do
io = IO.popen('ruby abc150/A.rb', 'w+')
io.puts("2 900\n")
io.close_write
expect(io.readlines.join).to eq("Yes\n")
end
it 'test with "1 501\n"' do
io = IO.popen('ruby abc150/A.rb', 'w+')
io.puts("1 501\n")
io.close_write
expect(io.readlines.join).to eq("No\n")
end
it 'test with "4 2000\n"' do
io = IO.popen('ruby abc150/A.rb', 'w+')
io.puts("4 2000\n")
io.close_write
expect(io.readlines.join).to eq("Yes\n")
end
end

Page: 8

デバックする (1)
テストで入出力をキャプチャしているので REPL
が動かない
> rspec abc150/spec/A_spec.rb
FFF
Failures:
1) abc150/A.rb test with "2 900\n"
Failure/Error: expect(io.readlines.join).to eq("Yes\n")
~~~~~~~~ snip ~~~~~~~~
(compared using ==)
Diff:
@@ -1,9 +1,18 @@
+
+From: abc150/A.rb @ line 3 :
+
+
1: k, x = gets.split.map(&:to_i)
+
2: check_complition = '予測変換もいい感じになってほしいなぁ'
+ => 3: binding.irb
+
4: puts k * 500 >= x ? 'Yes' : 'No'
+Switch to inspect mode.
+
Yes

Page: 9

デバックする (2)
リモートプロセスの IRB を別のプロセスから操
作することができる Gem を作りました
https://github.com/QWYNG/irb-remote

Page: 10

irb-remoteのデモ(1)
irb-remote

Page: 11

irb-remoteの先行研究
dRubyを使ってオブジェクトをプロセス間でや
りとりしています
dRubyでREPLを行う発想は先人の方を参考に
したものです
https://github.com/Mon-Ouie/pry-remote
https://github.com/iguchi1124/irb_remote
今回は Reline を使いたかったので自作しました

Page: 12

まとめ
皆さんもぜひ使ってみてください
Powered by Rabbit 3.0.3 and COZMIXNG

Other slides