Skip to content

Instantly share code, notes, and snippets.

View jeremy's full-sized avatar

Jeremy Daer jeremy

View GitHub Profile
@jeremy
jeremy / ruby-2.5.txt
Last active November 25, 2019 17:16
bcrypt-ruby bc_salt segfault
-- C level backtrace information -------------------------------------------
/opt/ruby2.5.1/bin/../lib/libruby.so.2.5(rb_vm_bugreport+0x974) [0x7f6e7aad0904]
/opt/ruby2.5.1/bin/../lib/libruby.so.2.5(0xaaec4) [0x7f6e7a941ec4]
/opt/ruby2.5.1/bin/../lib/libruby.so.2.5(0x1a89c2) [0x7f6e7aa3f9c2]
/lib/x86_64-linux-gnu/libc.so.6(0x7f6e7a4e4f20) [0x7f6e7a4e4f20]
/lib/x86_64-linux-gnu/libc.so.6(__strlen_avx2+0x11) [0x7f6e7a6345a1] ../sysdeps/x86_64/multiarch/strlen-avx2.S:59
/opt/ruby2.5.1/bin/../lib/libruby.so.2.5(rb_str_new_cstr+0xe) [0x7f6e7aa5712e]
/u/apps/bc3/shared/bundle-ruby221/ruby/2.5.0/gems/bcrypt-3.1.13/lib/bcrypt_ext.so(bc_salt+0x6a) [0x7f6e6ad2b04a]
@jeremy
jeremy / reraised_backtrace.rb
Created August 20, 2016 02:14
Reraising an exception never amends its backtrace
def foo
e = RuntimeError.new
def e.backtrace() %w[ lol rofl ] end
raise e
rescue => e
raise e
end
foo

Keybase proof

I hereby claim:

  • I am jeremy on github.
  • I am bitsweat (https://keybase.io/bitsweat) on keybase.
  • I have a public key ASAHmrs7GVnFuLVA6XK5t2znEMLHrRiixbMEQsbT2wB0dwo

To claim this, I am signing this object:

require 'active_support/concern'
module Touchless
module TouchLater
extend ActiveSupport::Concern
included do
# Preserve immediate touch behavior as touch_now
alias_method :touch, :touch_now
alias_method :touch_later, :touch
# CI runs tests in order so it gets nice diffable output.
if ENV['CI']
# Minitest always forces test suites to shuffle. Hack it.
class Minitest::Runnable
class NonShufflingArray < Array
def shuffle
self
end
end
require 'active_record'
ActiveRecord::Base.logger = Logger.new($stdout)
ActiveRecord::Base.establish_connection adapter: 'mysql2', database: 'activerecord_unittest'
ActiveRecord::Base.connection.instance_eval do
create_table(:taggings, :force => true) do |t|
t.belongs_to :taggable, polymorphic: true
t.belongs_to :tag
end
@jeremy
jeremy / gist:4211803
Created December 5, 2012 03:05
Template- and asset-aware ETags

Declared ETags, together with Russian Doll caching, can be used to automatically mix your template and asset versions into the ETags set in your controllers. This avoids the need to blow all browser caches on each deploy and neatly contains the scope of "freshness fallout" when you tweak a view.

To include the template's version in the ETag:

  # Incorporate the cache version for this action into our ETag.
  # This allows template changes to bubble up into HTTP cache
  # freshness and bust browser caches when we make changes.
  etag do
    begin
@jeremy
jeremy / gist:4206626
Created December 4, 2012 17:34
irb rake
diff --git a/railties/lib/rails/console/helpers.rb b/railties/lib/rails/console/helpers.rb
index 230d3d9..1bbdfd2 100644
--- a/railties/lib/rails/console/helpers.rb
+++ b/railties/lib/rails/console/helpers.rb
@@ -7,5 +7,16 @@ module Rails
def controller
@controller ||= ApplicationController.new
end
+
+ def rake(task)
@jeremy
jeremy / gist:4035286
Created November 7, 2012 23:15
Enumerable#associate

We've seen lots of Ruby feature requests about converting an Enumerable to a Hash: to_h, map_hash, map_to, each_with_hash, etc. Let's look at one common, simple case of this.

Building a key/value mapping from a collection of keys is awkward. We commonly see Hash[*collection.map { |element| [element, calculate(element)] }] or collection.each_with_object({}) { |element, hash| hash[element] = calculate(element) }. Both are verbose. They require boilerplate code that's not relevant to the programmer's intent: to associate an enumerable of keys with calculated values.

Ruby has the idea of an association already: a key and value paired together. It's used by Array#assoc to look up a value from a list of pairs and by Hash#assoc to return a key/value pair. Building up a mapping of key/value pairs is associating keys with values.

So! Consider Enumerable#associate which builds a mapping by associating keys with values:

# Associate filenames with URLs. Before:
@jeremy
jeremy / gist:3724459
Created September 14, 2012 20:17
queue consumer exception handler and refactoring
commit 63a12f72df1a7507f7a1923bdaa56b56b876b562
Author: Jeremy Kemper <jeremy@bitsweat.net>
Date: Fri Sep 14 17:00:46 2012 -0700
Pass an exception_handler to queue consumers. Don't run jobs in synchronous & test queues; delegate to a consumer.
diff --git a/activesupport/lib/active_support/queueing.rb b/activesupport/lib/active_support/queueing.rb
index f397e1c..c4ff8b8 100644
--- a/activesupport/lib/active_support/queueing.rb
+++ b/activesupport/lib/active_support/queueing.rb