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
class NullUser | |
User.reflections.each do |key, value| | |
name = key.to_s | |
if value.collection? | |
eval <<-RUBY | |
def #{name} | |
#{value.klass}.none | |
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
class ErrorPages < Ambulance::App | |
# idea 0: rails' rescue_from | |
rescue_from CanCan::AccessDenied, ActiveRecord::NotFound, ActionController::RoutingError do |exception| | |
render file: 'public/404.html', status: :not_found, layout: false | |
end | |
# idea 1: | |
routes ActiveRecord::NotFound, | |
ActionController::RoutingError, to: 404 |
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
# config/application.rb | |
config.exceptions_app = ->(env) { ErrorsController.action(:show).call(env) } |
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
BRANCH=0.16-stable; M=`git log --pretty=format:'%s' master | sort`; B=`git log --pretty=format:'%s' $BRANCH | sort`; diff <(echo "${MASTER}") <(echo "${B}") | grep "^>" |
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
class BaseNotifier < ActivePush::Base | |
self.notifier_name = "base_notifier" | |
default gcm: {collapse_key: '...', delay_while_idle: false}, | |
wp: { | |
message_id: 'message id', | |
notification_class: 'notification class', | |
windowsphone_target: 'target' | |
} |
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
class ApplicationController < ActionController::Base | |
before_filter :override_request_formats | |
def override_request_formats | |
request.formats = [:json] | |
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
require 'benchmark/ips' | |
Benchmark.ips do |x| | |
NEGATIVE = "-1" | |
ZERO = "0" | |
ONE = "1" | |
TWO = "2" | |
x.report("Array#max ( -1)") { [NEGATIVE.to_i, 1].max - 1 } | |
x.report("Array#max ( 0)") { [ ZERO.to_i, 1].max - 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
class Array | |
def to_proc | |
->(obj) { obj[first] } | |
end unless method_defined?(:to_proc) | |
end | |
users = [ | |
{name: "Matz"}, | |
{name: "DHH"}, | |
{name: "Yuki"} |
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 |x| | |
x.report "nothing" do | |
[1, 2, 3] | |
end | |
x.report "#-" do | |
[1, 2, 3] - [3] | |
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
Calculating ------------------------------------- | |
each_char 924.000 i/100ms | |
each_codepoint 1.381k i/100ms | |
------------------------------------------------- | |
each_char 9.320k (± 5.1%) i/s - 47.124k | |
each_codepoint 13.857k (± 3.6%) i/s - 70.431k | |
Comparison: | |
each_codepoint: 13857.4 i/s | |
each_char: 9319.5 i/s - 1.49x slower |
OlderNewer