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

Using Ruby for Reliability, Consistency, Speed ...

hone
September 24, 2014

Using Ruby for Reliability, Consistency, Speed - CNX2014

Talk at Exact Target Connections 2014

Ruby is just over 20 years old. It's no longer young or hip, and that’s a good thing! In the last decade, Ruby has matured as a web technology. It's being used in many successful companies out there such as Hulu, GitHub, and Bloomberg. The ecosystem is comprised of many stable libraries and tools to handle most common web tasks, allowing you to focus on adding features to improve your product and better serve your customers. We'll talk about how you can build scalable and reliable software, but still maintain fast development turnaround by leveraging the maturity and creativity of the Ruby community.

hone

September 24, 2014
Tweet

More Decks by hone

Other Decks in Programming

Transcript

  1. Track: Developers #CNX14 Track: Developers #CNX14 “I believe that the

    purpose of life is, at least in part, to be happy. Based on this belief, Ruby is designed to make programming not only easy but also fun. It allows you to concentrate on the creative side of programming, with less stress.” - Yukihiro Matsumoto, “Matz”, まつもとゆきひろ
  2. Track: Developers #CNX14 1995 - Ruby 0.95 1995 - Java

    1.0 1996 - Ruby 1.0 2000 - Programming Ruby Released 2003 - Ruby 1.8
  3. Track: Developers #CNX14 1995 - Ruby 0.95 1995 - Java

    1.0 1996 - Ruby 1.0 2000 - Programming Ruby Released 2003 - Ruby 1.8 2007 - Ruby 1.9
  4. Track: Developers #CNX14 1995 - Ruby 0.95 1995 - Java

    1.0 1996 - Ruby 1.0 2000 - Programming Ruby Released 2003 - Ruby 1.8 2007 - Ruby 1.9 2011 - Ruby 1.9.3
  5. Track: Developers #CNX14 1995 - Ruby 0.95 1995 - Java

    1.0 1996 - Ruby 1.0 2000 - Programming Ruby Released 2003 - Ruby 1.8 2007 - Ruby 1.9 2011 - Ruby 1.9.3 2/2013 - Ruby 2.0.0 12/2013 - Ruby 2.1.0
  6. Track: Developers #CNX14 1995 - Ruby 0.95 1995 - Java

    1.0 1996 - Ruby 1.0 2000 - Programming Ruby Released 2003 - Ruby 1.8 2007 - Ruby 1.9 2011 - Ruby 1.9.3 2/2013 - Ruby 2.0.0 12/2013 - Ruby 2.1.0 12/2014 - Ruby 2.2.0
  7. Track: Developers #CNX14 Fuji is the new Leica "Fuji is

    the new Leica. It's true! Fuji is making the world's best cameras, in every way, especially when it comes to functional design considerations. They are the only company that putting a priority on Human-Centered Design that isn't also charging $7,000 for their cameras."
  8. Track: Developers #CNX14 "Often people, especially computer engineers, focus on

    the machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines." - Yukihiro Matsumoto, “Matz”, まつもとゆきひろ
  9. Track: Developers #CNX14 COLORS = { black: "000", blue: "00f",

    white: "fff" } class String COLORS.each do |color,code| define_method "in_#{color}" do "<span style=\"color: ##{code}\">#{self}</span>" end end end puts "Hello World".in_blue "<span style=\"color: #00f\">Hello, World!</span>"
  10. Track: Developers #CNX14 Companies Using Ruby Amazon Good Reads Hulu

    Cookpad Bloomberg New York Times Basecamp Red Hat
  11. Track: Developers #CNX14 mruby #include <stdio.h> #include <mruby.h> #include <mruby/compile.h>

    int main(void) { mrb_state *mrb = mrb_open(); char code[] = "5.times { puts 'mruby is awesome!' }"; printf("Executing Ruby code with mruby:\n"); mrb_load_string(mrb, code); mrb_close(mrb); return 0; }
  12. Track: Developers #CNX14 RubyMotion Command line based tooling for iOS,

    Mac, and Android. Basecamp Frontback Jukely Bandcamp
  13. Track: Developers #CNX14 JRuby $ jruby -S jirb_swing require 'java'

    frame = javax.swing.JFrame.new("Window") label = javax.swing.JLabel.new("Hello") frame.add(label) frame.setDefaultCloseOperation(javax.swing.JFrame::EXIT_ON_CLOSE) frame.pack frame.setVisible(true)
  14. Track: Developers #CNX14 Bundler $ bundle install Fetching gem metadata

    from https: //rubygems.org/......... Resolving dependencies... Using bundler 1.6.2 Installing rspec-support 3.1.0 Installing diff-lcs 1.2.5 Installing rspec-mocks 3.1.1 Installing rspec-expectations 3.1.1 Installing rspec-core 3.1.4 Installing rspec 3.1.0 Your bundle is complete!
  15. Track: Developers #CNX14 Bundler # Gemfile.lock GEM remote: https://rubygems.org/ specs:

    diff-lcs (1.2.5) rspec (3.1.0) rspec-core (~> 3.1.0) rspec-expectations (~> 3.1.0) rspec-mocks (~> 3.1.0) rspec-core (3.1.4) rspec-support (~> 3.1.0) rspec-expectations (3.1.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.1.0) rspec-mocks (3.1.1) rspec-support (~> 3.1.0) rspec-support (3.1.0) PLATFORMS ruby DEPENDENCIES rspec
  16. Track: Developers #CNX14 Bundler # Gemfile ruby '2.1.2' gem 'rack'

    $ bundle install Your Ruby version is 1.9.3, but your Gemfile specified 2.1.2
  17. Track: Developers #CNX14 Rack # Gemfile gem 'rack' # config.ru

    run Proc.new {|env| ['200', {'Content-Type' => 'text/html'}, ['Hello World!']] } $ bundle exec rackup
  18. Track: Developers #CNX14 Sinatra require 'sinatra' get '/hi' do "Hello

    World!" end $ gem install sinatra $ ruby hi.rb == Sinatra has taken the stage ... >> Listening on 0.0.0.0:4567 $ curl http://localhost:4567 Hello World!
  19. Track: Developers #CNX14 Ruby on Rails $ gem install rails

    $ rails new hi create create README.rdoc create Rakefile create config.ru create .gitignore create Gemfile create app ...
  20. Track: Developers #CNX14 ActionController class ArticlesController < ApplicationController def index

    @articles = Article.all @article = Article.new end def show respond_to do |format| format.html { render :file => "#{Rails.root}/public/404.html", :status => 404 } format.json { render :show } end
  21. Track: Developers #CNX14 Generators $ bin/rails generate scaffold $ bin/rails

    generate controller $ bin/rails generate model $ bin/rails generate migration $ bin/rails generate helper $ bin/rails generate mailer
  22. Track: Developers #CNX14 Content Delivery Network (CDN) $ heroku addons:add

    fastly # config/environments/production.rb config.action_controller.asset_host = ENV['FASTLY_CDN_URL'] config.static_cache_control = 'public, s-maxage=2592000, maxage=86400'
  23. Track: Developers #CNX14 Sidekiq # Gemfile gem 'sidekiq' # job.rb

    class Job include Sidekiq::Worker def perform(path, host, port = 80) http = Net::HTTP.new(host, port) http.request(Net::HTTP::Get.new(path) end end
  24. Track: Developers #CNX14 RSpec # Gemfile gem 'rspec' # my_class_spec.rb

    describe MyClass do before { ... } let(:foo) { MyClass.new } it 'accesses the example' do expect(foo.bar).to eq("bar") end end
  25. Track: Developers #CNX14 rspec-mocks book = double("book", :pages => 250)

    allow(book).to receive(:title) { "The RSpec Book" }
  26. Track: Developers #CNX14 rspec-mocks book = double("book", :pages => 250)

    allow(book).to receive(:title) { "The RSpec Book" } it "calculates the read time" do book = double("book") expect(book).to receive(:read_time) { 12.4 } user.reads(book) end
  27. Track: Developers #CNX14 Artifice # Gemfile gem 'artifice' # test

    file class MockEndpoint < Sinatra::Base get "/endpoint" do "foo bar" end end Artifice.activate_with(MockEndpoint) do # make some requests using Net::HTTP end
  28. Track: Developers #CNX14 rspec-rails RSpec.describe User, :type => :model do

    it "orders by last name" do lindeman = User.create!(first_name: "Andy", last_name: "Lindeman") chelimsky = User.create!(first_name: "David", last_name: "Chelimsky") expect(User.ordered_by_last_name).to eq([chelimsky, lindeman]) end end
  29. Track: Developers #CNX14 rspec-rails RSpec.describe PostsController, :type => :controller do

    describe "GET #index" do it "responds successfully with an HTTP 200 status code" do get :index expect(response).to be_success expect(response).to have_http_status(200) end end end
  30. Track: Developers #CNX14 ember.js # Gemfile gem 'ember-rails' $ bin/rails

    generate ember:bootstrap in app/assets/javascripts/: controllers/ helpers/ components/ models/ routes/ templates/components views/
  31. Track: Developers #CNX14 require 'pismo' require 'sentimental' require 'ots' require

    'tokenizer' class Article def summarize doc = Pismo::Document.new(self.url) sent = Sentimental.new tokenizer = Tokenizer::Tokenizer.new tokens = tokenizer.tokenize(doc.body) poly_syl = tokens.select {|word| Lingua::EN::Syllable.syllables(word) >= 3 }.size self.title = doc.title self.image = doc.images.blank? ? nil : doc.images.first self.topics = OTS.parse(doc.body).topics self.sentiment = sent.get_sentiment(doc.body) self.words = tokens.size self.difficulty = smog(poly_syl, doc.sentences.size || 1) / 12 wpm = (200 - 100 * self.difficulty) || 1 self.minutes = (self.words / wpm.to_f).ceil end end
  32. Track: Developers #CNX14 the metal \m/ • separate middleware •

    API for request/response objects • request has read I/O for post body • response has write I/O for output
  33. Track: Developers #CNX14 Ruby is not young. It may not

    even be hip, but it has a rich 20 year history.
  34. Track: Developers #CNX14 Ruby has a rich history. There's a

    Ruby for all kinds of shapes and sizes. There's a vibrant ecosystem of libraries, tools, and practices surrounding Ruby. Recap Slide 1 2 3
  35. Track: Developers #CNX14 CUSTOMER JOURNEY SHOWCASE MARKETING THOUGHT LEADERS EMAIL

    MARKETING PRODUCT STRATEGY & ROADMAP PERSONAL TRANSFORMATION & GROWTH SOCIAL MARKETING MOBILE & WEB MARKETING DEVELOPERS HANDS-ON TRAINING INDUSTRY TRENDSETTERS CREATIVITY & INNOVATION SALESFORCE FOR MARKETERS ROUNDTABLES