Slide 1

Slide 1 text

Crystal in Operation Crystal 2018/07/18 Crystal.tokyo #7

Slide 2

Slide 2 text

61:+ • ʕ·ᴥ·ʔAKJ )C @arcage arcage • =A37.8(/>D &$" • .80!'2,95*=A ? • B/0 • ;/ &$" • &4 • 6@- %4<#' 2018/07/18 Crystal.tokyo #7

Slide 3

Slide 3 text

:6*!. maillog )$# SMTP AUTH;/( IP " %8 9&0. - +," ' /)51 23 10742" 1$43" 24$44" 2018/07/18 Crystal.tokyo #7

Slide 4

Slide 4 text

https://crystal-lang.org/api/ 2018/07/18 Crystal.tokyo #7

Slide 5

Slide 5 text

UTF-8 2018/07/18 Crystal.tokyo #7

Slide 6

Slide 6 text

IO#set_encoding # • #set_encoding • encoding: ICONV.-" • invalid: :skip or nil &)$UTF-8, • ' /+ File.open("./data.txt") do |file| # Shift_JIS*0% # (!0 file.set_ecoding("Shift_JIS", :skip) end # File.open # File.open("./data.txt", "w" encoding: "Shift_JIS", invalid: :skip) 2018/07/18 Crystal.tokyo #7

Slide 7

Slide 7 text

2018/07/18 Crystal.tokyo #7

Slide 8

Slide 8 text

File::Info#modification_time & 0.24File::Stat • % • #ino #? • #mtime → #modification_time • #atime#utime #? f_info = File.info("./README.md") f_info.modification_time #=> 2018-02-02 05:11:53.379574681 UTC f_info.permissions #=> rw-r--r-- (0o644) f_info.size #=> 11325_u64 # !"(inode$) f_info.same_file?(other_f_info) 2018/07/18 Crystal.tokyo #7

Slide 9

Slide 9 text

gz 2018/07/18 Crystal.tokyo #7

Slide 10

Slide 10 text

class Zlib::Reader gz • • Zlib::Reader IO • require "zlib" File.open("./maillog.gz") do |file| Zlib::Reader.open(file) do |gz| gz.each_line do |line| # ... end end end 2018/07/18 Crystal.tokyo #7

Slide 11

Slide 11 text

zip 2018/07/18 Crystal.tokyo #7

Slide 12

Slide 12 text

class Zip::Reader zip • • ! Zip::Reader::Entry • Zip / • #io require "zip" Zip::Reader.open("./logs.zip") do |zip| zip.each_entry do |entry| entry.io.each_line do |line| # ... end end end 2018/07/18 Crystal.tokyo #7

Slide 13

Slide 13 text

2018/07/18 Crystal.tokyo #7

Slide 14

Slide 14 text

method system • 0 true • 0 false system("which", ["cc"]) #=> true # system("whic", ["cc"]) #=> false # (Process::Status) $?.exit_code #=> 32512 2018/07/18 Crystal.tokyo #7

Slide 15

Slide 15 text

method ` ← • cc_path = `which cc` #=> "/usr/bin/cc\n" # cc_path = `whic cc` #=> "" # $?.exit_code #=> 32512 2018/07/18 Crystal.tokyo #7

Slide 16

Slide 16 text

class Process • • #wait • STDIN/OUT/ERR prc = Process.new("which", ["cc"]) exit_status = prc.wait exit_status.exit_code #=> 0 String.build { |io| Process.new("which", ["cc"] output: io).wait } #=> "/usr/bin/cc\n" 2018/07/18 Crystal.tokyo #7

Slide 17

Slide 17 text

ID 2018/07/18 Crystal.tokyo #7

Slide 18

Slide 18 text

class Process • ID • • CPU … • • kill Process.pid #=> 9651 Process.executable_path #=> "/home/user/bin/exec_file" Process.times #=> Process::Tms(@utime=0.0, @stime=0.0, @cutime=0.0, @cstime=0.0) Process.find_executable("cc") #=> "/usr/bin/cc" Process.kill(6523) 2018/07/18 Crystal.tokyo #7

Slide 19

Slide 19 text

UNIX 2018/07/18 Crystal.tokyo #7

Slide 20

Slide 20 text

enum Signal $! ! • #trap do ... end • #reset Signal::INT.trap do # Ctrl+C " end Signal::HUP.trap do # !# end # Signal::INT.reset 2018/07/18 Crystal.tokyo #7

Slide 21

Slide 21 text

2018/07/18 Crystal.tokyo #7

Slide 22

Slide 22 text

module System CPU Sytem.hostname #=> "myhost.example.org" Sytem.cpu_count #=> 8_u64 2018/07/18 Crystal.tokyo #7

Slide 23

Slide 23 text

97-I3F • 8.BG#$@ • )*6(;&:5 Ruby 90D → Crystal 25D • =2H%'!%8.4 • crystal run trial & error +C • 0EA1C? , • "& %-I/ 2018/07/18 Crystal.tokyo #7

Slide 24

Slide 24 text

…… 2018/07/18 Crystal.tokyo #7

Slide 25

Slide 25 text

https://guthub.com/arcage/*** 2018/07/18 Crystal.tokyo #7

Slide 26

Slide 26 text

crystal-logreader • ! • tail -F require "logreader" log = LogReader.new("/var/log/maillog") log.each do |line| #... end 2018/07/18 Crystal.tokyo #7

Slide 27

Slide 27 text

ip2country • • en/fr/es/de/ja/zh/ko ! / RIR delegations umpirsky/country-list require "ip2country" ip2c = IP2Country.new ip2c.lookup("8.8.8.8") #=> "United Status" ip2c.lookup("8.8.8.8", "ja") #=> " " ip2c = IP2Country.new("ja") ip2c.lookup("8.8.8.8") #=> " " 2018/07/18 Crystal.tokyo #7

Slide 28

Slide 28 text

%( crystal-email • UTF-8# • $& • HTML • AUTH PLAIN/LOGIN # • STARTTLS # • 'concurrent" Gmail • Thanks @sdogruyol! require "email" EMail.send("smtp.example.org") do from "[email protected]" to "[email protected]" subject ")!" message """ attach "photo.jpg" end 2018/07/18 Crystal.tokyo #7

Slide 29

Slide 29 text

crystal-patlite • PATLITE • PHN // // require "patlite" ip = "192.169.100.100" port = 10000 plite = Patlite::PHN.new(ip, port) plite.set do green_on end 2018/07/18 Crystal.tokyo #7

Slide 30

Slide 30 text

8 # 29 - +," (! /*51 10642" 1%43" 24%44" maillog *%$ SMTP AUTH :/) IP" &7 9'0. 23 2018/07/18 Crystal.tokyo #7

Slide 31

Slide 31 text

2018/07/18 Crystal.tokyo #7