jRuby para sua diversão e lucro

jRuby para sua diversão e lucro

Por que é relevante saber um pouco sobre jRuby? Alguns exemplos práticos do uso de jRuby no dia-a-dia de um programador Java, porque usar jRuby pode ser divertido e ainda lucrativo.

9000c1da9ef46a5ad8a64da511a897be?s=128

Kristopher Murata

November 24, 2012
Tweet

Transcript

  1. jRuby LUCRO para sua diversão e Saturday, November 24, 12

  2. Kristopher Murata @krsmurata murata.co /home/kris Saturday, November 24, 12

  3. COMMITA.COM FoodieRegistry.com /home/kris Saturday, November 24, 12

  4. /home/kris Saturday, November 24, 12

  5. •Java n00b /home/kris Saturday, November 24, 12

  6. •Java n00b •Speaker n00b /home/kris Saturday, November 24, 12

  7. •Java n00b •Speaker n00b •Rubyist /home/kris Saturday, November 24, 12

  8. •Java n00b •Speaker n00b •Rubyist /home/kris Saturday, November 24, 12

  9. jRuby para sua diversão e lucro Saturday, November 24, 12

  10. •jRuby é Ruby compilado para Bytecode que roda na JVM

    •jRuby está na versão 1.7 •jRuby tem +10 anos (começou em 2001) Saturday, November 24, 12
  11. Saturday, November 24, 12

  12. Saturday, November 24, 12

  13. diversão jRuby para sua e lucro Saturday, November 24, 12

  14. http://www.flickr.com/photos/33284937@N04/5734316836/ Saturday, November 24, 12

  15. OPS, Not funny :( http://www.flickr.com/photos/spunkinator/3109602958 Saturday, November 24, 12

  16. http://www.flickr.com/photos/pepe50/2185639779 Saturday, November 24, 12

  17. http://www.flickr.com/photos/chadwise/423746682/ #HoraExtra Saturday, November 24, 12

  18. programador O que é diversão para um ? Saturday, November

    24, 12
  19. /ha /say HuaHauhaUHahuaUauAHUhauhaUHahuuahuah mIRC scripting Saturday, November 24, 12

  20. PHP <?php echo "<textarea name='mydata'>\n"; echo htmlspecialchars($data)."\n"; echo "</textarea>"; for

    ($i = 1; $i <= 10; $i++) { echo "<p>YAY Tô no loop \o/</p>"; } ?> Saturday, November 24, 12
  21. Assembly mov cx, 0 ; cx stores number of characters

    mov bx, offset message ; store address of message in bx begin: cmp byte ptr [bx], 0 ; is this end of string? je fin ; if yes goto Finished inc cx ; cx = cx + 1 inc bx ; bx points to next character jmp begin Saturday, November 24, 12
  22. Assembly mov cx, 0 ; cx stores number of characters

    mov bx, offset message ; store address of message in bx begin: cmp byte ptr [bx], 0 ; is this end of string? je fin ; if yes goto Finished inc cx ; cx = cx + 1 inc bx ; bx points to next character jmp begin int stringlength = string.length(); Java Saturday, November 24, 12
  23. Saturday, November 24, 12

  24. Recursividade public class Fibonacci { public static long fib(int n)

    { if (n <= 1) return n; else return fib(n-1) + fib(n-2); } public static void main(String[] args) { int N = Integer.parseInt(args[0]); for (int i = 1; i <= N; i++) System.out.println(i + ": " + fib(i)); } } Saturday, November 24, 12
  25. Ordenação BubbleSort Folk Dance http://www.youtube.com/user/AlgoRythmics (InsertionSort, SelectionSort, MergeSort, QuickSort...) Saturday,

    November 24, 12
  26. jRuby OK, mas por que é divertido? Saturday, November 24,

    12
  27. Ruby.can_read?(“Java”) # => true Porque com jRuby você pode... Saturday,

    November 24, 12
  28. require 'java' java_hashmap = java.util.HashMap.new java_hashmap.put(:foo, "bar") puts java_hashmap.get(:foo) #

    => bar puts java_hashmap[:foo] # => bar puts java_hashmap.java_class # => java.util.HashMap Saturday, November 24, 12
  29. require "java" java_import javax.swing.JFrame java_import javax.swing.JButton java_import javax.swing.JOptionPane class HelloWorld

    < JFrame def initialize super "Example" setSize(150, 100) setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE) setLocationRelativeTo(nil) button = JButton.new("Say Hello") add(button) button.addActionListener do |e| JOptionPane.showMessageDialog(nil, "Hello World") end setVisible(true) end end Saturday, November 24, 12
  30. require "java" require "mvn:com.yammer.metrics:metrics-core" counter = com.yammer.metrics.Metrics.new_counter(...) gem install mvn:com.yammer.metrics:metrics-core

    Saturday, November 24, 12
  31. OMG, Threads! Saturday, November 24, 12

  32. def fib(n) n < 2 ? n : fib(n-1) +

    fib(n-2) end start = Time.now 1.upto(10).map do |n| " Thread.new do " " puts "Thread #{n}: #{fib(32)}" " end end puts "Time: #{Time.now - start}" Saturday, November 24, 12
  33. Java.canRead(“Ruby”); Saturday, November 24, 12

  34. Java.canRead(“Ruby”); Saturday, November 24, 12

  35. class MyMath def sum(a, b) puts a + b end

    end Saturday, November 24, 12
  36. class MyMath def sum(a, b) puts a + b end

    end jrubyc --javac ~/dev/jruby/rubyj/ my_math.rb Saturday, November 24, 12
  37. class MyMath def sum(a, b) puts a + b end

    end jrubyc --javac ~/dev/jruby/rubyj/ my_math.rb ~> ls ~/dev/jruby/rubyj MyMath.class MyMath.java my_math.rb Saturday, November 24, 12
  38. class MyMath def sum(a, b) puts a + b end

    end jrubyc --javac ~/dev/jruby/rubyj/ my_math.rb ~> ls ~/dev/jruby/rubyj MyMath.class MyMath.java my_math.rb java -cp ~/.rvm/rubies/jruby-1.7.0/ lib/jruby.jar:. MyMath Saturday, November 24, 12
  39. public Object sum(Object a, Object b) { IRubyObject ruby_a =

    JavaUtil.convertJavaToRuby(__ruby__, a); IRubyObject ruby_b = JavaUtil.convertJavaToRuby(__ruby__, b); IRubyObject ruby_result = RuntimeHelpers.invoke( __ruby__.getCurrentConte xt(), this, "sum", ruby_a, ruby_b); return (Object)ruby_result.toJava(Object.class); } Saturday, November 24, 12
  40. require 'java' java_require 'my_math' class MyMath java_signature 'void sum(int, int)'

    " def sum(a, b) puts a + b end end static { __ruby__.getLoadService().lockAndRequire("my_math"); ... } public void sum(int a, int b) { ... } Saturday, November 24, 12
  41. require 'java' java_require 'my_math' class MyMath java_signature 'void main(String[])' def

    self.main(args) sum(args[0], args[1]) end java_signature 'void sum(int, int)' def self.sum(a, b) puts a + b end end Saturday, November 24, 12
  42. ~> java -cp ~/.rvm/rubies/jruby-1.7.0/lib/jruby.jar:. MyMath 20 30 => 2030 Saturday,

    November 24, 12
  43. ~> java -cp ~/.rvm/rubies/jruby-1.7.0/lib/jruby.jar:. MyMath 20 30 => 2030 Saturday,

    November 24, 12
  44. require 'java' java_require 'my_math' class MyMath java_signature 'void main(String[])' def

    self.main(args) sum(args[0], args[1]) end java_signature 'void sum(int, int)' def self.sum(a, b) puts a + b end end Saturday, November 24, 12
  45. require 'java' java_require 'my_math' class MyMath java_signature 'void main(String[])' def

    self.main(args) sum(args[0], args[1]) end java_signature 'void sum(int, int)' def self.sum(a, b) puts a.to_i + b.to_i end end Saturday, November 24, 12
  46. Rhino (JS) Saturday, November 24, 12

  47. LUCRO jRuby para sua diversão e Saturday, November 24, 12

  48. Programador Saturday, November 24, 12

  49. CHEFE Saturday, November 24, 12

  50. O chefe antenado Saturday, November 24, 12

  51. Esse sistema de relatórios no SysJava é chato pra cara$%&#.

    Saturday, November 24, 12
  52. Nosso próximo projeto será em Ruby on Rails, porque é

    10x mais produtivo que Java! Saturday, November 24, 12
  53. A equipe precisa de treinamento, a curva de aprendizagem é

    alta e o prazo é curto. Isso é inviável. Saturday, November 24, 12
  54. Ok, então vamos contratar uma nova equipe de Rails Rockstars

    (Jedis, Ninjas, Milagreiros...) e você vai ficar alocado na equipe Rails. Saturday, November 24, 12
  55. Até que esse tal de Ruby é bacaninha. Saturday, November

    24, 12
  56. Programador, lembra do SysJava? Precisamos daqueles relatórios no nosso outro

    projeto SysRails. Deve ser coisa rápida, só copiar. Depois de um mês... Saturday, November 24, 12
  57. OK. Saturday, November 24, 12

  58. OK. FUUUUUU%*%%!!! FD$%ˆ#!! Saturday, November 24, 12

  59. soluções? Quais são as possíveis Saturday, November 24, 12

  60. Saturday, November 24, 12

  61. •Portar toda a lógica do SysJava para o SysRails. Saturday,

    November 24, 12
  62. •Portar toda a lógica do SysJava para o SysRails. •Fazer

    uma API (REST/SOA) no SysJava Saturday, November 24, 12
  63. •Portar toda a lógica do SysJava para o SysRails. •Fazer

    uma API (REST/SOA) no SysJava •jRuby for the rescue! Saturday, November 24, 12
  64. require 'path/to/mycode.jar' OU java_import 'example.report.Reports' java_import 'example.report.ReportsFull' Saturday, November 24,

    12
  65. Não estou gostando dessa infra de deploy. Saturday, November 24,

    12
  66. https://speakerdeck.com/headius/aloha-rubyconf-2012-jruby Saturday, November 24, 12

  67. http://torquebox.org + Torquebox = Saturday, November 24, 12

  68. https://speakerdeck.com/headius/aloha-rubyconf-2012-jruby Saturday, November 24, 12

  69. •Rack friendly •Daemons •Scheduled jobs •Messaging •Async Tasks •Caching •WebSockets

    Features Saturday, November 24, 12
  70. Programador, precisamos colocar o SysRails nas NUVENS!!! Mais alguns meses...

    Saturday, November 24, 12
  71. Hehehe, essa é fácil. Saturday, November 24, 12

  72. Can we has Cloud? •Heroku (Buildpack) •EngineYard (Trinidad) •OpenShift (Torquebox)

    •CloudBees (Warbler) •Google AppEngine Saturday, November 24, 12
  73. Where`s my money, bro? Saturday, November 24, 12

  74. Sistemas Heterogêneos Saturday, November 24, 12

  75. POLIGLOTA Programador Saturday, November 24, 12

  76. referências Saturday, November 24, 12

  77. Tobias Talk http://www.eventials.com/rubyconfbr2012/ https://github.com/tobias/rubyconfbr-demo/ Saturday, November 24, 12

  78. http://pragprog.com/news/black-friday-cyber-monday-40-off-sale code: TURKEY Saturday, November 24, 12

  79. http://www.confreaks.com/videos?search=jruby Saturday, November 24, 12

  80. Get out of the couch! Saturday, November 24, 12

  81. Obrigado! slides: http://murata.co Perguntas? Saturday, November 24, 12