This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
Benchmark.ips do |bm| | |
# Create a list with 10_000 elements and some nil values | |
list = (0..10_000).to_a | |
fn = ->(x) { x+1 if x.even? } | |
bm.report "select + map" do | |
list.select {|x| x.even? }.map {|x| x+1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
Benchmark.ips do |bm| | |
# Create a list with 10_000 elements and some nil values | |
list = (0..10_000).to_a | |
fn = ->(x) { [x, x * x] if x.even? } | |
bm.report "flat_map + compact" do | |
list.flat_map(&fn).compact |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'securerandom' | |
require 'digest' | |
require 'benchmark' | |
# Test weight | |
n = 1_000 | |
started_time = Time.now | |
word_1k = SecureRandom.hex(512) | |
word_10k = SecureRandom.hex(5_120) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'countries/iso3166' | |
class CreateCountries < ActiveRecord::Migration[6.0] | |
def change | |
create_table :countries do |t| | |
t.string :name, limit: 64 | |
t.string :name_it, limit: 64 | |
t.integer :region, limit: 1 | |
t.string :iso2, limit: 2 | |
t.string :phone_prefix, limit: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Session controller provides a token | |
#/controllers/api/sessions_controller.rb | |
class Api::SessionsController < Devise::SessionsController | |
before_filter :authenticate_user!, :except => [:create] | |
before_filter :ensure_params_exist, :except => [:destroy] | |
respond_to :json | |
def create | |
resource = User.find_for_database_authentication(:email => params[:user_login][:email]) | |
return invalid_login_attempt unless resource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#yield | |
class A | |
def go(*attrs) | |
p "Before block" | |
attrs.each do |attr| | |
p yield(attr) | |
end if block_given? | |
p "After block" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Add this new method | |
#activeadmin-0.4.0\lib\active_admin\views\pages\show.rb | |
#after def attributes_table | |
def attributes_table_for_resource(specified_resource, *args, &block) | |
panel(I18n.t('active_admin.details', :model => "#{specified_resource.class.name} #{specified_resource.id}")) do | |
attributes_table_for specified_resource, *args, &block | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it: | |
errors: | |
messages: | |
expired: "è scaduto ed è necessario richiederne uno nuovo" | |
not_found: "non trovato" | |
already_confirmed: "è già stato confermato, riprova a collegarti" | |
not_locked: "non era bloccato" | |
not_saved: | |
one: "un errore ha impedito il salvataggio di %{resource}:" | |
other: "%{count} errori hanno impedito il salvataggio di %{resource}:" |