Skip to content

Instantly share code, notes, and snippets.

View johnnyshields's full-sized avatar
💭
Spreading joy and love across the universe

Johnny Shields johnnyshields

💭
Spreading joy and love across the universe
View GitHub Profile
@johnnyshields
johnnyshields / gist:4ad359d099576cc2e6fc6914da3e159c
Created July 20, 2022 04:27
Ruby Array vs. Hash creation benchmark
require 'benchmark'
a = 1
b = 2
c = 3
Benchmark.bm do |bm|
bm.report do
10_000_000.times do |a|
[a, b, c]
@johnnyshields
johnnyshields / mongoid-relations-proposal.md
Last active April 12, 2017 06:39
mongoid-relations-proposal.md

Proposal for Better Mongoid Relation Schema

There is opportunity to simplify Mongoid's relation definitions, increase intuitiveness, and at the same time make them more powerful.

One particular issue I'm facing is over-usage of has_and_belongs_to_many ... inverse_of: nil. The problem with this is that the inverse side of the relationship doesn't trigger any callbacks, which leads to out-of-sync data. It would be more natural to express this as belongs_to_many and has_many as per below.

Definitions

Given two models, each can have the one of the following verbs to define a relation, so long as at least one side is belongs:

def current_path_for_locale(loc = I18n.locale, is_link = true)
return 'javascript: void(0);' if is_link && I18n.locale == loc
url_regex = /\A\/(?:(#{I18n.available_locales.join('|')})\/)?/
current_page.url.gsub(url_regex, '').blank? ?
home_for_locale(loc) :
current_page.url.gsub(url_regex, root_for_locale(loc))
end
Stack trace
javax.servlet.ServletException: com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:796)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
at org.kohsuke.stapler.MetaClass$5.doDispatch(MetaClass.java:233)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649)

Keybase proof

I hereby claim:

  • I am johnnyshields on github.
  • I am johnnyshields (https://keybase.io/johnnyshields) on keybase.
  • I have a public key whose fingerprint is D34E ABFC C9A0 B183 E266 0112 DCB7 FDD4 0E86 6A5B

To claim this, I am signing this object:

@johnnyshields
johnnyshields / moped1x_instrumenter.rb
Created February 23, 2016 19:29
Monkey patch to instrument Moped 1.x same as 2.x.
# Monkey patch to instrument Moped 1.x same as 2.x.
# Can be removed after upgrading to Mongoid 4.
module Moped
module Instrumentable
class Noop
class << self
# Do not instrument anything.
@johnnyshields
johnnyshields / gist:4c8e71a846249fbfc5bd
Created November 12, 2014 11:45
Prawn Table - 2013-11-12 Issue 1
#!/bin/env ruby
# encoding: utf-8
############################################
# NOTE: THIS CLASS EXTENDS PRAWN::DOCUMENT #
############################################
class ErrorDoc < ::Prawn::Document
def initialize