Skip to content

Instantly share code, notes, and snippets.

View jodosha's full-sized avatar

Luca Guidi jodosha

View GitHub Profile
<%=
form_for :book, routes.book_path(id: book.id), values: { book: book } do |f|
div do
f.text_field :title
end
end
%>
module Web::Controllers::Books
class Create
def call(params)
puts params[:book] # => {:title => "TDD"}
end
end
end
@jodosha
jodosha / bench.rb
Created January 7, 2016 08:53
Ruby bench: String#+ vs String concat "#{ }"
#!/usr/bin/env ruby
require 'bundler/setup'
require 'benchmark/ips'
require 'lotus/utils/string'
GC.disable
ENGINE_TYPE = Lotus::Utils::String.new('Lotus::Assets::Compressors::Javascript').demodulize.classify.freeze
ENGINE_NAME = :uglifier
@jodosha
jodosha / tap_vs_linear.rb
Created November 30, 2015 10:45
Lotus::Utils::String#rsub bench
#!/usr/bin/env ruby
require 'bundler/setup'
require 'benchmark/ips'
require 'lotus/utils/string'
# Comparing
=begin
def rsub_tap(pattern, replacement)
self.class.new(@string.dup).tap do |s|
if i = rindex(pattern)
source 'https://rubygems.org'
gem 'mail'
gem 'broken_string_blank', git: 'https://gist.github.com/c7ec3b778631a5a038fc.git', require: false
@jodosha
jodosha / broken_string_blank.gemspec
Created November 29, 2015 11:13
Broken String#blank?
Gem::Specification.new do |s|
s.name = 'broken_string_blank'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'Luca Guidi'
s.email = 'me@lucaguidi.com'
s.summary = 'Broken String#blank?'
s.description = 'Demo'
s.files = ['broken_string_blank.rb']
@jodosha
jodosha / associations_test.rb
Created October 16, 2015 14:46
Test for Lotus::Model associations
require 'bundler/setup'
require 'lotus/model'
require 'lotus/model/migrator'
require 'pg'
class Bicycle
include Lotus::Entity
attributes :parts
end
@jodosha
jodosha / bench.rb
Created October 7, 2015 08:32
Ruby inflectors benchmark
#!/usr/bin/env ruby
require 'rubygems'
require 'benchmark/ips'
require 'allocation_stats'
require 'lotus/utils/inflector'
require 'inflecto'
require 'active_support/inflector'
GC.disable
@jodosha
jodosha / bench.rb
Last active August 29, 2015 14:19
Lotus::Utils::String#pluralize vs ActiveSupport String#pluralize
#!/usr/bin/env ruby
$:.unshift 'lib'
require 'benchmark/ips'
require 'lotus/utils/string'
require 'active_support/all'
GC.disable
TEST_PLURALS = {
"murex" => "murices",
Chapter 01
* RSpec: --test=rspec option for app generator
Chapter 02
* Migrations: they are a work in progress.
* Lotus comes with a filesystem adapter, which is a great tool for quick prototyping because it's schemaless. For the initial iteractions I use it and then switch to a relational database as soon it becomes painful to work with it.
* I usually use top level entities and repositories, but this is up to the developer.
Chapter 03
* It's lotus generate action web articles#show