Rabbit Slide Show

My way with Ruby

2018-06-01

Description

Here are my activities as a Rubyist: * Increase what Ruby can do with free software * Maintain libraries In this talk, I introduce my activities.

Text

Page: 1

My way with Ruby
Kouhei Sutou
ClearCode Inc.
RubyKaigi 2018
2018-06-01
My way with Ruby
Powered by Rabbit 2.2.2

Page: 2

Ad: Silver sponsor
My way with Ruby
Powered by Rabbit 2.2.2

Page: 3

Acknowledgment
感謝
@drbrain
Eric Hodel
He fixed English in this slide
英語をチェックしてくれたよ!ありがとう!
My way with Ruby
Powered by Rabbit 2.2.2

Page: 4

Keynote-ish topic
キーノートっぽい話題
Did you think
about it?
考えたことある?
My way with Ruby
Powered by Rabbit 2.2.2

Page: 5

Keynote-ish topic1
キーノートっぽい話題1
Future
未来のこと
My way with Ruby
Powered by Rabbit 2.2.2

Page: 6

Keynote-ish topic2
キーノートっぽい話題2
Focus on
one thing
deeply
なにかを深掘り
My way with Ruby
Powered by Rabbit 2.2.2

Page: 7

Keynote-ish topic3
キーノートっぽい話題3
Overview
俯瞰した話
My way with Ruby
Powered by Rabbit 2.2.2

Page: 8

My activities
as a Rubyist
私のRubyist活動
✓ Increase what Ruby can do
with free software
フリーソフトウェアを使ってRubyでできることを増やす
✓ Maintain libraries
ライブラリーのメンテナンス
My way with Ruby
Powered by Rabbit 2.2.2

Page: 9

# of libraries maintained
メンテナンスしているライブラリー数
About 130
130くらい
My way with Ruby
Powered by Rabbit 2.2.2

Page: 10

Today's topic
今日の話題
Overview
what we can do
with Ruby
Rubyでできるようになったことをたくさん紹介
My way with Ruby
Powered by Rabbit 2.2.2

Page: 11

How to find targets?
そんなにネタがあるの?
Just I needed
単に自分が必要だったから
My way with Ruby
Powered by Rabbit 2.2.2

Page: 12

Opening1
きっかけ1
Web feed
Webフィード
My way with Ruby
Powered by Rabbit 2.2.2

Page: 13

RSS Parser
RSS/Atom parser
with
validation
バリデーション機能付きのRSS/Atomパーサー
My way with Ruby
Powered by Rabbit 2.2.2

Page: 14

RSS Parser - History
歴史
✓ 2003-05: The first release
最初のリリース
✓ No other RSS/Atom parser that
supports validation even now
今でもバリデーション付きのパーサーは他にない
✓ 2004-01: Ruby bundles this
RubyがRSS Parserをバンドル
✓ I became a Ruby committer
Rubyコミッターになる
My way with Ruby
Powered by Rabbit 2.2.2

Page: 15

Validate RSS/Atom
RSS/Atomのバリデーション
✓ Important for me
私にとっては大事
✓ Most wild RSS/Atom feeds are
invalid
野生のRSS/Atomの多くは不正
✓ Validation helps to find problems
バリデーションがあると問題を見つけやすくなる
My way with Ruby
Powered by Rabbit 2.2.2

Page: 16

RSS::Parser.parse
# Validates by default
# デフォルトでバリデーション
RSS::Parser.parse(rss)
# Validation can be disabled
# 無効にできる
RSS::Parser.parse(rss, false)
My way with Ruby
Powered by Rabbit 2.2.2

Page: 17

Since Ruby 2.6
Ruby 2.6以降
# Supports keyword argument
# キーワード引数対応
parse(rss, validate: false)
My way with Ruby
Powered by Rabbit 2.2.2

Page: 18

REXML
XML parser
written in
pure Ruby
Ruby実装のXMLパーサー
My way with Ruby
Powered by Rabbit 2.2.2

Page: 19

REXML - History
歴史
✓ 2001: Started by Sean Russell
Seanさんが開発を開始
✓ Based on Electric XML (Java)
Java実装のElectric XMLを参考に開発
✓ REXML is "Ruby Electric XML"
REXMLは「Ruby Electric XML」
✓ 2003-01: Ruby bundles this
RubyがREXMLをバンドル
My way with Ruby
Powered by Rabbit 2.2.2

Page: 20

REXML - Side story
おまけ話
✓ Sean was "書運" in Kanji
Seanさんには「書運」という漢字表記があった
✓ He was interested in Japan
日本好きだった
✓ "How to write your name in Kanji?"
「君の名前は漢字でどう書くの?」
✓ We can connect with Ruby!
RubyistはRubyをきっかけにつながれる!
My way with Ruby
Powered by Rabbit 2.2.2

Page: 21

Ad: Code Party
宣伝:コード懇親会
My way with Ruby
Powered by Rabbit 2.2.2

Page: 22

Ad: Code Party
宣伝:コード懇親会
This is a challenge
実験的な企画
✓ Ruby focus: to have fun
Rubyは楽しさを大事にしている
✓ We have fun writing Ruby
Rubyistは楽しくRubyを書いている
✓ We have fun together with
writing Ruby at after party!?
だったら懇親会で一緒にRubyを書くと楽しそう!?
My way with Ruby
Powered by Rabbit 2.2.2

Page: 23

Ad: Code Party
宣伝:コード懇親会
✓ Matz attends Code Party
まつもとさんもコード懇親会に参加
✓ Sponsored by Speee, Inc.
Speeeさんがスポンサー
My way with Ruby
Powered by Rabbit 2.2.2

Page: 24

REXML - Recent1
最近1
✓ 2010-08: RubyKaigi 2010
✓ I became the maintainer
私がメンテナーになった
✓ Because RSS Parser uses it
RSS Parserが使っているから
My way with Ruby
Powered by Rabbit 2.2.2

Page: 25

REXML - Recent2
最近2
✓ 2016: element[attribute_name]
✓ Ruby 2.5 ships it
Ruby 2.5以降で使える
My way with Ruby
Powered by Rabbit 2.2.2

Page: 26

REXML - Recent3
最近3
✓ 2018: Fix XPath related bugs
XPath関連のバグ修正
✓ Ruby 2.6 ships it
Ruby 2.6以降で使える
My way with Ruby
Powered by Rabbit 2.2.2

Page: 27

REXML - Future?
未来はあるの?
✓ Pure Ruby is valuable
Rubyだけで書かれていることには価値がある
✓ Easy to install
インストールが簡単
✓ JIT may improve performance
NOTE: We should improve general logic before we
expect JIT to improve performance
JITで速くなるかもしれない
JITの前に普通にロジックを改良するのが先だけどね
My way with Ruby
Powered by Rabbit 2.2.2

Page: 28

Recent my works
最近の仕事
✓ XML/HTML libraries for LuaJIT
LuaJIT用のXML/HTMLライブラリー
✓ XMLua: https://clear-code.github.io/xmlua/
libxml2 based XML/HTML parser
✓ LuaCS: https://clear-code.github.io/luacs/
CSS Selectors→XPath converter
✓ Found what is lacking in
REXML API
REXMLのAPIに足りないものはなにか考えた
My way with Ruby
Powered by Rabbit 2.2.2

Page: 29

REXML - Future1
未来1
Introduce
NodeSet
NodeSetが足りないんじゃないか
My way with Ruby
Powered by Rabbit 2.2.2

Page: 30

REXML - NodeSet
doc.
search("//list"). # => NodeSet
search("item"). # => All <item> in <list>
text # All texts in <item> in <list>
My way with Ruby
Powered by Rabbit 2.2.2

Page: 31

REXML - Future2
未来2
Support
CSS Selectors
CSSセレクターが足りないんじゃないか
My way with Ruby
Powered by Rabbit 2.2.2

Page: 32

REXML - CSS Selectors
CSSセレクター
doc.css_select("ul li, dl dt")
My way with Ruby
Powered by Rabbit 2.2.2

Page: 33

REXML - Future3
未来3
Support
HTML5 support
HTML5対応が足りないんじゃないか
My way with Ruby
Powered by Rabbit 2.2.2

Page: 34

REXML - HTML5
doc = REXML::HTML5Document.new(html5)
doc.search("//li")
doc.css_select("ul li")
My way with Ruby
Powered by Rabbit 2.2.2

Page: 35

REXML - Future
未来
✓ Low priority in my activities
優先度は高くない
✓ Do you want to work with me?
一緒にやりたい人はいる?
My way with Ruby
Powered by Rabbit 2.2.2

Page: 36

Opening2
きっかけ1
Presentation
プレゼンテーション
My way with Ruby
Powered by Rabbit 2.2.2

Page: 37

Rabbit
Presentation tool
Rubyist
for
Rubyist用のプレゼンツール
My way with Ruby
Powered by Rabbit 2.2.2

Page: 38

Rabbit - History
歴史
✓ 2004-07: The first release
最初のリリース
✓ No other presentation tool for a
Rubyist even now
今でもRubyist用のプレゼンツールは他にない
✓ 2010: Matz migrated to Rabbit
まつもとさんがRabbitに乗り換えた
✓ Since RubyKaigi 2010?
RubyKaigi 2010から?
My way with Ruby
Powered by Rabbit 2.2.2

Page: 39

For Rubyist?
Rubyist向けに必要なもの
RD support
RDサポート
My way with Ruby
Powered by Rabbit 2.2.2

Page: 40

RD
✓ Ruby Document
✓ Designed by Matz
(Right?)
まつもとさんがデザインしたはず
✓ A text based markup language
テキストベースのマークアップ言語
✓ Version controllable
バージョン管理できる
My way with Ruby
Powered by Rabbit 2.2.2

Page: 41

For Rubyist?
Rubyist向けに必要なもの
Publish
our slides
as usual
いつも通りスライドを公開できる
My way with Ruby
Powered by Rabbit 2.2.2

Page: 42

Publish as usual
いつも通り公開
% gem push your-slide-1.0.gem
My way with Ruby
Powered by Rabbit 2.2.2

Page: 43

Published!
公開完了!
https://slide.rabbit-shocker.org/
My way with Ruby
Powered by Rabbit 2.2.2

Page: 44

What's needed for
presentation tool?
プレゼンツールに必要なもの
GUI
My way with Ruby
Powered by Rabbit 2.2.2

Page: 45

Ruby/GTK3
Multi-platform
GUI toolkit
複数プラットフォーム対応GUIツールキット
My way with Ruby
Powered by Rabbit 2.2.2

Page: 46

Ruby/GTK3 - History
歴史
✓ 1998-01: 1st release by Matz
[ruby-list:5877]
まつもとさんが最初のリリース
✓ 2004-05: I joined development
私が開発に参加
My way with Ruby
Powered by Rabbit 2.2.2

Page: 47

Example - Window
require "gtk3"
app = Gtk::Application.new
app.signal_connect(:activate) do
window = Gtk::ApplicationWindow.new(app)
window.show_all
end
app.run
My way with Ruby
Powered by Rabbit 2.2.2

Page: 48

Approaches on
missing libraries(1)
ライブラリーがない時のやり方(1)
1. Implement only the needed
features
必要な機能だけ実装
2. then back to Rabbit
必要な機能ができたらRabbitに戻る
My way with Ruby
Powered by Rabbit 2.2.2

Page: 49

Approaches on
missing libraries(2)
ライブラリーがない時のやり方(2)
1. Implement not only the
needed features
必要な機能だけじゃなく
2. but also
almost
ほぼすべての機能を実装
all features
3. then back to Rabbit
終わったらRabbitに戻る
My way with Ruby
Powered by Rabbit 2.2.2

Page: 50

My approach
私のやり方
Implement
all features
testing with Rabbit
すべての機能を実装
My way with Ruby
Powered by Rabbit 2.2.2

Page: 51

My priority
私の優先度
✓ Rabbit is important
Rabbitは大事だけど
✓ Increasing what Ruby can do
is important too
Rubyでできることを増やすのも大事
My way with Ruby
Powered by Rabbit 2.2.2

Page: 52

GTK+ 3 - Size
サイズ
3000 over APIs
3000以上のAPI
My way with Ruby
Powered by Rabbit 2.2.2

Page: 53

How to implement
実装方法
Handwriting
↓
Auto generation
手書き
自動生成
My way with Ruby
Powered by Rabbit 2.2.2

Page: 54

Ruby/GI
Generate bindings
automatically
at
run-time
実行時に自動でバインディングを生成
GI: GObject Introspection
My way with Ruby
Powered by Rabbit 2.2.2

Page: 55

Ruby/GI - History
歴史
✓ 2012: The first commit by me
最初のコミット
✓ 2014: Ruby/GTK3 used Ruby/GI
Ruby/GTK3をRuby/GIベースに移行
My way with Ruby
Powered by Rabbit 2.2.2

Page: 56

Handwriting
手書き
Handwritten bindings
libgtk-3
Ruby/GTK3
Ruby
script
Ruby
C
My way with Ruby
Powered by Rabbit 2.2.2

Page: 57

Auto generation
自動生成
Generated at run-time
libgtk-3
Ruby/GTK3
Gtk-3.0.typelib
Ruby
script
Ruby/GI
GI = GObject Introspection
My way with Ruby
Ruby
C
Data
Powered by Rabbit 2.2.2

Page: 58

Performance (性能)
✓ Slower than handwriting
手書きより遅い
✓ Overhead
オーバーヘッド
✓ Dynamic arguments conversion
動的な引数の変換
✓ libffi based function call
libffiを使った関数呼び出し
My way with Ruby
Powered by Rabbit 2.2.2

Page: 59

Improve idea (改善案)
JIT compiling
JITコンパイル
My way with Ruby
Powered by Rabbit 2.2.2

Page: 60

JIT compiling (JITコンパイル)
VALUE rb_method_generic() {
func = dlsym(name); ...
ffi_call(func, ..., &result);
return C2RB(result);
} ↓
// Build rb_method() at run-time and call it.
VALUE rb_method() {return C2RB(name(...));}
My way with Ruby
Powered by Rabbit 2.2.2

Page: 61

Ruby/GI - See also
参考情報
✓ "How to create bindings
2016" at RubyKaigi 2016
✓ http://rubykaigi.org/2016/presentations/ktou.html
✓ "GI Introduction"
(in Japanese)
「GObject Introspection入門」
✓ https://github.com/RubyData/workshop-materials/
blob/master/gobject-introspection/introduction.md
✓ Build system: Meson + Ninja
ビルドシステム:Meson + Ninja
My way with Ruby
Powered by Rabbit 2.2.2

Page: 62

Ruby/GI based bindings
Ruby/GIベースのバインディング
Ruby/Pango
My way with Ruby
Powered by Rabbit 2.2.2

Page: 63

Ruby/Pango
Text layout engine
with
i18n
support
国際化対応のテキストレイアウトエンジン
i18n: Internationalization
My way with Ruby
Powered by Rabbit 2.2.2

Page: 64

Prohibition processing
禁則処理
widget.signal_connect(:draw) do |_, context|
layout = context.create_pango_layout
layout.text = "Helloこんにちは。 "
context.show_pango_layout(layout)
GLib::Source::CONTINUE
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 65

Bidirectional text
双方向テキスト
Hello
‫ا‬ ‫ب‬ ‫ح‬ ‫ر‬ ‫م‬
こんにちは
My way with Ruby
Powered by Rabbit 2.2.2

Page: 66

Ruby/GI based bindings
Ruby/GIベースのバインディング
Ruby/GdkPixbuf2
My way with Ruby
Powered by Rabbit 2.2.2

Page: 67

Ruby/GdkPixbuf2
Image
manipulation
画像操作
My way with Ruby
Powered by Rabbit 2.2.2

Page: 68

Half image
画像を半分に
require "gdk_pixbuf2"
# Load an image: Format is auto detected
pixbuf = GdkPixbuf::Pixbuf.new(file: "x.png")
# Scale to half size
half = pixbuf.scale(pixbuf.width / 2,
pixbuf.height / 2,
:bilinear)
# Save as different format
half.save("half.jpg")
My way with Ruby
Powered by Rabbit 2.2.2

Page: 69

Animated GIF
アニメーションGIF
My way with Ruby
Powered by Rabbit 2.2.2

Page: 70

Ruby/GI based bindings
Ruby/GIベースのバインディング
Ruby/Poppler
My way with Ruby
Powered by Rabbit 2.2.2

Page: 71

Ruby/Poppler
PDF
parser/renderer
PDFパーサー・レンダラー
My way with Ruby
Powered by Rabbit 2.2.2

Page: 72

Text extraction
テキスト抽出
require "poppler"
doc = Poppler::Document.new("x.pdf")
doc.each do |page|
puts(page.text) # Extract all texts
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 73

Embed PDF
PDFの埋め込み
Improve extension API
C++ as better language for extension
Kouhei Sutou
ClearCode Inc.
RubyKaigi 2017
2017-09-18
Improve extension API - C++ as better language for extension
Powered by Rabbit 2.2.2
http://rubykaigi.org/2017/presentations/ktou.html
My way with Ruby
Powered by Rabbit 2.2.2

Page: 74

Ruby/GI based bindings
Ruby/GIベースのバインディング
Ruby/GStreamer
My way with Ruby
Powered by Rabbit 2.2.2

Page: 75

Ruby/GStreamer
Audio/Video
player
音声・動画プレイヤー
(*) Streaming media framework
本当はストリーミングメディアフレームワーク
My way with Ruby
Powered by Rabbit 2.2.2

Page: 76

Camera (カメラ)
require "gst"
description = [
"autovideosrc", # Camera
"videoconvert", # Filter
"autovideosink", # Window
].join(" ! ")
pipeline = Gst.parse_launch(description)
pipeline.play
until pipeline.bus.poll.type.eos? do
end # Main loop
pipeline.stop
My way with Ruby
Powered by Rabbit 2.2.2

Page: 77

Face detection (顔認識)
description = [
"autovideosrc", # Camera
"videoconvert", # Filter
"facedetect",
# Face detection (!)
"videoconvert", # Filter
(!)
"autovideosink", # Window
].join(" ! ")
pipeline = Gst.parse_launch(description)
pipeline.play
My way with Ruby
Powered by Rabbit 2.2.2

Page: 78

What's needed for
presentation tool?
プレゼンツールに必要なもの
PDF output
PDF出力
My way with Ruby
Powered by Rabbit 2.2.2

Page: 79

rcairo
2D graphics
renderer
2次元画像レンダラー
My way with Ruby
Powered by Rabbit 2.2.2

Page: 80

rcairo - Outputs
出力
✓ PNG・SVG
✓ PDF
✓ Display (X/macOS/Windows)
✓ ...
My way with Ruby
Powered by Rabbit 2.2.2

Page: 81

rcairo - History
歴史
✓ 2003-10: The initial commit
最初のコミット
✓ 2005-09: I started developing
私が開発に参加
My way with Ruby
Powered by Rabbit 2.2.2

Page: 82

Red A4 PDF
赤いA4のPDFを出力
require "cairo"
include Cairo
PDFSurface.create("x.pdf", "A4") do |surface|
Context.create(surface) do |context|
context.set_source_color(:red)
context.paint
end
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 83

rcairo - GC
1000.times do
Cairo::ImageSurface.new(:argb32, 6000, 6000)
end
15
14.5
14
13.5
13
12.5
12
11.5
11
My way with Ruby
0
100
200
300
400
500
Nth loop
600
700
800
900
1000
Powered by Rabbit 2.2.2

Page: 84

GC - Cause (原因)
✓ GC isn't run often enough
GCの実行頻度が十分じゃなかった
✓ Because Ruby doesn't know how
much memory used by cairo
Rubyはcairoのメモリー使用量を知らないから
15
14.5
14
13.5
13
12.5
12
11.5
11
My way with Ruby
0
100
200
300
400
500
Nth loop
600
700
800
900
1000
Powered by Rabbit 2.2.2

Page: 85

GC - Fix (修正)
✓ rb_gc_adjust_memory_usage()
✓ Improve GC frequency (GC実行頻度を改善)
✓ Ruby 2.4 ships it (Ruby 2.4以降)
15
14.5
14
13.5
13
12.5
12
11.5
11
My way with Ruby
0
100
200
300
400
500
Nth loop
600
700
800
900
1000
Powered by Rabbit 2.2.2

Page: 86

What's needed for
presentation tool?
プレゼンツールに必要なもの
Easy to install
簡単インストール
My way with Ruby
Powered by Rabbit 2.2.2

Page: 87

native-package-installer
Install
system packages
on gem install
gem install時にシステムのパッケージをインストール
My way with Ruby
Powered by Rabbit 2.2.2

Page: 88

extconf.rb/Rakefile
require "pkg-config"
require "native-package-installer"
unless PKGConfig.check_version?("gdk-3.0")
packages = {
altlinux: "libgtk+3-devel",
debian: "libgtk-3-dev",
redhat: "pkgconfig(gdk-3.0)",
homebrew: "gtk+3",
macports: "gtk3",
msys2: "gtk3",
}
unless NativePackageInstaller.install(packages)
exit(false)
end
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 89

rake-compiler
Build fat gem
by
cross compile
クロスコンパイルでfat gemをビルド
My way with Ruby
Powered by Rabbit 2.2.2

Page: 90

rake-compiler - History
歴史
✓ 2008-11: The first commit
最初のコミット
✓ 2014-12: Orphan
だれかメンテナー変わってー
✓ 2014-12:
I became the maintainer
私がメンテナーになった
My way with Ruby
Powered by Rabbit 2.2.2

Page: 91

Opening3
きっかけ3
Test
テスト
My way with Ruby
Powered by Rabbit 2.2.2

Page: 92

test-unit
Testing
framework
to write tests
in Ruby
Rubyでテストを書けるテスティングフレームワーク
My way with Ruby
Powered by Rabbit 2.2.2

Page: 93

test-unit - History
歴史
✓ 2003-02: Import to Ruby
Rubyに取り込まれる
✓ 2008-05:
I became the maintainer
私がメンテナーになった
✓ 2008-10: Removed from Ruby
Rubyから削除
See also: "The history of testing framework in Ruby"
http://rubykaigi.org/2015/presentations/kou
My way with Ruby
Powered by Rabbit 2.2.2

Page: 94

test-unit - New feature
新機能
Grouping
グループ化
My way with Ruby
Powered by Rabbit 2.2.2

Page: 95

Grouping
グループ化
✓ The most important feature
一番大事な機能
✓ Keep tests maintainable
メンテナンスできるテストを維持できる
My way with Ruby
Powered by Rabbit 2.2.2

Page: 96

Example (例)
class StackTest < Test::Unit::TestCase
class PushTest < self
def test_XXX; end
end
class PopTest < self
def test_XXX; end
end
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 97

Method style (メソッド形式)
class StackTest < Test::Unit::TestCase
sub_test_case("#push") do
def test_XXX; end
end
sub_test_case("#pop") do
def test_XXX; end
end
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 98

test-unit - New feature
新機能
Data driven
test
データ駆動テスト
My way with Ruby
Powered by Rabbit 2.2.2

Page: 99

Data driven test
データ駆動テスト
data("positive", [3, 1, 2])
data("negative", [-4, 1, -5])
def test_add(data)
expected, augend, addend = data
assert_equal(expected,
add(augend, addend))
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 100

test-unit - New feature
新機能
Reverse
backtrace
逆順のバックトレース
My way with Ruby
Powered by Rabbit 2.2.2

Page: 101

Reverse backtrace
逆順のバックトレース
✓ Reverse backtrace only for
terminal output
ターミナル出力のときだけ逆順
✓ The same change as Ruby 2.5.0
Ruby 2.5.0と同じ変更
My way with Ruby
Powered by Rabbit 2.2.2

Page: 102

test-unit - New feature
新機能
Test double
テストダブル
My way with Ruby
Powered by Rabbit 2.2.2

Page: 103

test-unit-rr
RR integration
RRとの統合
My way with Ruby
Powered by Rabbit 2.2.2

Page: 104

RR - History
歴史
✓ 2007-06: The initial commit
最初のコミット
✓ 2014-12: Orphan
だれかメンテナー変わってー
✓ 2015-05:
I became the maintainer
私がメンテナーになった
My way with Ruby
Powered by Rabbit 2.2.2

Page: 105

Stub (スタブ)
adder = Object.new
adder.add(1, 2) # => Error
stub(adder).add(1, 2) {3}
adder.add(1, 2) # => 3
My way with Ruby
Powered by Rabbit 2.2.2

Page: 106

Opening4
きっかけ4
Full text
search
全文検索
My way with Ruby
Powered by Rabbit 2.2.2

Page: 107

Rroonga
Full text
search
library
全文検索ライブラリー
My way with Ruby
Powered by Rabbit 2.2.2

Page: 108

Library vs Client
ライブラリー対クライアント
✓ No server process
サーバープロセスがいらない
✓ Easy to start
簡単に使い始められる
✓ Write in Ruby
Rubyで書ける
My way with Ruby
Powered by Rabbit 2.2.2

Page: 109

Create DB (データベース作成)
require "groonga"
Groonga::Database.create(path: "/tmp/db")
My way with Ruby
Powered by Rabbit 2.2.2

Page: 110

Define schema (スキーマ定義)
Groonga::Schema.define do |schema|
schema.create_table("docs") do |table|
# The column to store text
table.text("content")
end
# The index for full text search
schema.create_lexicon("terms") do |table|
table.index("docs.content")
end
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 111

Add records (レコード追加)
docs = Groonga["docs"]
docs.add(content: "String#<< concatenates ...")
docs.add(content: "String#dup duplicates ...")
My way with Ruby
Powered by Rabbit 2.2.2

Page: 112

Search (検索)
matches = docs.select do |record|
record.content.match("concat")
end
p matches.size # => 1
matches.each do |record|
p record.content # => "String#<< concat..."
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 113

User - Rabbit Slide Show
https://slide.rabbit-shocker.org/
My way with Ruby
Powered by Rabbit 2.2.2

Page: 114

User - Rurema Search
https://docs.ruby-lang.org/ja/search/
My way with Ruby
Powered by Rabbit 2.2.2

Page: 115

Rurema Search
るりまサーチ
✓ Super fast!
すごく速い!
✓ Tuned for Ruby documents
Rubyのドキュメント用にチューニング
My way with Ruby
Powered by Rabbit 2.2.2

Page: 116

User - RDoc Search
✓ Planning
考えてはいるけど。。。
✓ Do you want to work with me?
一緒にやりたい人はいる?
My way with Ruby
Powered by Rabbit 2.2.2

Page: 117

Rurema and RDoc
Project
Rurema Language
Japanese
RDoc English
My way with Ruby
Target
Japanese
Rubyists
All
Rubyists
Powered by Rabbit 2.2.2

Page: 118

Source
ソース
✓ Shared nothing
共有していない
✓ Copy based share
共有するときはコピー
✓ e.g.:
Description,
Sample codes,
...
例:説明やサンプルコードなどをコピー
My way with Ruby
Powered by Rabbit 2.2.2

Page: 119

From my point of view
私が思うこと
✓ Can we share documents?
ドキュメントを共有できないかな
✓ How to work together deeply?
もっと協力してできないかな
My way with Ruby
Powered by Rabbit 2.2.2

Page: 120

I18n
国際化
✓ Source: RDoc
ソースはRDoc
✓ For all Rubyists
これは全Rubyist向け
✓ Translate to Japanese
RDocのドキュメントを日本語に翻訳
✓ For Japanese Rubyists
これは日本人Rubyist向け
My way with Ruby
Powered by Rabbit 2.2.2

Page: 121

Add i18n support
国際化サポートを追加
✓ YARD
✓ Since 0.8.0 at 2012-04
✓ RDoc
✓ Since 4.2.0 at 2014-12
My way with Ruby
Powered by Rabbit 2.2.2

Page: 122

YARD - i18n
# Generates po/yard.pot
# po/yard.potを生成
% yard i18n
My way with Ruby
Powered by Rabbit 2.2.2

Page: 123

YARD - i18n
# Create po/ja.po from po/yard.pot
# po/yard.potからpo/ja.poを作成
% msginit \
--locale=ja_JP.UTF-8 \
--input=po/yard.pot \
--output-file=po/ja.po
My way with Ruby
Powered by Rabbit 2.2.2

Page: 124

YARD - i18n
# Translate messages in po/ja.po
# po/ja.po内のメッセージを翻訳
% editor po/ja.po
My way with Ruby
Powered by Rabbit 2.2.2

Page: 125

YARD - i18n
#
#
#
#
%
My way with Ruby
Generate documents with
translated messages
翻訳したメッセージを使って
ドキュメント生成
yard --locale ja
Powered by Rabbit 2.2.2

Page: 126

Packnga
Rake task
for
YARD i18n
YARDの国際化機能向けのRakeタスク
My way with Ruby
Powered by Rabbit 2.2.2

Page: 127

Setting
設定
# Rakefile
require "packnga"
Packnga::DocumentTask.new(spec) do |task|
task.original_language = "en"
task.translate_languages = ["ja"]
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 128

Workflow
ワークフロー
% rake reference:translate
% editor doc/po/ja/x.edit.po
% rake reference:translate
% editor lib/x.rb
% rake reference:translate
...
My way with Ruby
Powered by Rabbit 2.2.2

Page: 129

Users
ユーザー
✓ test-unit
✓ Rroonga
✓ ...
My way with Ruby
Powered by Rabbit 2.2.2

Page: 130

RDoc - i18n
# Generates doc/rdoc.pot
# doc/rdoc.potを生成
% rdoc --format=pot
My way with Ruby
Powered by Rabbit 2.2.2

Page: 131

RDoc - i18n
#
#
#
%
%
Create locale/ja.po
from doc/rdoc.pot
doc/rdoc.potからlocale/ja.poを作成
mkdir -p locale
msginit \
--locale=ja_JP.UTF-8 \
--input=doc/rdoc.pot \
--output-file=locale/ja.po
My way with Ruby
Powered by Rabbit 2.2.2

Page: 132

RDoc - i18n
# Translate messages in locale/ja.po
# locale/ja.po内のメッセージを翻訳
% editor locale/ja.po
My way with Ruby
Powered by Rabbit 2.2.2

Page: 133

RDoc - i18n
#
#
#
#
%
My way with Ruby
Generate documents with
translated messages
翻訳したメッセージを使って
ドキュメント生成
rdoc --locale ja
Powered by Rabbit 2.2.2

Page: 134

RDoc, Rurema and i18n
✓ No progress...
ツールの整備まででそれ以降は進んでいない。。。
✓ Do you want to work with me?
一緒にやりたい人はいる?
My way with Ruby
Powered by Rabbit 2.2.2

Page: 135

jekyll-task-i18n
Jekyll + i18n
My way with Ruby
Powered by Rabbit 2.2.2

Page: 136

Features
機能
✓ Support all markups!
すべてのマークアップ対応!
✓ GitHub Pages ready!
GitHub Pagesでも使える!
My way with Ruby
Powered by Rabbit 2.2.2

Page: 137

Setting (設定)
# Rakefile
require "jekyll/task/i18n"
Jekyll::Task::I18n.define do |task|
task.locales = ["ja"]
task.files = Rake::FileList["**/*.md"]
task.files -= Rake::FileList["_*/**/*.md"]
task.locales.each do |locale|
task.files -= Rake::FileList["#{locale}/**/*.md"]
end
end
task default: ["jekyll:i18n:translate"]
My way with Ruby
Powered by Rabbit 2.2.2

Page: 138

Workflow (ワークフロー)
%
%
%
%
%
My way with Ruby
editor index.md
rake
editor _po/ja/index.edit.po
rake
git commit -a
Powered by Rabbit 2.2.2

Page: 139

User - Red Data Tools
https://red-data-tools.github.io/
My way with Ruby
Powered by Rabbit 2.2.2

Page: 140

groonga-client
Full text
search
client
全文検索クライアント
My way with Ruby
Powered by Rabbit 2.2.2

Page: 141

Library vs Client
ライブラリー対クライアント
✓ Less dependencies
依存関係が少ない
✓ Less resources needed
必要なリソースが少ない
My way with Ruby
Powered by Rabbit 2.2.2

Page: 142

Search (検索)
require "groonga/client"
url = "http://localhost:10041"
Groonga::Client.open(url: url) do |client|
response =
client.select(table: "docs",
match_columns: "content",
query: "concat")
p response.n_hits # => 1
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 143

Asynchronous (非同期)
# Call with block
client.select(table: "docs",
match_columns: "content",
query: "concat") do |response|
p response.n_hits # => 1
end
p :here # => :here then ↑
sleep(0.1)
My way with Ruby
Powered by Rabbit 2.2.2

Page: 144

Asynchronous - wait
request =
client.select(table: "docs",
match_columns: "content",
query: "concat") do |response|
p response.n_hits # => 1
end
p :here # => :here then ↑
request.wait
My way with Ruby
Powered by Rabbit 2.2.2

Page: 145

groonga-client-rails
Ruby on Rails
integration
for
groonga-client
Ruby on Railsで使う
My way with Ruby
Powered by Rabbit 2.2.2

Page: 146

Architecture
アーキテクチャー
✓ Data: RDBMS
データはRDBMSに格納
✓ Full text search: Groonga
全文検索はGroongaで処理
My way with Ruby
Powered by Rabbit 2.2.2

Page: 147

Define app searcher
アプリ用サーチャーを定義
# app/searchers/application_searcher.rb
class ApplicationSearcher <
Groonga::Client::Searcher
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 148

Define searcher
サーチャーを定義
# app/searchers/document_searcher.rb
class DocumentsSearcher < ApplicationSearcher
# Define a full text search index as "content"
# 全文検索用のインデックスを定義
schema.column :content, {
type: "Text",
index: true,
index_type: :full_text_search,
}
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 149

Bind to model
モデルと結びつける
# app/models/document.rb
class Document < ApplicationRecord
# DocumentsSearcher searches Document model
source = DocumentsSearcher.source(self)
# Bind Document's "content" column to
# DocumentsSearcher's "content" index
source.content = :content
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 150

Search (検索)
# app/controllers/documents_controller.rb
class DocumentsController < ApplicationController
def index
@query = params[:query]
searcher = DocumentSearcher.new
@result_set = searcher.search.
query(@query).
result_set
end
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 151

See also
参考情報
✓ Tutorial in Japanese
日本語のチュートリアル
✓ http://www.clear-code.com/blog/2016/12/22.html
My way with Ruby
Powered by Rabbit 2.2.2

Page: 152

Ranguba (WIP) (開発中)
Full text
search system
全文検索システム
My way with Ruby
Powered by Rabbit 2.2.2

Page: 153

Use cases
利用例
✓ File server search
ファイルサーバー検索
✓ E-mail search
メール検索
✓ Web site search
Webサイト検索
My way with Ruby
Powered by Rabbit 2.2.2

Page: 154

Features
機能
✓ Crawlers
クローラー
✓ Web UI
✓ Command line interface
✓ Update documents
更新
✓ Search documents
検索
My way with Ruby
Powered by Rabbit 2.2.2

Page: 155

ChupaText
Text extractor
テキスト抽出
My way with Ruby
Powered by Rabbit 2.2.2

Page: 156

Supported formats
対応フォーマット
✓ PDF
✓ Office documents (オフィス文書)
✓ OpenDocument, Word, Excel, ...
✓ E-mail (メール)
✓ ...
My way with Ruby
Powered by Rabbit 2.2.2

Page: 157

Interface
インターフェイス
✓ HTTP
✓ Web UI
✓ Command line interface
✓ API (Library)
My way with Ruby
Powered by Rabbit 2.2.2

Page: 158

Install - Docker
% GITHUB=https://github.com
% git clone \
${GITHUB}/ranguba/chupa-text-docker.git
% cd chupa-text-docker
% docker-compose up --build
My way with Ruby
Powered by Rabbit 2.2.2

Page: 159

How to use
使い方
% curl \
--form data=@XXX.pdf \
http://localhost:20080/extraction.json
My way with Ruby
Powered by Rabbit 2.2.2

Page: 160

Use cases
利用例
✓ Ranguba
✓ Full text search system
全文検索システム
✓ Commit e-mail
コミットメール
My way with Ruby
Powered by Rabbit 2.2.2

Page: 161

git-commit-mailer
Commit e-mail
for Git
Git用のコミットメール
My way with Ruby
Powered by Rabbit 2.2.2

Page: 162

Features
機能
✓ HTML mail
HTMLメール
✓ Highlighted diff
diffをハイライト
✓ GitLab/GitHub Web hook
GitLab/GitHubのWebフック対応
✓ By GitHub:clear-code/github-web-hooks-receiver
My way with Ruby
Powered by Rabbit 2.2.2

Page: 163

Users
利用者
✓ tDiary
✓ My products
My way with Ruby
Powered by Rabbit 2.2.2

Page: 164

commit-email.info
Commit e-mail
as a
Service
コミットメールのクラウドサービス
My way with Ruby
Powered by Rabbit 2.2.2

Page: 165

How to use
使い方
✓ Send a pull request to
GitHub:kou/commit-email.info
pull requestを送る
✓ Register a Web hook
Webフックを登録
✓ Subscribe your mailing list
メーリングリストを購読
See also http://www.commit-email.info/
My way with Ruby
Powered by Rabbit 2.2.2

Page: 166

Opening5
きっかけ5
Data processing
データ処理
My way with Ruby
Powered by Rabbit 2.2.2

Page: 167

csv
CSV parser
CSVパーサー
My way with Ruby
Powered by Rabbit 2.2.2

Page: 168

csv - History
歴史
✓ 2003: Import
Rubyに取り込み
✓ 2007: Replaced with FasterCSV
FasterCSVで置き換え
✓ 2018: I became a co-
maintainer with mrkn
mrknと一緒にメンテナーになった
My way with Ruby
Powered by Rabbit 2.2.2

Page: 169

Why?
なんで?
✓ There are many data sources
in CSV
CSVのデータはたくさんある
✓ Important to process data
データを処理するためにCSVパーサーは重要
My way with Ruby
Powered by Rabbit 2.2.2

Page: 170

CSV format problems
CSVフォーマットの問題
✓ Slow to parse
パースが遅い
✓ Too wild
なんでもあり
My way with Ruby
Powered by Rabbit 2.2.2

Page: 171

Red Arrow
Apache Arrow
Ruby
My way with Ruby
Powered by Rabbit 2.2.2

Page: 172

Red Arrow - History
歴史
✓ 2017-02: The first commit
最初のコミット
✓ 2018-05: Became the
"official" Ruby bindings of
Apache Arrow
Apache Arrowの公式Rubyバインディングになった
My way with Ruby
Powered by Rabbit 2.2.2

Page: 173

Apache Arrow
✓ Super fast data format
すごく速いデータフォーマット
✓ For in-memory data
インメモリーデータ用
✓ Cross-language support
いろんな言語がサポート
✓ Easy to share data with Python,
Java, ...
PythonやJavaなどとデータ交換がしやすい
My way with Ruby
Powered by Rabbit 2.2.2

Page: 174

Performance (性能)
Apache Arrow
CSV
0.045
0.04
0.035
0.03
0.025
0.02
0.015
0.01
0.005
0
0
500
1000
1500
2000
2500
N rows
My way with Ruby
Powered by Rabbit 2.2.2

Page: 175

Apache Arrow - Position
立ち位置
✓ A very important piece
in recent data processing
最近のデータ処理界隈ではすごく大事な1ピース
✓ Like JIT for Ruby 3
Ruby 3で例えるとJITみたいな感じ
My way with Ruby
Powered by Rabbit 2.2.2

Page: 176

Red Arrow - Impl.
実装
✓ Based on Ruby/GI
Ruby/GIを使っている
✓ Auto generated bindings
バインディングを自動生成
My way with Ruby
Powered by Rabbit 2.2.2

Page: 177

Extendable load API
拡張可能なロードAPI
# Load Apache Arrow data
Arrow::Table.load("iris.arrow")
# Load CSV data
Arrow::Table.load("iris.csv")
# Load Apache Parquet data
Arrow::Table.load("iris.parquet")
My way with Ruby
Powered by Rabbit 2.2.2

Page: 178

Apache Parquet
✓ Super fast data format
すごく速いデータフォーマット
✓ For storing analysis target data
解析対象のデータを保存する用
✓ Widely used
広く使われている
My way with Ruby
Powered by Rabbit 2.2.2

Page: 179

Performance (性能)
Apache Arrow
CSV
0.045
Apache Parquet
0.04
0.035
0.03
0.025
0.02
0.015
0.01
0.005
0
0
500
1000
1500
2000
2500
N rows
My way with Ruby
Powered by Rabbit 2.2.2

Page: 180

Red Parquet
Apache Parquet
My way with Ruby
Powered by Rabbit 2.2.2

Page: 181

Red Data Tools
A project to
make Ruby data
processable
Rubyでデータ処理できるようにするためのプロジェクト
My way with Ruby
Powered by Rabbit 2.2.2

Page: 182

Red Data Tools - History
歴史
✓ 2017-02: Start (開始)
✓ 2017-11-: Develop events per
month at Tokyo
東京で毎月開発イベントを開催
My way with Ruby
Powered by Rabbit 2.2.2

Page: 183

The number of products
プロダクト数
About 20
including Red Arrow and Red Parquet
20くらい
Red ArrowやRed ParquetもRed Data Toolsプロダクツ
My way with Ruby
Powered by Rabbit 2.2.2

Page: 184

Red Datasets
Dataset fetcher
データセット取得
My way with Ruby
Powered by Rabbit 2.2.2

Page: 185

Supported datasets
対応データセット
✓ Iris
✓ CIFAR
✓ Wikipedia
My way with Ruby
Powered by Rabbit 2.2.2

Page: 186

Wikipedia
require "datasets"
wikipedia = Datasets::Wikipedia.new
wikipedia.each do |page|
p page.title
end
My way with Ruby
Powered by Rabbit 2.2.2

Page: 187

Wikipedia search
pages = Groonga["pages"]
wikipedia = Datasets::Wikipedia.new
wikipedia.each do |page|
pages.add(title: page.title,
content: page.revision.text)
end
ruby_pages = pages.select do |record|
record.match("Ruby OR Rails") do |target|
(target.title * 10) | target.content
end
end
p ruby_pages.size
My way with Ruby
Powered by Rabbit 2.2.2

Page: 188

jekyll-jupyter-notebook
Jekyll
+
Jupyter
Notebook
My way with Ruby
Powered by Rabbit 2.2.2

Page: 189

Usage
使い方
{% jupyter_notebook sample.ipynb %}
My way with Ruby
Powered by Rabbit 2.2.2

Page: 190

Red OpenCV
Computer vision
コンピュータービジョン
My way with Ruby
Powered by Rabbit 2.2.2

Page: 191

Camera (カメラ)
require "cv"
camera = CV::Camera.new
image = camera.read
image.write("capture.jpg")
My way with Ruby
Powered by Rabbit 2.2.2

Page: 192

Face detect (顔認識)
image_gray = image.convert_color(:bgr2gray)
classifier = # Face detector
CV::CascadeClassifier.new("frontalface_alt")
objects = classifier.detect(image_gray)
color = CV::Color.new(0, 0, 255)
objects.each do |object|
# Draw detected area
image.draw_rectangle(object, color)
end
image.write("detect.jpg")
My way with Ruby
Powered by Rabbit 2.2.2

Page: 193

Red OpenCV - Impl.
実装
✓ Based on Ruby/GI
Ruby/GIを使っている
✓ Auto generated bindings
バインディングを自動生成
My way with Ruby
Powered by Rabbit 2.2.2

Page: 194

Ad: RubyData Workshop
✓ 2018-06-01 15:50/17:20
✓ Contents: (内容)
✓ Workshop by mrkn
mrknによるワークショップ
✓ Presentations from
Red Data Tools members
Red Data ToolsメンバーによるRed Data Toolsでやって
きたことの紹介
My way with Ruby
Powered by Rabbit 2.2.2

Page: 195

Process data with Ruby
Rubyでデータ処理
✓ We're working on it
Red Data Toolsは継続して取り組んでいる
✓ Do you want to work with us?
一緒にやりたい人はいる?
My way with Ruby
Powered by Rabbit 2.2.2

Page: 196

How to join1 (参加方法1)
✓ Join our chat rooms:
チャットルームに参加
✓ en: Gitter:red-data-tools/en
✓ ja: Gitter:red-data-tools/ja
✓ Join monthly events at Tokyo
東京での毎月の開発イベントに参加
✓ https://speee.connpass.com/
My way with Ruby
Powered by Rabbit 2.2.2

Page: 197

How to join2 (参加方法2)
✓ Hire developers to work on it
仕事として開発する開発者を雇う
✓ e.g.: mrkn by Speee, Inc.
例:Speeeの村田さん
My way with Ruby
Powered by Rabbit 2.2.2

Page: 198

How to join3 (参加方法3)
✓ Order ClearCode to work on it
クリアコードに開発の仕事を発注
✓ Join ClearCode to work on it
クリアコードに入って仕事として開発を進める
My way with Ruby
Powered by Rabbit 2.2.2

Page: 199

Wrap up
まとめ
✓ I'm working on the following
as a Rubyist
Rubyistとしての私の活動
✓ Increase what Ruby can do
with free software
フリーソフトウェアを使ってRubyでできることを増やす
✓ Maintain libraries
ライブラリーのメンテナス
✓ Do you want to work with me?
一緒にやりたい人はいる?
My way with Ruby
Powered by Rabbit 2.2.2

Other slides

Apache Arrow Apache Arrow
2017-06-13
Apache Arrow Apache Arrow
2017-05-28
Mroonga! Mroonga!
2015-10-30