Skip to content

Instantly share code, notes, and snippets.

@rolentle
rolentle / any_vs_length.rb
Created May 3, 2018 14:01
any vs length > 0
require 'benchmark'
a = []
iterations = 1_000_000
puts "for empty array"
Benchmark.bm do |x|
x.report("length") { iterations.times do; a.length > 0; end }
x.report("any") { iterations.times do; a.any?; end }
end
@rolentle
rolentle / Foo.rb
Created March 18, 2018 20:04
Puts example
class Foo
def hello
puts "hello"
end
end
Foo.new.hello
# What will return?
name: Cardiothoracic Surgery score: 0.00022565003
Explanation
description: sum of:, value: 0.00045130006, details:
description: max of:, value: 9.0260015e-05, details:
description: ConstantScore(name:cardio*), product of:, value: 9.0260015e-05, details:
description: boost, value: 1.0
description: queryNorm, value: 9.0260015e-05
description: ConstantScore(common_terms:cardio*), product of:, value: 9.0260015e-05, details:
description: boost, value: 1.0
description: queryNorm, value: 9.0260015e-05
@rolentle
rolentle / gist:c7da72d7e4bbd9194445
Created May 2, 2014 14:09
Agile Metric Test Errors.
/Users/A664724/.rvm/gems/ruby-2.0.0-p451@global/gems/bundler-1.6.1/lib/bundler/runtime.rb:222: warning: Insecure world writable dir /usr/local in PATH, mode 040777
DEPRECATION WARNING: Model based mass assignment security has been extracted
out of Rails into a gem. Please use the new recommended protection model for
params or add `protected_attributes` to your Gemfile to use the old one.
To disable this message remove the `whitelist_attributes` option from your
`config/application.rb` file and any `mass_assignment_sanitizer` options
from your `config/environments/*.rb` files.
See http://guides.rubyonrails.org/security.html#mass-assignment for more information.
class User < ActiveRecord::Base
has_many :trips
has_many :feed_sources
has_many :photos
has_many :statuses
has_many :checkins
validates :name, :presence => true
def possessive_name