GEMS
Thursday, February 7, 13
@markbates
Thursday, February 7, 13
Thursday, February 7, 13
http://www.metacasts.tv
                           PROJNIGHT213


Thursday, February 7, 13
1. Konacha
                              http://www.metacasts.tv
                                  PROJNIGHT213
Thursday, February 7, 13
JavaScript/CoffeeScript
                               testing for Rails


                                http://www.metacasts.tv
                                    PROJNIGHT213
Thursday, February 7, 13
CoffeeScript                                                                     JavaScript
                           describe	
  "Calculator",	
  -­‐>                                     describe("Calculator",	
  function()	
  {
                           	
                                                                    	
  
                           	
  	
  beforeEach	
  -­‐>                                            	
  	
  beforeEach(function()	
  {
                           	
  	
  	
  	
  @calculator	
  =	
  new	
  Calculator()               	
  	
  	
  	
  this.calculator	
  =	
  new	
  Calculator();
                           	
                                                                    	
  	
  });
                           	
  	
  context	
  "add",	
  -­‐>                                     	
  
                           	
                                                                    	
  	
  context("add",	
  function()	
  {
                           	
  	
  	
  	
  it	
  "adds	
  two	
  numbers",	
  -­‐>               	
  
                           	
  	
  	
  	
  	
  	
  @calculator.add(2,	
  2).should.eql(4)        	
  	
  	
  	
  it("adds	
  two	
  numbers",	
  function()	
  {
                           	
                                                                    	
  	
  	
  	
  	
  	
  this.calculator.add(2,	
  2).should.eql(4);
                           	
  	
  	
  	
  context	
  "null	
  numbers",	
  -­‐>                 	
  	
  	
  	
  });
                           	
                                                                    	
  
                           	
  	
  	
  	
  	
  	
  it	
  "throws	
  an	
  exception",	
  -­‐>    	
  	
  	
  	
  context("null	
  numbers",	
  function()	
  {
                           	
  	
  	
  	
  	
  	
  	
  	
  expect(=>                             	
  
                           	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  @calculator.add(1,	
  null)   	
  	
  	
  	
  	
  	
  it("throws	
  an	
  exception",	
  function()	
  {
                           	
  	
  	
  	
  	
  	
  	
  	
  ).to.throw(NullNumberError)           	
  	
  	
  	
  	
  	
  	
  	
  var	
  _this	
  =	
  this;
                                                                                                 	
  	
  	
  	
  	
  	
  	
  	
  expect(function()	
  {
                                                                                                 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  _this.calculator.add(1,	
  null);
                                                                                                 	
  	
  	
  	
  	
  	
  	
  	
  }).to["throw"](NullNumberError);
                                                                                                 	
  	
  	
  	
  	
  	
  });
                                                                                                 	
  
                                                                                                 	
  	
  	
  	
  });
                                                                                                 	
  
                                                                                                 	
  	
  });
                                                                                                 	
  
                                                                                                 });



                                                                     http://www.metacasts.tv
                                                                         PROJNIGHT213
Thursday, February 7, 13
More Info
                                     https://github.com/jfirebaugh/konacha
                                     http://visionmedia.github.com/mocha/
                                                http://chaijs.com/
                           http://www.metacasts.tv/casts/unit-testing-javascript-in-rails




                                           http://www.metacasts.tv
                                               PROJNIGHT213
Thursday, February 7, 13
2. SideKiq
                             http://www.metacasts.tv
                                 PROJNIGHT213
Thursday, February 7, 13
Super fast
                           background workers


                              http://www.metacasts.tv
                                  PROJNIGHT213
Thursday, February 7, 13
class	
  MyWorker
                           	
  	
  include	
  Sidekiq::Worker
                           	
  	
  sidekiq_options	
  unique:	
  true
                           	
  
                           	
  	
  def	
  perform(some_attributes)
                           	
  	
  	
  	
  #	
  do	
  some	
  work	
  here
                           	
  	
  end
                           	
  
                           end
                           	
  
                           MyWorker.perform_async(some_attributes)




                               http://www.metacasts.tv
                                   PROJNIGHT213
Thursday, February 7, 13
http://www.metacasts.tv
                               PROJNIGHT213
Thursday, February 7, 13
More Info
                                   http://sidekiq.org/
                           https://github.com/mperham/sidekiq




                               http://www.metacasts.tv
                                   PROJNIGHT213
Thursday, February 7, 13
3. SunSpot
                             http://www.metacasts.tv
                                 PROJNIGHT213
Thursday, February 7, 13
Simple full-text
                           search using Solr


                            http://www.metacasts.tv
                                PROJNIGHT213
Thursday, February 7, 13
class	
  Post	
  <	
  ActiveRecord::Base
                           	
  	
  searchable	
  do
                           	
  	
  	
  	
  text	
  :title,	
  :body
                           	
  	
  	
  	
  text	
  :comments	
  do
                                                                                                         Post.search	
  do
                           	
  	
  	
  	
  	
  	
  comments.map	
  {	
  |comment|	
  comment.body	
  }
                                                                                                         	
  	
  fulltext	
  'best	
  pizza'
                           	
  	
  	
  	
  end
                                                                                                         	
  	
  with	
  :blog_id,	
  1
                           	
  	
  	
  	
  integer	
  :blog_id
                                                                                                         	
  	
  with(:published_at).less_than	
  Time.now
                           	
  	
  	
  	
  integer	
  :author_id
                                                                                                         	
  	
  order_by	
  :published_at,	
  :desc
                           	
  	
  	
  	
  integer	
  :category_ids,	
  multiple:	
  true
                                                                                                         	
  	
  paginate	
  page:	
  2,	
  per_page:	
  15
                           	
  	
  	
  	
  time	
  :published_at
                                                                                                         	
  	
  facet	
  :category_ids,	
  :author_id
                           	
  	
  	
  	
  string	
  :sort_title	
  do
                                                                                                         end
                           	
  	
  	
  	
  	
  	
  title.downcase.gsub(/^(an?|the)b/,	
  '')
                           	
  	
  	
  	
  end
                           	
  	
  end
                           end




                                                                       http://www.metacasts.tv
                                                                           PROJNIGHT213
Thursday, February 7, 13
More Info
                               http://sunspot.github.com/
                           https://github.com/sunspot/sunspot
                             http://lucene.apache.org/solr/




                              http://www.metacasts.tv
                                  PROJNIGHT213
Thursday, February 7, 13
4. Sinatra
                             http://www.metacasts.tv
                                 PROJNIGHT213
Thursday, February 7, 13
A DSL for quickly
                           creating Ruby Web Apps


                               http://www.metacasts.tv
                                   PROJNIGHT213
Thursday, February 7, 13
require	
  'sinatra'
                              	
  
                              get	
  '/'	
  do
                              	
  	
  'Hello	
  world!'
                              end




                           http://www.metacasts.tv
                               PROJNIGHT213
Thursday, February 7, 13
require	
  'sinatra'
                             	
  
                             get	
  '/'	
  do
                             	
  	
  erb	
  :index
                             end
                             	
  
                             __END__
                             	
  
                             @@	
  index
                             <div>Hello	
  World!</div>




                           http://www.metacasts.tv
                               PROJNIGHT213
Thursday, February 7, 13
require	
  'sinatra/base'
                            require	
  './todo'
                            require	
  'sinatra/twitter-­‐bootstrap'
                            require	
  './url_helpers'
                            	
  
                            class	
  TodoApp	
  <	
  Sinatra::Base
                            	
  	
  register	
  Sinatra::Twitter::Bootstrap::Assets
                            	
  
                            	
  	
  helpers	
  UrlHelpers
                            	
  
                            	
  	
  get	
  "/todos"	
  do
                            	
  	
  	
  	
  @todos	
  =	
  Todo.all
                            	
  	
  	
  	
  erb	
  :index
                            	
  	
  end
                            	
  
                            	
  	
  get	
  "/todos/new"	
  do
                            	
  	
  	
  	
  @todo	
  =	
  Todo.new
                            	
  	
  	
  	
  erb	
  :form
                            	
  	
  end
                            	
  
                            	
  	
  get	
  "/todos/:id"	
  do
                            	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                            	
  	
  	
  	
  redirect	
  edit_todo_path(@todo)
                            	
  	
  end
                            	
  
                            	
  	
  get	
  "/todos/:id/edit"	
  do
                            	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                            	
  	
  	
  	
  erb	
  :form
                            	
  	
  end
                            	
  
                            	
  	
  post	
  "/todos"	
  do
                            	
  	
  	
  	
  Todo.create(params[:todo])
                            	
  	
  	
  	
  redirect	
  todos_path
                            	
  	
  end
                            	
  
                            	
  	
  put	
  "/todos/:id"	
  do
                            	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                            	
  	
  	
  	
  @todo.update_attributes(params[:todo])
                            	
  	
  	
  	
  redirect	
  todos_path
                            	
  	
  end
                            	
  
                            	
  	
  delete	
  "/todos/:id"	
  do
                            	
  	
  	
  	
  @todo	
  =	
  Todo.find(params[:id])
                            	
  	
  	
  	
  @todo.destroy
                            	
  	
  	
  	
  redirect	
  todos_path
                            	
  	
  end
                            	
  
                            end
                            	
  
                            use	
  Rack::MethodOverride
                            run	
  TodoApp




                           http://www.metacasts.tv
                               PROJNIGHT213
Thursday, February 7, 13
More Info
                                              http://www.sinatrarb.com/
                                           https://github.com/sinatra/sinatra
                           http://www.metacasts.tv/casts/building-a-sinatra-application-pt-1
                           http://www.metacasts.tv/casts/building-a-sinatra-application-pt-2
                              http://www.metacasts.tv/casts/gettings-started-with-sinatra




                                             http://www.metacasts.tv
                                                 PROJNIGHT213
Thursday, February 7, 13
5. Foreman
                             http://www.metacasts.tv
                                 PROJNIGHT213
Thursday, February 7, 13
Manage Application
                              Commands


                              http://www.metacasts.tv
                                  PROJNIGHT213
Thursday, February 7, 13
web:	
  bundle	
  exec	
  thin	
  start	
  -­‐p	
  3000
                           solr:	
  bundle	
  exec	
  rake	
  sunspot:solr:run
                           worker:	
  bundle	
  exec	
  sidekiq




                                      http://www.metacasts.tv
                                          PROJNIGHT213
Thursday, February 7, 13
More Info
                           https://github.com/ddollar/foreman




                              http://www.metacasts.tv
                                  PROJNIGHT213
Thursday, February 7, 13
@markbates
Thursday, February 7, 13

5 Favorite Gems (Lightning Talk(

  • 1.
  • 2.
  • 3.
  • 4.
    http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 5.
    1. Konacha http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 6.
    JavaScript/CoffeeScript testing for Rails http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 7.
    CoffeeScript JavaScript describe  "Calculator",  -­‐> describe("Calculator",  function()  {        beforeEach  -­‐>    beforeEach(function()  {        @calculator  =  new  Calculator()        this.calculator  =  new  Calculator();      });    context  "add",  -­‐>        context("add",  function()  {        it  "adds  two  numbers",  -­‐>              @calculator.add(2,  2).should.eql(4)        it("adds  two  numbers",  function()  {              this.calculator.add(2,  2).should.eql(4);        context  "null  numbers",  -­‐>        });                it  "throws  an  exception",  -­‐>        context("null  numbers",  function()  {                expect(=>                      @calculator.add(1,  null)            it("throws  an  exception",  function()  {                ).to.throw(NullNumberError)                var  _this  =  this;                expect(function()  {                    _this.calculator.add(1,  null);                }).to["throw"](NullNumberError);            });          });      });   }); http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 8.
    More Info https://github.com/jfirebaugh/konacha http://visionmedia.github.com/mocha/ http://chaijs.com/ http://www.metacasts.tv/casts/unit-testing-javascript-in-rails http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 9.
    2. SideKiq http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 10.
    Super fast background workers http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 11.
    class  MyWorker    include  Sidekiq::Worker    sidekiq_options  unique:  true      def  perform(some_attributes)        #  do  some  work  here    end   end   MyWorker.perform_async(some_attributes) http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 12.
    http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 13.
    More Info http://sidekiq.org/ https://github.com/mperham/sidekiq http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 14.
    3. SunSpot http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 15.
    Simple full-text search using Solr http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 16.
    class  Post  <  ActiveRecord::Base    searchable  do        text  :title,  :body        text  :comments  do Post.search  do            comments.map  {  |comment|  comment.body  }    fulltext  'best  pizza'        end    with  :blog_id,  1        integer  :blog_id    with(:published_at).less_than  Time.now        integer  :author_id    order_by  :published_at,  :desc        integer  :category_ids,  multiple:  true    paginate  page:  2,  per_page:  15        time  :published_at    facet  :category_ids,  :author_id        string  :sort_title  do end            title.downcase.gsub(/^(an?|the)b/,  '')        end    end end http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 17.
    More Info http://sunspot.github.com/ https://github.com/sunspot/sunspot http://lucene.apache.org/solr/ http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 18.
    4. Sinatra http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 19.
    A DSL forquickly creating Ruby Web Apps http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 20.
    require  'sinatra'   get  '/'  do    'Hello  world!' end http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 21.
    require  'sinatra'   get  '/'  do    erb  :index end   __END__   @@  index <div>Hello  World!</div> http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 22.
    require  'sinatra/base' require  './todo' require  'sinatra/twitter-­‐bootstrap' require  './url_helpers'   class  TodoApp  <  Sinatra::Base    register  Sinatra::Twitter::Bootstrap::Assets      helpers  UrlHelpers      get  "/todos"  do        @todos  =  Todo.all        erb  :index    end      get  "/todos/new"  do        @todo  =  Todo.new        erb  :form    end      get  "/todos/:id"  do        @todo  =  Todo.find(params[:id])        redirect  edit_todo_path(@todo)    end      get  "/todos/:id/edit"  do        @todo  =  Todo.find(params[:id])        erb  :form    end      post  "/todos"  do        Todo.create(params[:todo])        redirect  todos_path    end      put  "/todos/:id"  do        @todo  =  Todo.find(params[:id])        @todo.update_attributes(params[:todo])        redirect  todos_path    end      delete  "/todos/:id"  do        @todo  =  Todo.find(params[:id])        @todo.destroy        redirect  todos_path    end   end   use  Rack::MethodOverride run  TodoApp http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 23.
    More Info http://www.sinatrarb.com/ https://github.com/sinatra/sinatra http://www.metacasts.tv/casts/building-a-sinatra-application-pt-1 http://www.metacasts.tv/casts/building-a-sinatra-application-pt-2 http://www.metacasts.tv/casts/gettings-started-with-sinatra http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 24.
    5. Foreman http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 25.
    Manage Application Commands http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 26.
    web:  bundle  exec  thin  start  -­‐p  3000 solr:  bundle  exec  rake  sunspot:solr:run worker:  bundle  exec  sidekiq http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 27.
    More Info https://github.com/ddollar/foreman http://www.metacasts.tv PROJNIGHT213 Thursday, February 7, 13
  • 28.