Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
TOKIWANOMORI-20180901
Search
MzRyuKa
September 01, 2018
Programming
0
480
TOKIWANOMORI-20180901
トキワの森LT大会(2018/09/01)でLT発表した資料です。
MzRyuKa
September 01, 2018
Tweet
Share
More Decks by MzRyuKa
See All by MzRyuKa
EDI_LT_Elixir_books_story
mzryuka
0
580
インフラ勉強会LT資料:自分の本を宣伝するLT
mzryuka
1
110
Internet-Oldman-2_LT-today-no2
mzryuka
0
260
Ginza.js #1 LT_Draw_LineChart
mzryuka
1
440
「ドラクエに学ぶチームマネジメント」読書会第5章
mzryuka
1
230
WebEngineerMeetup10_cui_quiz
mzryuka
1
1.8k
pplog_5thbd_lt
mzryuka
0
190
aniben-20180823
mzryuka
1
1.3k
Other Decks in Programming
See All in Programming
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
イマのCSSでできる インタラクション最前線 + CSS最新情報
clockmaker
4
550
受け取る人から提供する人になるということ
little_rubyist
0
250
CSC509 Lecture 13
javiergs
PRO
0
110
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.2k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
340
Outline View in SwiftUI
1024jp
1
340
Modular Monolith Monorepo ~シンプルさを保ちながらmonorepoのメリットを最大化する~
yuisakamoto
5
300
Jakarta EE meets AI
ivargrimstad
0
180
CSC509 Lecture 11
javiergs
PRO
0
180
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
700
Featured
See All Featured
KATA
mclloyd
29
14k
Building Adaptive Systems
keathley
38
2.3k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Adopting Sorbet at Scale
ufuk
73
9.1k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Code Reviewing Like a Champion
maltzj
520
39k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Fireside Chat
paigeccino
34
3k
Transcript
RubyεΫϦϓτΛ Goݴޠʹஔ͖͑ͨΒ ॲཧ͕࣌ؒ̎̌ͷ̍ʹͳͬͨ 2018.09.01 τΩϫͷLTେձ @MzRyuKa
ຊ͍͑ͨ͜ͱ ͪΐͬͱͨ͠ॲཧͰGoͰॻ͘ͷ͓͢͢Ί
ࣗݾհ ΈͣΓΎ @MzRyuKa https://mzryuka.hatenablog.jp/ தখاۀͷSIer ࠷ۙɺࣗࣾͷࣾษ ڧձͰएखࣾһʹࠞͬ͡ ͯ৭ʑָ͠ΜͰ͍·͢ɻ
͖͔͚ͬ ผձ͕ࣾఏڙ͢Δ6000ݸͷcsvϑΝΠϧ͕Πϯϓοτɻ ͔͠͠ɺ͜Μͳ͕ଟൃͨ͠ɻ ϑΝΠϧ໊ͷ໋໊ϧʔϧʹ͋ͬͯͳ͍ɻ ϑΝΠϧͷσʔλܗ͕ࣜʮόΠφϦܗࣜʯʹͳ͍ͬͯͨɻ ϑΝΠϧதͷॻ͕ࣜؒҧ͍ͬͯͨɻ σʔλ߲ͷΧϯϚͷ͕ؒҧ͍ͬͯͨɻ ಛఆͷσʔλ߲ͷઃఆ͕ޡ͍ͬͯͨɻ
ରࡦͱͯ͠ɺ؆қతͳνΣοΫεΫϦϓτΛ bashͱrubyͰύύοͱ࡞ͨ͠ɻ ༁ɿ bash: ʮfileʯίϚϯυͰϑΝΠϧܗࣜΛνΣοΫɻ 1ͰνΣοΫྃ ruby: ϑΝΠϧܗࣜҎ֎ͷνΣοΫΛ࣮ࢪɻ ̏̌ͰνΣοΫྃ ݁Ռɺ1ճͷνΣοΫʹ̏̎ͷॲཧ࣌ؒɻ
ʢ݄̍ͷσʔλͷͨΊɺ̍͋ͨΓ1ͷॲཧʣ
ఔ͜ΕͰରԠ͍ͯͨ͠ɻ ͔͠͠ɺʹճ֬ೝ͢Δέʔε͕ग़͖ͯͨͷ Ͱɺͪΐͬͱ͕࣌ؒମແ͘ͳ͖ͬͯͨɻ ʮࣄʹ༨༟͕͋Δঢ়گͳͷͰɺͪΐͬ͘Β GoݴޠͰॻ͖ͯ͠ΈΔ͔ɻʯͱࢥཱ͍ͭɻ
GoݴޠͰͷॻ͖͑ ผݴޠͰͷ࣮ͩ̇ͱු͔Εͯͨ໘ɺrubyͷॻ͖ํʹ׳ Ε͍ͯͨͷͰɺׂͱΠϥͬͱ͠ͳ͕Βॻ͍͍ͯͨɻ ΠϥΠϥϙΠϯτɿ ར༻͍ͯ͠ͳ͍มύοέʔδͷએݴͰౖΒΕΔ ifจ͕̍ߦͰॻ͚ͳ͍ͨΊߦ͕૿͑Δ ໌ࣔతͳܕࢦఆΛ͢ΔͷͰɺؔͷฦ͢ܕͷௐ͕ࠪ໘
ϑΝΠϧͷܗࣜνΣοΫɺGoͰͲ͏͢Εྑ͍ ͔Θ͔Βͳ͔ͬͨͷͰɺ֎෦ίϚϯυͰʮfileʯΛ ࣮ߦ͢ΔΑ͏ʹͨ͠ɻ out, err := exec.Command(“file”,fullpath).Output() if err !=
nil { return false } outstr := fmt.Sprintf(“out: %s”, out) if strings.Index(outstr, “ASCII text”) == -1 { return false } return true
ϑΝΠϧͷ໋໊νΣοΫɺਖ਼نදݱΛར༻ɻ ಉ༷ʹɺͷॻࣜνΣοΫਖ਼نදݱɻ Goͷਖ਼نදݱ͍ͱฉ͍͍͕ͯͨɺ ଞʹྑ͍Ҋࢥ͍͔ͭͣɺ͜ΕͰ࣮ɻ var re := regex.MustCompile(`^2[0-1][0-9][0-9]ʢ~ུ~ʣ.csv$`) func checkFileName(filename
string) bool { return re.MatchString(filename) }
࣮ߦલ ͜Μͳײ͡Ͱॻ͍ͯɺͻͱ·ͣɻಛʹ ͤͣʹॻ͍ͨͷͰੑೳෆ͔҆͠ͳ͍ɻ ·͊ɺ͕࣌ؒʹͳΕɺ͏͚ͷɻ ͘ͳͬͯͨΒGoroutineͰฒྻ࣮ߦͰ͢ΔΑ͏ ʹมߋ͠Α͏͔ͳʙɺͱࢥ͍ͳ͕Β࣮ߦɻ
݁Ռ શνΣοΫͷ࣮ߦ࣌ؒʮ̍ʯͱͳͬͨɻ ʢtimeίϚϯυͰճܭଌʣ ɾɾ͋ΕɺbashͷνΣοΫ࣮ߦ࣌ؒͱ΄΅ಉ͡ʁ
݁Ռʢͦͷ̎ʣ ؾʹͳͬͯɺ ʮfileʯίϚϯυͷ࣮ߦ෦͚ͩͰ࣮ߦͨ͠Βɺ ࣮ߦ࣌ؒʮ1ʯͩͬͨɻ
݁Ռʢͦͷ̏ʣ ͞Βʹؾʹͳͬͯɺ ʮfileʯίϚϯυ෦Λআ͍࣮ͯߦ͢Δͱɺ ࣮ߦ࣌ؒʮ̍̍ඵʯͩͬͨɻ
“ॲཧ࣌ؒͷ୯Ґ͕มΘͬͨʂ” ϏόʂGolang!!
ॻ͖͑ͨՌ ୯७ʹGoݴޠͰॻ͖͚͑ͨͩͰɺॲཧ࣌ؒ ʮ̎̌ͷ1ʯ(32ˠ1)ͱͳͬͨɻ ʮfileʯίϚϯυͷݺͼग़͠෦࣮࣭తʹมΘͬ ͍ͯͳ͍ͷͰɺruby→golangʹมߋͨ͜͠ͱʹΑ ΔޮՌɺʮ̍̒̌ͷ̍ʯ(30ˠ11ඵ)ͱ ͳͬͨɻ
·ͱΊ Rubyͷಈతݴޠɺͬ͞ͱ࡞ΕΔ͓ख͕ܰ͋͞ Δ͕ॲཧ͕ؾʹͳͬͯ͘Δɻ GoͰॻ͍ͯΔͱଟগΠϥΠϥ͢Δ͜ͱ͋ͬͨɻ ͕ɺॲཧΛΈͯաڈͷ͜ͱਫʹྲྀͨ͠ɻ Ұ୴ಈతݴޠͰॻ͍ͯΈͯɺΠϝʔδΛ௫ΜͰ ͔ΒGoͰஔ͖͑Δͷ͋Γͩͱࢥ͍·͢ɻ