Pro Yearly is on sale from $80 to $50! »

課題をテストで解決する

0ac642c69b7f699a69e3ae3372244dc6?s=47 shibayu36
April 20, 2014

 課題をテストで解決する

0ac642c69b7f699a69e3ae3372244dc6?s=128

shibayu36

April 20, 2014
Tweet

Transcript

  1. ՝୊ΛςετͰղܾ͢Δ DevLOVEؔ੢ 2014/04/19 shiba_yu36

  2. ࣗݾ঺հ

  3. !TIJCB@ZV • ͸ͯͳΞϓϦέʔγϣϯΤϯδχΞ • ͸ͯͳϒϩάνʔϜ • PerlɺςετɺσϓϩΠɺ։ൃ؀ڥ

  4. ϒϩά http://shibayu36.hatenablog.com/

  5. ࠓ೔ͷ࿩ ͸ͯͳϒϩάͷςετ ՝୊Λղܾ͢Δςετࣄྫ ՝୊ͱςετ

  6. ͸ͯͳϒϩάͷςετ

  7.  UFTUT UFTUTNP CVJMETEBZ NJOCVJME FOHJOFFST

  8. Perlͷ୯ମςετ ;Δ·͍ςετ Model DB Controller View JavaScript lint ͦͷଞ crontab

    nginx ઃఆ߲໨ syntax
  9. ςετͷํ਑ • શͯͷϝιουΛςετ • PerlҎ֎ͷ෦෼΋ • ՝୊ΛςετͰΧόʔ

  10. ςετͷํ਑ • શͯͷϝιουΛςετ • PerlҎ֎ͷ෦෼΋ • ՝୊ΛςετͰΧόʔ

  11. ՝୊ΛςετͰΧόʔʁ

  12. ՝୊ʁ ॻࣜϛε ຋༁๨Ε υΩϡϝϯτ σβΠφͱͷڠۀ ઃఆϛε

  13. ՝୊ʁ ॻࣜϛε ຋༁๨Ε υΩϡϝϯτ σβΠφͱͷڠۀ ઃఆϛε ਓ͕ؾΛ͚ͭΔ

  14. ਓ͕ؾΛ͚ͭΔ ՝୊ʁ ॻࣜϛε ຋༁๨Ε υΩϡϝϯτ σβΠφͱͷڠۀ ઃఆϛε ςετͰΧόʔ

  15. ՝୊Λղܾ͢Δςετ

  16. ݴޠʹΑΒͳ͍ ՝୊ͱςετ ݴޠʹΑΔ ୯ମςετ

  17. ՝୊1 crontabΛσϓϩΠͨ͠Β ಈ͔ͳ͔ͬͨ

  18. • crontabͷॻࣜϛε • ࢦఆͨ͠ϑΝΠϧύεΛؒҧ͑Δ • ϩδοΫϛε -> ςετ͋ΔͷͰ΄ͱΜͲͳ͍ ݪҼ

  19. ݪҼ • crontabͷॻࣜϛε • ࢦఆͨ͠ϑΝΠϧύεΛؒҧ͑Δ • ϩδοΫϛε -> ςετ͋ΔͷͰ΄ͱΜͲͳ͍ ਓ͕ؾΛ͚ͭΔ

    ςετͰΧόʔ
  20. ςετ͍ͨ͜͠ͱ MAILTO=shibayu36@hatena.ne.jp! 10 5 * * * apache perl /path/to/dir/script/echo.pl!

    30 09 * * * apache perl /path/to/dir/script/sleep.pl
  21. ςετ͍ͨ͜͠ͱ MAILTO=shibayu36@hatena.ne.jp! 10 5 * * * apache perl /path/to/dir/script/echo.pl!

    30 09 * * * apache perl /path/to/dir/script/sleep.pl ϑΝΠϧऴ୺ʹվߦ͋Δ ࢦఆϑΝΠϧଘࡏ͢Δ ೔෇ࢦఆਖ਼͍͠
  22. ϑΝΠϧऴ୺ʹվߦ͋Δ? my $crontab = file('config/crontab')->slurp;! like $crontab, qr/\n$/, 'ϑΝΠϧ຤ඌʹվߦඞཁ'; ϑΝΠϧ಺༰Λ

    ਖ਼نදݱͰνΣοΫ
  23. ࢦఆϑΝΠϧଘࡏ͢Δ? my @files = $crontab =~ m{/path/to/dir/(.*\.pl)}g;! ! for my

    $file (@files) {! ok -e $file, "$file ͕ଘࡏ";! }
  24. ࢦఆϑΝΠϧଘࡏ͢Δ? my @files = $crontab =~ m{/path/to/dir/(.*\.pl)}g;! ! for my

    $file (@files) {! ok -e $file, "$file ͕ଘࡏ";! } QSPKFDU಺ͬΆ͍ϑΝΠϧ୳͢ ͦΕͧΕϑΝΠϧ͋Δ͔
  25. ߋʹςετ͢Δ • crontabͷParser࣮૷Λ࢖͏ • PerlͩͱParse::Crontab • ೔෇ͷࢦఆϛεͱ͔νΣοΫͯ͘͠ΕΔ

  26. গ͠ͷςετͰਓ͕ ؾΛ͚ͭΔඞཁແ͘ͳͬͨ

  27. ՝୊2 ઃఆϛεΛͯ͠ σϓϩΠͯ͠͠·ͬͨ

  28. ΞϓϦέʔγϣϯͷઃఆ • ؀ڥ͝ͱͷઃఆͱ͔ • DBʹ֨ೲ͢Δ·Ͱ΋ͳ͍σʔλ • etc

  29. [! {! "blog_url" : "http://shibayu36.hatenablog.com/",! "permission" : "public",! "can_be_edited_by" :

    [! "shiba_yu36"! ]! },! {! "blog_url" : "http://shibayu36-private.hatenablog.com/",! "permission" : "private",! "can_be_edited_by" : [! "shiba_yu36",! "shiba_yu37"! ]! },! {! "blog_url" : "http://blog.example.com/",! "permission" : "public",! "can_be_edited_by" : [! "example-user"! ]! }! ]
  30. [! {! "blog_url" : "http://shibayu36.hatenablog.com/",! "permission" : "public",! "can_be_edited_by" :

    [! "shiba_yu36"! ]! },! {! "blog_url" : "http://shibayu36-private.hatenablog.com/",! "permission" : "private",! "can_be_edited_by" : [! "shiba_yu36",! "shiba_yu37"! ]! },! {! "blog_url" : "http://blog.example.com/",! "permission" : "public",! "can_be_edited_by" : [! "example-user"! ]! }! ] CMPH@VSM͸63-Ͱ͋Δ
  31. [! {! "blog_url" : "http://shibayu36.hatenablog.com/",! "permission" : "public",! "can_be_edited_by" :

    [! "shiba_yu36"! ]! },! {! "blog_url" : "http://shibayu36-private.hatenablog.com/",! "permission" : "private",! "can_be_edited_by" : [! "shiba_yu36",! "shiba_yu37"! ]! },! {! "blog_url" : "http://blog.example.com/",! "permission" : "public",! "can_be_edited_by" : [! "example-user"! ]! }! ] QFSNJTTJPO͸ QVCMJD͔QSJWBUF
  32. [! {! "blog_url" : "http://shibayu36.hatenablog.com/",! "permission" : "public",! "can_be_edited_by" :

    [! "shiba_yu36"! ]! },! {! "blog_url" : "http://shibayu36-private.hatenablog.com/",! "permission" : "private",! "can_be_edited_by" : [! "shiba_yu36",! "shiba_yu37"! ]! },! {! "blog_url" : "http://blog.example.com/",! "permission" : "public",! "can_be_edited_by" : [! "example-user"! ]! }! ] CMPH@VSM͸ શମͰϢχʔΫ
  33. Ͳ͏΍ͬͯ࢓༷Λ఻͑Δ? υΩϡϝϯτ ؾ͔ͮΕͳ͍ ϛεΛ͢Δ

  34. ͜Ε΋ςετʹͯ͠͠·͏

  35. my $blogs_config = decode_json(file('blogs.json')->slurp);! ! for my $config (@$blogs_config) {!

    ! my $blog_url = URI->new($config->{blog_url});! is $blog_url->scheme, 'http', "blog_url͸httpͷURLͰ͋Δ";! ! cmp_deeply $config->{permission}, any('public', 'private'),! 'permission͸public͔privateͰ͋Δ';! }
  36. my $blogs_config = decode_json(file('blogs.json')->slurp);! ! for my $config (@$blogs_config) {!

    ! my $blog_url = URI->new($config->{blog_url});! is $blog_url->scheme, 'http', "blog_url͸httpͷURLͰ͋Δ";! ! cmp_deeply $config->{permission}, any('public', 'private'),! 'permission͸public͔privateͰ͋Δ';! } CMPH@VSM͸63-Ͱ͋Δ QFSNJTTJPO͸ QVCMJD͔QSJWBUF
  37. CMPH@VSM͸ શମͰϢχʔΫ my $blogs_config_uniq = [! uniq_by { $_->{blog_url} }

    @$blogs_config,! ];! ! is scalar @$blogs_config_uniq,! scalar @$blogs_config,! "blog_url͕શମͰϢχʔΫͰ͋Δ";
  38. υΩϡϝϯτ͔Βςετʹ • ؾ෇͔Εͳͯ͘΋ɺςετ͕མͪͯ஌Βͤ ͯ͘ΕΔ • ϛε͕͋ͬͯ΋ςετͰݕ஌

  39. IUUQTIJCBZVIBUFOBCMPHDPNFOUSZ  ઃఆͷ࢓༷ΛυΩϡϝϯτʹ ॻ͘ͷͰ͸ͳ͘ɺςετʹͯ͠͠·͏

  40. ൃల • ઃఆͷΫϥεΛ࡞Δ • http://hitode909.hatenablog.com/entry/ 2014/04/10/114403

  41. ՝୊3 ຋༁Λ๨Εͯ σϓϩΠͯ͠͠·ͬͨ

  42. ଟݴޠରԠͷ࢓૊Έ CMPHNBOBHF MPD bCMPHNBOBHF` ϒϩά؅ཧ .BOBHF#MPH

  43. <html>! <head>! <title>[% loc('blog.manage') %]</title>! </head>! <body>! <p>[% loc('blog.manage.description') %]</p>!

    </body>! </html> <html>! <head>! <title>[% loc('blog.manage') %]</title>! </head>! <body>! <p>ϒϩά؅ཧ͕Ͱ͖·͢</p>! </body>! </html>
  44. Ͳ͏΍ͬͯݕ஌͢Δ͔ • Viewʹ೔ຊޠ͕ೖͬͯͳ͍͜ͱͷςετ • ೔ຊਓͳͷͰɺେ఍͜ΕͰղܾͰ͖Δ

  45. my @files = glob('templates/*.html');! ! for my $file (@files) {!

    my $content = file($file)->slurp;! my $has_japanese = $content =~ /[^[:ascii:]]+/;! ok ! $has_japanese, "$file ͸೔ຊޠΛؚ·ͳ͍";! } <html>! <head>! <title>[% loc('blog.manage') %]</title>! </head>! <body>! <p>ϒϩά؅ཧ͕Ͱ͖·͢</p>! </body>! </html>
  46. ՝୊4 υΩϡϝϯτʹ ؾ͍ͮͯ΋Β͑ͳ͍

  47. ରࡦ4 IUUQTIJCBZVIBUFOBCMPHDPNFOUSZ  υΩϡϝϯτͷ৔ॴΛ஌ΒͤΔͨΊʹɺ མͪΔςετΛ࡞Δ

  48. ՝୊5 Nginxͷઃఆ͕ ϦϑΝΫλϦϯά͞Εͳ͍ ֬ೝ͕೉͍ͨ͠Ί

  49. ରࡦ5 NginxΛҰ࣌తʹىಈͯ͠ ςετΛ͢Δ

  50. IUUQTIJCBZVIBUFOBCMPHDPNFOUSZ  nginxͷproxyઃఆϑΝΠϧ΋ ࣗಈςετ͠Α͏

  51. ·ͱΊ

  52. ػցʹ΍ΒͤΔ ਓ͕ؾΛ͚ͭΔ ՝୊ ྫ) ςετ

  53. ೉͍͜͠ͱͯ͠ͳ͍ ୯ମςετΑΓΉ͠Ζ؆୯

  54. ςετ͍Ζ͍Ζ͋ͬͯ ࢝Ίํ෼͔Βͳ͍

  55. ೔ʑͷ՝୊ΛςετͰ ղܾ͢Δͱ͜Ζ͔Β͸͡ΊΔ