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
alias gti="git" | |
alias gst="git status" | |
alias gbr="git branch" | |
alias glg="git log" | |
alias gfu="git fetch upstream" | |
alias gfo="git fetch origin" | |
alias gpo="git push origin" | |
alias gpu="git push upstream" |
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
log/ |
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"} |