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
array = 1_000_000.times.map{ rand(0..3) } | |
Benchmark.bm do |x| | |
x.report('check') { array.each_slice(2){|a,b| b == 0 ? 0 : a / b } } | |
x.report('rescue') { array.each_slice(2){|a,b| a / b rescue 0 } } | |
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
#!/usr/bin/env ruby | |
console = File.expand_path(File.dirname(__FILE__), '.') + "/console" | |
exec console, *ARGV, '--irb=pry' |
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
module October | |
class Daemon | |
attr_reader :child, :root, :env | |
def initialize(root, env = nil) | |
@root = root | |
@env = env | |
end | |
def spawn! |
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
module UTF8 | |
module Params | |
private | |
def normalize_parameters_with_encoding(value) | |
normalize_parameters_without_encoding(value).tap do |value| | |
value.force_encoding(Encoding.default_external) if value.respond_to?(:force_encoding) | |
end | |
end | |
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
class Example | |
attr_reader :value | |
def initialize(value) | |
@value = value | |
end | |
def truthy? | |
!!@value | |
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
preload_app true | |
worker_processes 2 | |
listen 3000 | |
before_fork do |server, worker| | |
ActiveRecord::Base.connection.disconnect! | |
end | |
after_fork do |server, worker| |
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
NoMethodError: | |
undefined method `split' for ["blob"]:Array | |
# /Users/mikz/.rvm/gems/ruby-1.9.3-p125-falcon@thesis/gems/rspec-expectations-2.9.0/lib/rspec/expectations/differ.rb:13:in `diff_as_string' | |
# /Users/mikz/.rvm/gems/ruby-1.9.3-p125-falcon@thesis/gems/rspec-expectations-2.9.0/lib/rspec/expectations/fail_with.rb:25:in `fail_with' | |
# /Users/mikz/.rvm/gems/ruby-1.9.3-p125-falcon@thesis/gems/rspec-expectations-2.9.0/lib/rspec/expectations/handler.rb:17:in `handle_matcher' | |
# /Users/mikz/.rvm/gems/ruby-1.9.3-p125-falcon@thesis/gems/rspec-expectations-2.9.0/lib/rspec/expectations/extensions/kernel.rb:12:in `should' | |
# /Users/mikz/.rvm/gems/ruby-1.9.3-p125-falcon@thesis/gems/rspec-core-2.9.0/lib/rspec/core/subject.rb:54:in `should' | |
# ./spec/test_spec.rb:5:in `block (2 levels) in <top (required)>' |
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
var d = new Date() | |
var h = d.getHours() | |
if (h < 5){ | |
document.write("Today is ") | |
} | |
else | |
if (h < 9){ | |
document.write("Today is ") | |
} |
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
diff --git a/test/test_helpers/redis.rb b/test/test_helpers/redis.rb | |
index 3ba8649..fd0fa1e 100644 | |
--- a/test/test_helpers/redis.rb | |
+++ b/test/test_helpers/redis.rb | |
@@ -1,7 +1,13 @@ | |
+require 'backend/storage' | |
+ | |
module TestHelpers | |
module Redis | |
private |
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
def instance_method_already_implemented?(method_name) | |
method_name = method_name.to_s | |
return true if method_name =~ /^id(=$|\?$|$)/ | |
@_defined_class_methods ||= ancestors.first(ancestors.index(ActiveRecord::Base)).sum([]) { |m| m.public_instance_methods(false) | m.private_instance_methods(false) | m.protected_instance_methods(false) }.map(&:to_s).to_set | |
@@_defined_activerecord_methods ||= (ActiveRecord::Base.public_instance_methods(false) | ActiveRecord::Base.private_instance_methods(false) | ActiveRecord::Base.protected_instance_methods(false)).map(&:to_s).to_set | |
raise DangerousAttributeError, "#{method_name} is defined by ActiveRecord" if @@_defined_activerecord_methods.include?(method_name) | |
@_defined_class_methods.include?(method_name) | |
end | |