Slide 1

Slide 1 text

ࢥΘ͵ಈ͖Λ͢Δ ίϚϯυͷࣄྫ USP༑ͷձ @papiron

Slide 2

Slide 2 text

ރΕ͍ͯΔίϚϯυʁ • UNIXͰੲ͔Β࢖ΘΕΔίϚϯυ • ࢖͍ݹ͞Ε͍ͯͯރΕ͍ͯΔ • க໋తόά͕গͳ͍

Slide 3

Slide 3 text

ރΕ͍ͯΔίϚϯυʁ ιϨμϝʂʂ ʙ͋ͳͨͷৗࣝ͸ඇৗࣝʂʁʙ ʻςϨϏ౦ژʼ

Slide 4

Slide 4 text

ιϨμϝʂͳࣄྫ • dateίϚϯυ • ࢦఆͨ͠೔෇ͷදࣔ • awkίϚϯυ • ཚ਺ൃੜ ͜ͷൃදͰ͸ԼهίϚϯυͷ ιϨμϝʂͳࣄྫΛ঺հ͢Δ

Slide 5

Slide 5 text

dateίϚϯυ • BSD൛ͱGNU൛Ͱಈ࡞͕ҟͳΔ • Mac΍FreeBSD͸BSDܥͷOS • Linux͸GNU൛͕ඪ४෇ଐ

Slide 6

Slide 6 text

BSD൛dateίϚϯυ date -j -f ࢦఆformat ೔෇จࣈྻ ग़ྗformat ۩ମతͳར༻ྫ BSD൛dateίϚϯυͰࢦఆͨ͠೔෇ͷදࣔ $ date -j -f '%Y%m%d' 20160618 ‘+%Y೥%m݄%d೔' 2016೥06݄18೔

Slide 7

Slide 7 text

ෆਖ਼ͳ೔෇ͷݕূ ෆਖ਼ͳ೔෇Λࢦఆ͢ΔͱΤϥʔ͕ൃੜ $ date -j -f '%Y%m%d' 20160150 '+%Y೥%m݄%d೔' Failed conversion of ``20160150'' using format ``%Y%m%d'' $ date -j -f '%Y%m%d' 20160150 '+%Y೥%m݄%d೔' Failed conversion of ``20160150'' using format ``%Y%m%d'' 2016೥1݄50೔ 2016೥13݄1೔

Slide 8

Slide 8 text

ෆਖ਼ͳ೔෇ͷݕূ Τϥʔ͕ൃੜͯ͠ͳ͍ʂʁʂʁ දࣔ͞Εͨ೔෇͕͓͔͍͠ʁʁ $ date -j -f '%Y%m%d' 20160200 '+%Y೥%m݄%d೔' 2016೥01݄31೔ $ date -j -f '%Y%m%d' 20150229 '+%Y೥%m݄%d೔' 2015೥03݄01೔ 2016೥2݄0೔ 2015೥2݄29೔

Slide 9

Slide 9 text

ෆਖ਼ͳ೔෇ͷݕূ GNU൛ͷdateίϚϯυͰ͸Τϥʔൃੜ $ gdate -d '20160200' '+%Y೥%m݄%d೔' gdate: invalid date ‘20160200’ $ gdate -d '20150229' '+%Y೥%m݄%d೔' gdate: invalid date ‘20150229’ 2016೥2݄0೔ 2015೥2݄29೔

Slide 10

Slide 10 text

݁࿦ʂʁ • dateίϚϯυͰ೔෇ͷݕূ • GNU൛date • ෆਖ਼ͳ೔෇͸Τϥʔൃੜ • BSD൛date • Ұ෦ͷෆਖ਼ͳ೔෇ͰΤϥʔ͕ൃੜ͠ͳ͍ • ͜Ε͸க໋తόάͰ͸ͳ͍ͷ͔ʁʁ

Slide 11

Slide 11 text

ิ଍ BSD൛dateίϚϯυͰͷ೔෇ݕূ͸ ೔ͷ෦෼ͷ਺஋͕31ҎԼ͔Ͳ͏͔͚ͩ ֬ೝ͍ͯ͠ΔΒ͍͠ ʢUSP༑ͷձװࣄͷࠓઘޫ೭͞Μ͕ ιʔείʔυͰ֬ೝʣ

Slide 12

Slide 12 text

awkίϚϯυ • ෳ਺ͷ࣮૷͕͋Δ • Macඪ४awk • ݹ͍࣮૷ʁॲཧ଎౓͸஗͍ • GNU൛awk • GNUಠ֦ࣗுͰଟػೳ • mawk • ߴ଎ॲཧ͕Մೳ

Slide 13

Slide 13 text

awkͰཚ਺ൃੜ • awk͸rand()ؔ਺Ͱཚ਺ൃੜ • BEGIN۟Ͱsrand()ؔ਺Λ࢖ͬͯseed Λࢦఆ • srand()ؔ਺͸σϑΥϧτͰ೔෇Λ seedʹ࢖͏

Slide 14

Slide 14 text

ͲΜͳཚ਺͕ൃੜʁ ϚχϡΞϧʹΑΔͱ0͔Β1ͷؒͷ਺஋ • Macඪ४awk • rand random number on (0,1) • GNU൛awk • rand() Return a random number N, between 0 and 1, such that 0 <= N < 1. • mawk • rand() Returns a random number between zero and one. ֤छAWKͷਖ਼ࣜϚχϡΞϧΑΓ

Slide 15

Slide 15 text

awkͰཚ਺ൃੜͷ۩ମྫ $ yes | awk 'BEGIN{srand()}{print rand()}' 0.468882 0.800048 0.259498 0.369426 0.88324 ... yesίϚϯυͱawkͷ࿈ܞͰແݶʹཚ਺Λൃੜ

Slide 16

Slide 16 text

awkͰཚ਺ൃੜͷ۩ମྫ $ yes | awk 'BEGIN{srand()}{print rand()}’ ɹ| head -n 100 ཚ਺Λ100ݸൃੜͤ͞Δ৔߹͸ԼهͷΑ͏ʹɻ $ seq 100 | awk 'BEGIN{srand()}{print rand()}’ headίϚϯυͰ࠷ޙʹ100ߦ෼੾Δ seqίϚϯυͰ100ߦੜ੒

Slide 17

Slide 17 text

࠷େ࠷খ஋ͷ֬ೝํ๏ $ yes | awk 'BEGIN{srand()}{print rand()}' | head -n 100 | sort -n 0.0059382 0.0111584 ... 0.995792 0.999588 sortίϚϯυͷ-nΦϓγϣϯͰ਺஋ॱʹฒ΂ସ͑Δ

Slide 18

Slide 18 text

࠷େ࠷খ஋ͷ֬ೝํ๏ ͞ΒʹsedίϚϯυͰ1ߦ໨ͱ࠷ऴߦ໨Λग़ྗɻ $ yes | awk 'BEGIN{srand()}{print rand()}' | head -n 100 | sort -n | sed -n ‘1p;$p;’ | xargs 0.0059382 0.999588

Slide 19

Slide 19 text

ิ଍ $ yes | awk 'BEGIN{srand()}{print rand()}' | head -n 100 | st --min --max min max 0.0248714 0.999223 stίϚϯυͱ͍͏ศརͳίϚϯυ΋͋Δ ฏۉ஋ɺதԝ஋ɺඪ४ภࠩͳͲ΋ܭࢉՄೳ stίϚϯυͷGithubαΠτ͸ͪ͜Β https://github.com/nferraz/st

Slide 20

Slide 20 text

ิ଍ $ yes | gawk 'BEGIN{srand()}{print rand()}' | head -n 100 | awk ‘BEGIN{min=10000;max=-10000} {if($1max){max=$1}} END{print min,max}’ 0.00555304 0.996305 awkͰ΋֬ೝ͸Մೳ

Slide 21

Slide 21 text

ཚ਺ੜ੒ςετ $ yes | awk 'BEGIN{srand()}{print rand()}' | head -n 100 | sort -n | sed -n ‘1p;$p’ | xargs 0.0114521 0.991685 Macඪ४awk 0͔Β1ͷൣғ

Slide 22

Slide 22 text

ཚ਺ੜ੒ςετ $ yes | gawk 'BEGIN{srand()}{print rand()}' | head -n 100 | sort -n | sed -n ‘1p;$p’ | xargs 0.0114521 0.991685 GNU൛awk 0͔Β1ͷൣғ

Slide 23

Slide 23 text

ཚ਺ੜ੒ςετ $ yes | mawk 'BEGIN{srand()}{print rand()}' | head -n 100 | sort -n | sed -n ‘1p;$p' | xargs 0.0307588 1.99062 mawk 0͔Β1ͷൣғ͡Όͳ͍ʁʁ 0͔Β2ͷൣғͬΆ͍ʁʁ

Slide 24

Slide 24 text

ཚ਺ੜ੒ςετ $ yes | mawk 'BEGIN{srand()}{print rand()}' | head -n 100 | sort -n | sed -n ‘1p;$p’ | xargs 0.00340401 0.981487 mawk ઌͷ࣮ݧྫ͸MacͰ࣮ߦ ࠓ౓͸LinuxͰ࣮ߦͯ͠ΈΔͱʁ 0͔Β1ͷൣғ

Slide 25

Slide 25 text

݁࿦ʂʁ • awkͰ࢖͑Δཚ਺ൃੜrand()ؔ਺ • ਖ਼ࣜϚχϡΞϧͰ͸0͔Β1ͷؒ • BSDܥOSͰಈ͘mawkͰ͸0͔Β2ͷؒʁʁ • ͜Ε͸க໋తόάͰ͸ͳ͍ͷ͔ʁʁ

Slide 26

Slide 26 text

ݪҼ͸ʁ Twitter্Ͱ γΣϧܳք۾ͷํͱҰॹʹ mawkͷιʔείʔυಡΜ͕ͩ ͦͷ࣌͸ܸ௜ @grethlen͞Μ @gin_135͞Μ ͋Γ͕ͱ͏͍͟͝·ͨ͠

Slide 27

Slide 27 text

ݪҼ͸ʁ ͦͷޙ ιʔεΛݟͯ ݪҼΛಛఆͯ͠ ͘Εͨํ͕ʂ

Slide 28

Slide 28 text

ݪҼ͸ʁ $ yes | ./mawk 'BEGIN{srand()}{print rand()}' | head -n 100 | sort -n | sed -n '1p;$p' | xargs 0.00650974 0.987933 mawk 0͔Β1ʹͳͬͨʂʂ patch͋ͯͨmawkͰ࣮ݧʂ