Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DaFunk, IOT Framework in Ruby

E822acb0564c5632aae69fef35f85b3d?s=47 Scalone
September 26, 2016

DaFunk, IOT Framework in Ruby

Talk about the DaFunk Framework ecosystem, with small pinches of mruby-cli.

E822acb0564c5632aae69fef35f85b3d?s=128

Scalone

September 26, 2016
Tweet

Transcript

  1. THIAGO SCALONE - @scalone DaFunk IOT FRAMEWORK

  2. Wecolme Message! The activities of a company associated with buying

    and selling a product or service that includes advertising, social media, selling products Marketing is based on thinking about the business in terms of customer needs and their satisfaction marketing differs from selling because in the words of the best university of the world.
  3. Wecolme Message! The activities of a company associated with buying

    and selling a product or service that includes advertising, social media, selling products Marketing is based on thinking about the business in terms of customer needs and their satisfaction marketing differs from selling because in the words of the best university of the world.
  4. Wecolme Message! The activities of a company associated with buying

    and selling a product or service that includes advertising, social media, selling products Marketing is based on thinking about the business in terms of customer needs and their satisfaction marketing differs from selling because in the words of the best university of the world.
  5. None
  6. HAPPY! Felling 1994

  7. None
  8. 2000

  9. 2000

  10. None
  11. 2004

  12. 2004

  13. 2004

  14. None
  15. 2007

  16. 2007

  17. None
  18. None
  19. mruby

  20. THIAGO SCALONE - @scalone DaFunk IOT FRAMEWORK

  21. Wecolme Message! The activities of a company associated with buying

    and selling a product or service that includes advertising, social media, selling products Marketing is based on thinking about the business in terms of customer needs and their satisfaction marketing differs from selling because in the words of the best university of the world.
  22. mruby

  23. MRuby ISO/IEC 30170:2012

  24. MRuby ISO/IEC 30170:2012 Ruby 1.9.3 Syntax

  25. MRuby ISO/IEC 30170:2012 Ruby 1.9.3 Syntax No built-in IO/Thread/stdlib

  26. MRuby ISO/IEC 30170:2012 Ruby 1.9.3 Syntax No built-in IO/Thread/stdlib Cross-compilation

    / ANSI C
  27. MRuby ISO/IEC 30170:2012 Ruby 1.9.3 Syntax No built-in IO/Thread/stdlib Cross-compilation

    / ANSI C No gems, but mrbgems
  28. runtime Operation System

  29. runtime Operation System SDK / Dynlib

  30. runtime Operation System SDK / Dynlib MRuby VM

  31. runtime Operation System SDK / Dynlib MRuby VM Mrbgem

  32. runtime Operation System SDK / Dynlib MRuby App MRuby App

    MRuby VM Mrbgem
  33. runtime Operation System SDK / Dynlib MRuby App MRuby App

    MRuby VM Mrbgem
  34. static Operation System SDK / Dynlib MRuby App MRuby App

    MRuby VM Mrbgem
  35. mrbgem Operation System SDK / Dynlib MRuby App MRuby App

    MRuby VM Mrbgem
  36. $ cd mruby-print/ $ ls mrbgem.rake mrblib src $ cat

    mrbgem.rake MRuby::Gem::Specification.new('mruby-print') do |spec| spec.license = 'MIT' spec.author = 'mruby developers' spec.summary = 'standard print/puts/p' end
  37. $ cd mruby-print/ $ ls mrbgem.rake mrblib src $ cat

    mrbgem.rake MRuby::Gem::Specification.new('mruby-print') do |spec| spec.license = 'MIT' spec.author = 'mruby developers' spec.summary = 'standard print/puts/p' end
  38. $ cd mruby-print/ $ ls mrbgem.rake mrblib src $ cat

    mrbgem.rake MRuby::Gem::Specification.new('mruby-print') do |spec| spec.license = 'MIT' spec.author = 'mruby developers' spec.summary = 'standard print/puts/p' end
  39. $ cd mruby-print/ $ ls mrbgem.rake mrblib src $ cat

    mrbgem.rake MRuby::Gem::Specification.new('mruby-print') do |spec| spec.license = 'MIT' spec.author = 'mruby developers' spec.summary = 'standard print/puts/p' end
  40. runtime Operation System SDK / Dynlib MRuby App MRuby App

    MRuby VM Mrbgem
  41. $ echo "puts 'Hello RUBYCONF'" >> rubyconf.rb $ mrbc rubyconf.rb

    $ hexdump -C rubyconf.mrb 00000000 52 49 54 45 30 30 30 33 0e 93 00 00 00 67 4d 41 |RITE0003.....gMA| 00000010 54 5a 30 30 30 30 49 52 45 50 00 00 00 49 30 30 |TZ0000IREP...I00| 00000020 30 30 00 00 00 41 00 01 00 04 00 00 00 00 00 04 |00...A..........| 00000030 00 80 00 06 01 00 00 3d 00 80 00 a0 00 00 00 4a |.......=.......J| 00000040 00 00 00 01 00 00 0d 48 65 6c 6c 6f 20 47 55 52 |.......HelloRUBY| 00000050 55 2d 53 50 00 00 00 01 00 04 70 75 74 73 00 45 |CONF......puts.E| 00000060 4e 44 00 00 00 00 08 |ND.....| 00000067 $ mruby -b rubyconf.mrb Hello RUBYCONF
  42. None
  43. THIAGO SCALONE - @scalone DaFunk IOT FRAMEWORK

  44. FRAMEWORK

  45. FRAMEWORK reusable set of libraries or classes for a software

    system
  46. FRAMEWORK

  47. FRAMEWORK Philosophy

  48. FRAMEWORK Philosophy Design

  49. FRAMEWORK Philosophy Design Good Practices

  50. FRAMEWORK Philosophy Design Good Practices Backward compatibility

  51. FRAMEWORK Philosophy Design Good Practices Backward compatibility Tools

  52. FRAMEWORK GUIDE

  53. FRAMEWORK GUIDE

  54. DaFunk

  55. Pillars

  56. Pillars

  57. Pillars Optimize for happiness

  58. Pillars Optimize for happiness Cross Compilation

  59. Pillars Optimize for happiness Cross Compilation Modularity

  60. Pillars Optimize for happiness Cross Compilation Modularity Small better

  61. Pillars Optimize for happiness Cross Compilation Modularity Small better Convention

    over configuration
  62. Ecosystem

  63. mruby + mruby-cli AroundTheWorld

  64. lib/device/ !"" application.rb !"" audio.rb !"" crypto.rb !"" display.rb !""

    io.rb !"" magnetic.rb !"" network.rb !"" printer.rb !"" runtime.rb !"" system.rb #"" version.rb
  65. lib/device/ !"" application.rb !"" audio.rb !"" crypto.rb !"" display.rb !""

    io.rb !"" magnetic.rb !"" network.rb !"" printer.rb !"" runtime.rb !"" system.rb #"" version.rb
  66. lib/device/ !"" application.rb !"" audio.rb !"" crypto.rb !"" display.rb !""

    io.rb !"" magnetic.rb !"" network.rb !"" printer.rb !"" runtime.rb !"" system.rb #"" version.rb
  67. lib/device/ !"" application.rb !"" audio.rb !"" crypto.rb !"" display.rb !""

    io.rb !"" magnetic.rb !"" network.rb !"" printer.rb !"" runtime.rb !"" system.rb #"" version.rb class Device class Audio def self.adapter Device.adapter::Audio end def self.beep(tone, seconds) milli = seconds * 1000 adapter.beep(tone, milli) end end end
  68. lib/device/ !"" application.rb !"" audio.rb !"" crypto.rb !"" display.rb !""

    io.rb !"" magnetic.rb !"" network.rb !"" printer.rb !"" runtime.rb !"" system.rb #"" version.rb class Device class Audio def self.adapter Device.adapter::Audio end def self.beep(tone, seconds) milli = seconds * 1000 adapter.beep(tone, milli) end end end
  69. lib/device/ !"" application.rb !"" audio.rb !"" crypto.rb !"" display.rb !""

    io.rb !"" magnetic.rb !"" network.rb !"" printer.rb !"" runtime.rb !"" system.rb #"" version.rb class Device class Audio def self.adapter Device.adapter::Audio end def self.beep(tone, seconds) milli = seconds * 1000 adapter.beep(tone, milli) end end end
  70. Adapter Pattern

  71. Modularity

  72. Modularity

  73. AroundTheWorld

  74. None
  75. $ ls around_the_world/mrbgems/ around.gembox mruby-context mruby-mock mruby-polarssl mruby-sha1 mruby-socket mruby-base58

    mruby-platform
  76. $ ls around_the_world/mrbgems/ around.gembox mruby-context mruby-mock mruby-polarssl mruby-sha1 mruby-socket mruby-base58

    mruby-platform
  77. Adapter Pattern

  78. lib/device/ !"" application.rb !"" audio.rb !"" crypto.rb !"" display.rb !""

    io.rb !"" magnetic.rb !"" network.rb !"" printer.rb !"" runtime.rb !"" system.rb #"" version.rb class Device class Audio def self.adapter Device.adapter::Audio end def self.beep(tone, seconds) milli = seconds * 1000 adapter.beep(tone, milli) end end end
  79. lib/device/ !"" application.rb !"" audio.rb !"" crypto.rb !"" display.rb !""

    io.rb !"" magnetic.rb !"" network.rb !"" printer.rb !"" runtime.rb !"" system.rb #"" version.rb class Device class Audio def self.adapter Device.adapter::Audio end def self.beep(tone, seconds) milli = seconds * 1000 adapter.beep(tone, milli) end end end
  80. mruby-platform

  81. mruby-platform C/C++

  82. mruby-platform C/C++ - Posix

  83. Cross Compilation

  84. mruby-cli

  85. The Pitch

  86. Why?

  87. Web API Mail Analytics Communication Monitoring Authentication Errors

  88. $ my-cli

  89. Who Github - Hub Heroku - Heroku Toolbelt AWS -

    aws-cli Trello - trelo_cli Slack - slack-cli CW - cloudwalk
  90. CRuby

  91. CRuby Requires Ruby

  92. CRuby Requires Ruby Performance (Require)

  93. CRuby Requires Ruby Performance (Require) Ruby Versions

  94. CRuby Requires Ruby Performance (Require) Ruby Versions Packaging Problems

  95. :(

  96. None
  97. $ GOOS=linux GOARCH=amd64 go build $ GOOS=windos GOARCH=amd64 go build

    $ GOOS=darwin GOARCH=amd64 go build
  98. HAPPY! Felling

  99. None
  100. mruby-cli

  101. + = https://github.com/hone/mruby-cli mruby-cli + = https://github.com/hone/mruby-cli mruby-cli + =

  102. mruby-cli Ruby Performance No Require Binary for each platform Simple

    compile and release
  103. $ echo "puts 'Hello RUBYCONF'" >> rubyconf.rb $ mrbc rubyconf.rb

    $ hexdump -C rubyconf.mrb 00000000 52 49 54 45 30 30 30 33 0e 93 00 00 00 67 4d 41 |RITE0003.....gMA| 00000010 54 5a 30 30 30 30 49 52 45 50 00 00 00 49 30 30 |TZ0000IREP...I00| 00000020 30 30 00 00 00 41 00 01 00 04 00 00 00 00 00 04 |00...A..........| 00000030 00 80 00 06 01 00 00 3d 00 80 00 a0 00 00 00 4a |.......=.......J| 00000040 00 00 00 01 00 00 0d 48 65 6c 6c 6f 20 47 55 52 |.......HelloRUBY| 00000050 55 2d 53 50 00 00 00 01 00 04 70 75 74 73 00 45 |CONF......puts.E| 00000060 4e 44 00 00 00 00 08 |ND.....| 00000067 $ mruby -b rubyconf.mrb Hello RUBYCONF
  104. $ echo "puts 'Hello RUBYCONF'" >> rubyconf.rb $ mrbc rubyconf.rb

    $ hexdump -C rubyconf.mrb 00000000 52 49 54 45 30 30 30 33 0e 93 00 00 00 67 4d 41 |RITE0003.....gMA| 00000010 54 5a 30 30 30 30 49 52 45 50 00 00 00 49 30 30 |TZ0000IREP...I00| 00000020 30 30 00 00 00 41 00 01 00 04 00 00 00 00 00 04 |00...A..........| 00000030 00 80 00 06 01 00 00 3d 00 80 00 a0 00 00 00 4a |.......=.......J| 00000040 00 00 00 01 00 00 0d 48 65 6c 6c 6f 20 47 55 52 |.......HelloRUBY| 00000050 55 2d 53 50 00 00 00 01 00 04 70 75 74 73 00 45 |CONF......puts.E| 00000060 4e 44 00 00 00 00 08 |ND.....| 00000067 $ mruby -b rubyconf.mrb Hello RUBYCONF
  105. $ echo "puts 'Hello RUBYCONF'" >> rubyconf.rb $ mrbc rubyconf.rb

    $ hexdump -C rubyconf.mrb 00000000 52 49 54 45 30 30 30 33 0e 93 00 00 00 67 4d 41 |RITE0003.....gMA| 00000010 54 5a 30 30 30 30 49 52 45 50 00 00 00 49 30 30 |TZ0000IREP...I00| 00000020 30 30 00 00 00 41 00 01 00 04 00 00 00 00 00 04 |00...A..........| 00000030 00 80 00 06 01 00 00 3d 00 80 00 a0 00 00 00 4a |.......=.......J| 00000040 00 00 00 01 00 00 0d 48 65 6c 6c 6f 20 47 55 52 |.......HelloRUBY| 00000050 55 2d 53 50 00 00 00 01 00 04 70 75 74 73 00 45 |CONF......puts.E| 00000060 4e 44 00 00 00 00 08 |ND.....| 00000067 $ mruby -b rubyconf.mrb Hello RUBYCONF
  106. $ echo "puts 'Hello RUBYCONF'" >> rubyconf.rb $ mrbc rubyconf.rb

    $ hexdump -C rubyconf.mrb 00000000 52 49 54 45 30 30 30 33 0e 93 00 00 00 67 4d 41 |RITE0003.....gMA| 00000010 54 5a 30 30 30 30 49 52 45 50 00 00 00 49 30 30 |TZ0000IREP...I00| 00000020 30 30 00 00 00 41 00 01 00 04 00 00 00 00 00 04 |00...A..........| 00000030 00 80 00 06 01 00 00 3d 00 80 00 a0 00 00 00 4a |.......=.......J| 00000040 00 00 00 01 00 00 0d 48 65 6c 6c 6f 20 47 55 52 |.......HelloRUBY| 00000050 55 2d 53 50 00 00 00 01 00 04 70 75 74 73 00 45 |CONF......puts.E| 00000060 4e 44 00 00 00 00 08 |ND.....| 00000067 $ mruby -b rubyconf.mrb Hello RUBYCONF
  107. $ echo "puts 'Hello RUBYCONF'" >> rubyconf.rb $ mrbc rubyconf.rb

    $ hexdump -C rubyconf.mrb 00000000 52 49 54 45 30 30 30 33 0e 93 00 00 00 67 4d 41 |RITE0003.....gMA| 00000010 54 5a 30 30 30 30 49 52 45 50 00 00 00 49 30 30 |TZ0000IREP...I00| 00000020 30 30 00 00 00 41 00 01 00 04 00 00 00 00 00 04 |00...A..........| 00000030 00 80 00 06 01 00 00 3d 00 80 00 a0 00 00 00 4a |.......=.......J| 00000040 00 00 00 01 00 00 0d 48 65 6c 6c 6f 20 47 55 52 |.......HelloRUBY| 00000050 55 2d 53 50 00 00 00 01 00 04 70 75 74 73 00 45 |CONF......puts.E| 00000060 4e 44 00 00 00 00 08 |ND.....| 00000067 $ mruby -b rubyconf.mrb Hello RUBYCONF
  108. rubyconf[] = { 0x45,0x54,0x49,0x52,0x30,0x30,0x30,0x33,0x78,0xfb,0x00,0x00,0x00,0x67,0x4d,0x41, 0x54,0x5a,0x30,0x30,0x30,0x30,0x49,0x52,0x45,0x50,0x00,0x00,0x00,0x49,0x30,0x30, 0x30,0x30,0x00,0x00,0x00,0x41,0x00,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x04, 0x06,0x00,0x80,0x00,0x3d,0x00,0x00,0x01,0xa0,0x00,0x80,0x00,0x4a,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0x00,0x00,0x0d,0x48,0x65,0x6c,0x6c,0x6f,0x20,0x47,0x55,0x52, 0x55,0x2d,0x53,0x50,0x00,0x00,0x00,0x01,0x00,0x04,0x70,0x75,0x74,0x73,0x00,0x45, 0x4e,0x44,0x00,0x00,0x00,0x00,0x08,

    };
  109. int main(void) { mrb_state *mrb = mrb_open(); mrbc_context *c; mrb_value

    v; c = mrbc_context_new(mrb); mrb_load_irep_cxt(mrb, rubyconf, c); mrbc_context_free(mrb, c); return 0; }
  110. int main(void) { mrb_state *mrb = mrb_open(); mrbc_context *c; mrb_value

    v; c = mrbc_context_new(mrb); mrb_load_irep_cxt(mrb, rubyconf, c); mrbc_context_free(mrb, c); return 0; }
  111. $ gcc -o rubyconf rubyconf.c -I mruby/ include mruby/build/host/lib/libmruby.a $

    ./rubyconf Hello RUBYCONF
  112. .RB Review

  113. BYTECODE MRB .RB Review

  114. BYTECODE MRB VM + MRBGEM + MRB .RB Review

  115. BYTECODE MRB VM + MRBGEM + MRB BIN .RB Review

  116. + = https://github.com/hone/mruby-cli mruby-cli + = https://github.com/hone/mruby-cli mruby-cli + =

  117. + = https://github.com/hone mrub

  118. + = https://github.com/hone mrub MRuby App MRuby VM Mrbgem Cross

    Compilation
  119. + = https://github.com/hone mrub MRuby App MRuby VM Mrbgem Cross

    Compilation
  120. + = https://github.com/hone mrub MRuby App MRuby VM Mrbgem Cross

    Compilation
  121. + = https://github.com/hone mrub MRuby App MRuby VM Mrbgem Cross

    Compilation
  122. None
  123. + = https://github.com/hone/mruby-cli mruby-cli + = https://github.com/hone/mruby-cli mruby-cli + =

  124. DEMO

  125. mruby + mruby-cli AroundTheWorld

  126. funky-cli

  127. DaFunk

  128. I18n $ cat resources/app/i18n.json { "en":{"success":"SUCCESS"}, "pt-br":{"success"SUCESSO!"} } $ cat

    lib/main.rb class Main < Device def self.call I18n.configure("app", "en") I18n.pt(:success) I18n.locale = "pt-br" I18n.pt(:success) getc true end end
  129. I18n $ cat resources/app/i18n.json { "en":{"success":"SUCCESS"}, "pt-br":{"success"SUCESSO!"} } $ cat

    lib/main.rb class Main < Device def self.call I18n.configure("app", "en") I18n.pt(:success) I18n.locale = "pt-br" I18n.pt(:success) getc true end end
  130. I18n $ cat resources/app/i18n.json { "en":{"success":"SUCCESS"}, "pt-br":{"success"SUCESSO!"} } $ cat

    lib/main.rb class Main < Device def self.call I18n.configure("app", "en") I18n.pt(:success) I18n.locale = "pt-br" I18n.pt(:success) getc true end end
  131. I18n $ cat resources/app/i18n.json { "en":{"success":"SUCCESS"}, "pt-br":{"success"SUCESSO!"} } $ cat

    lib/main.rb class Main < Device def self.call I18n.configure("app", "en") I18n.pt(:success) I18n.locale = "pt-br" I18n.pt(:success) getc true end end
  132. I18n $ cat resources/app/i18n.json { "en":{"success":"SUCCESS"}, "pt-br":{"success"SUCESSO!"} } $ cat

    lib/main.rb class Main < Device def self.call I18n.configure("app", "en") I18n.pt(:success) I18n.locale = "pt-br" I18n.pt(:success) getc true end end
  133. I18n $ cat resources/app/i18n.json { "en":{"success":"SUCCESS"}, "pt-br":{"success"SUCESSO!"} } $ cat

    lib/main.rb class Main < Device def self.call I18n.configure("app", "en") I18n.pt(:success) I18n.locale = "pt-br" I18n.pt(:success) getc true end end
  134. I18n $ cat resources/app/i18n.json { "en":{"success":"SUCCESS"}, "pt-br":{"success"SUCESSO!"} } $ cat

    lib/main.rb class Main < Device def self.call I18n.configure("app", "en") I18n.pt(:success) I18n.locale = "pt-br" I18n.pt(:success) getc true end end
  135. Rubygem

  136. Rubygem files = (`git ls-files -z`.split("\x0") files << “out/app/main.mrb”)

  137. Rubygem files = (`git ls-files -z`.split("\x0") files << “out/app/main.mrb”) Gem::Specification.new

    do |spec| spec.files = files end
  138. Rubygem files = (`git ls-files -z`.split("\x0") files << “out/app/main.mrb”) Gem::Specification.new

    do |spec| spec.files = files end resources.each do |file,dest| FileUtils.cp(file, dest) end
  139. None
  140. DEMO

  141. We're hiring thiago@cloudwalk.io

  142. Thank you @scalone THIAGO SCALONE - thiago@scalone.com.br