Skip to content

Instantly share code, notes, and snippets.

View jodosha's full-sized avatar

Luca Guidi jodosha

View GitHub Profile
@jodosha
jodosha / explanation.md
Last active August 29, 2015 14:00
Lotus::Repository: class vs instance methods

Given that an adapter brings its own query API, the implementation of the finders depends on the interface of the current adapter's query.

class ArticleRepository
  include Lotus::Repository

  def self.most_recent(limit = 5)
    query do
      desc(:created_at)
    end.limit(limit)
@jodosha
jodosha / coercer.rb
Created May 5, 2014 08:44
Bench for Lotus::Model coercer iteration vs metaprogramming
#!/usr/bin/env ruby
require 'rubygems'
require 'benchmark'
require 'benchmark/ips'
require 'lotus/model'
GC.disable
TIMES = ENV['TIMES'] || 1_000_000
# See https://github.com/lotus/model/blob/master/lib/lotus/model/mapping/coercer.rb
@jodosha
jodosha / falsey_vs_nil.rb
Created May 5, 2014 09:00
Falsey vs Nil check
#!/usr/bin/env ruby
require 'benchmark/ips'
class Coercer
def slow(input)
Integer(input) unless input.nil?
end
def fast(input)
Integer(input) if input
@jodosha
jodosha / gist:ade11746700fe23cd4f2
Last active August 29, 2015 14:01
Lotus application structure
# app/
# controllers/
# dashboard_controller.rb DashboardController::Index or Controllers::Dashboard::Index
# identity_controller.rb IdentityController::Edit|Update or Controllers::Identity::Edit|Update
# sessions_controller.rb SessionsController::New|Create|Destroy or Controllers::Sessions::New|Create|Destroy
# entities/
# account.rb Account
# identity.rb Identity
# person.rb Person
# interactors/
require 'test_helper'
describe Lotus::Router do
before do
@router = Lotus::Router.new do
get '/', to: ->(env) {}
get '/dashboard', to: 'this#does_not_exist'
get '/some_exception', to: ->(env) { raise StandardError.new('Hello') } # Was StandardError('Hello')
end
@app = Rack::MockRequest.new(@router)
@jodosha
jodosha / Gemfile
Created June 26, 2014 16:30
Lotus::View with Slim
source 'https://rubygems.org'
gem 'slim'
gem 'lotus-view'
@jodosha
jodosha / benchmark.rb
Last active August 29, 2015 14:03
Lotus::Utils Inheritance vs delegation https://github.com/lotus/utils/pull/14
#!/usr/bin/env ruby
require 'benchmark'
require_relative 'lib/lotus/utils/string'
TIMES = ENV['TIMES'] || 1_000_000
classify = Lotus::Utils::String.new('lotus_utils')
underscore = Lotus::Utils::String.new('Lotus::Utils')
demodulize = Lotus::Utils::String.new('Lotus::Utils::String')
namespace = Lotus::Utils::String.new('Lotus::Utils::String')
#!/usr/bin/env ruby
require 'benchmark'
require_relative 'lib/lotus/utils/hash'
TIMES = (ENV['TIMES'] || 1_000_000).to_i
symbolize = Lotus::Utils::Hash.new({'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5})
symbolize_nested = Lotus::Utils::Hash.new({'f' => { 'g' => { 'h' => { 'i' => {'j' => 10 }}}}})
Benchmark.bm(30) do |bm|
@jodosha
jodosha / class_loading_benchmark.rb
Last active August 29, 2015 14:04
Lotus::Utils vs ActiveSupport benchmarks
#!/usr/bin/env ruby
require 'benchmark'
require 'rubygems'
require 'active_support/core_ext/string/inflections' # v4.1.4
require 'lotus/utils/class' # v0.2.0
TIMES = (ENV['TIMES'] || 1_000_000).to_i
class Foo
end
@jodosha
jodosha / 00_tldr.md
Last active August 29, 2015 14:04
Lotus wrk benchmarks

Action

Lotus    (22.ru)  5018.70 req/s
Sinatra  (04.ru)  2922.74 req/s
Rails    (02.ru)  1148.16 req/s

Template