Skip to content

Instantly share code, notes, and snippets.


Yves Senn senny

  • - (@yves_senn)
  • Bern, Switzerland
View GitHub Profile
View totp.rb
class TOTP
attr_reader :secret, :digits, :digest, :interval
def initialize(s, options = {})
@interval = options[:interval] || DEFAULT_INTERVAL
@digits = options[:digits] || DEFAULT_DIGITS
@digest = options[:digest] || "sha1"
View lists.html
<p>bullet deeply nested</p>
<li>lorem ipsum</li>
consectetur adipiscing elit
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
<li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo <u>consequat</u>. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li>
senny /
Last active Aug 29, 2015
`Array#flatten` ignores `respond_to_missing?` when calling `to_ary`

This issue was reported on

The issue appears when using Array#flatten on an instance of Array containing instances of a Class that implements method_missing. Ruby still calls #to_ary even when said class implements respond_to_missing? and returns false for to_ary. Everything works when the class also overwrites respond_to?.


  1. Is it expected that respond_to_missing? has no effect in the scenario above?
  2. Should a possible workaround rather define a respond_to? method or overwrite to_ary and return nil?
View patch.diff
diff --git a/activerecord/lib/active_record/explain.rb b/activerecord/lib/active_record/explain.rb
index 727a9be..1d9dde0 100644
--- a/activerecord/lib/active_record/explain.rb
+++ b/activerecord/lib/active_record/explain.rb
@@ -16,14 +16,14 @@ module ActiveRecord
# Makes the adapter execute EXPLAIN for the tuples of queries and bindings.
# Returns a formatted string ready to be logged.
def exec_explain(queries) # :nodoc:
- str = do |sql, bind|
+ str = do |sql, bind, connection_id|
senny / env
Last active Aug 29, 2015
Ruby 2.2.1 bug
View env
$ ruby --version
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]
View 1_solution.diff
diff --git a/test/fixtures/high_scores.yml b/test/fixtures/high_scores.yml
index 0c3721e..9d3b342 100644
--- a/test/fixtures/high_scores.yml
+++ b/test/fixtures/high_scores.yml
@@ -1,5 +1,7 @@
# Read about fixtures at
+<% require Rails.root + "test/support/fixture_helper" %>
View errors.log
E, [2015-02-12T03:25:25.223244 #32185] ERROR -- : Actor crashed!
Errno::EHOSTDOWN: Host is down @ dir_initialize - <THE/DIRECTORY/LISTEN/WATCHES>
/usr/local/rbenv/versions/2.1.5/lib/ruby/2.1.0/pathname.rb:425:in `open'
/usr/local/rbenv/versions/2.1.5/lib/ruby/2.1.0/pathname.rb:425:in `foreach'
/usr/local/rbenv/versions/2.1.5/lib/ruby/2.1.0/pathname.rb:425:in `children'
/path/to/app/vendor/bundle/ruby/2.1.0/gems/listen-2.8.3/lib/listen/directory.rb:14:in `scan'
/path/to/app/vendor/bundle/ruby/2.1.0/gems/listen-2.8.3/lib/listen/change.rb:38:in `change'
/path/to/app/vendor/bundle/ruby/2.1.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `public_send'
/path/to/app/vendor/bundle/ruby/2.1.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `dispatch'
/path/to/app/vendor/bundle/ruby/2.1.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:63:in `dispatch'
View plugin_Rakefile.rb
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
require 'rdoc/task' do |rdoc|
rdoc.rdoc_dir = 'rdoc'
View patch.diff
diff --git a/guides/source/ b/guides/source/
index 32140be..f2e0f82 100644
--- a/guides/source/
+++ b/guides/source/
@@ -223,7 +223,16 @@ Every test must contain at least one assertion, with no restriction as to how ma
### Maintaining the test database schema
-In order to run your tests, your test database will need to have the current structure. The test helper checks whether your test database has any pending migrations. If so, it will try to load your `db/schema.rb` or `db/structure.sql` into the test database. If migrations are still pending, an error will be raised.
+In order to run your tests, your test database will need to have the current
View 1test.rb
require 'bundler'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger =