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' | |
def check?(a, value) | |
Array(a).include? value | |
end | |
a = (1..100).to_a | |
value = 500 | |
disabled = true | |
html_attributes = {} |
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' | |
def old_method(a) | |
return 'abc' unless a == true || a == false | |
a ? 1 : 0 | |
end | |
def new_method(a) | |
case a | |
when TrueClass | |
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
# ruby 2.0.0-p247 | |
require 'benchmark' | |
def old_method(&block) | |
yield | |
end | |
def new_method | |
yield | |
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
require 'active_model' | |
class Account | |
include ActiveModel::Model | |
attr_accessor :subdomain, :subdomain1, :subdomain2, :subdomain3, :size, :size1, :size2, :size3 | |
validates :subdomain, exclusion: { in: %w(www us ca jp) } | |
validates :subdomain1, exclusion: { in: %w(www us ca jp), message: "is reserverd" } | |
validates :subdomain2, exclusion: { in: %w(www us ca jp), message: "%{value} is reserverd" } | |
validates :subdomain3, exclusion: { in: %w(www us ca jp), message: "Subdomain %{value} is reserverd" } |
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' | |
def old_many?(enum) | |
cnt = 0 | |
enum.any? { (cnt += 1) > 1 } | |
end | |
def new_many?(enum) | |
enum.count > 1 | |
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
# RSpec matcher to spec delegations, taken from gist at | |
# https://gist.github.com/joeytheman/0fe021821e4c62f552ce | |
# | |
# Usage: | |
# | |
# describe Post do | |
# it { should delegate(:name).to(:author).with_prefix } # post.author_name | |
# it { should delegate(:name).to(:author).with_prefix(:any) } # post.any_name | |
# it { should delegate(:month).to(:created_at) } | |
# it { should delegate(:year).to(:created_at) } |
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
# Login as root | |
ssh root@domain | |
# Create deploy user | |
adduser <username> #Adds User with username given. Enter Password when Prompted. Other Details are Optional | |
# Add user to sudo group | |
usermod -g <groupname> <username> | |
# Add .ssh/authorized_keys for deploy user |
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
# encoding: utf-8 | |
# # | |
# # RFC822 Email Address Regex | |
# # -------------------------- | |
# # | |
# # Originally written by Cal Henderson | |
# # c.f. http://iamcal.com/publish/articles/php/parsing_email/ | |
# # | |
# # Translated to Ruby by Tim Fletcher, with changes suggested by Dan Kubb. | |
# # |