Skip to content

Instantly share code, notes, and snippets.

View krisleech's full-sized avatar

Kris Leech krisleech

View GitHub Profile
@krisleech
krisleech / INFO.md
Created July 6, 2023 16:00
Re-signing an expired certificate for publishing gems
$ gem build wisper.gemspec
Enter PEM pass phrase:
INFO:  Your certificate has expired, trying to re-sign it...
ERROR:  While executing gem ... (Gem::Security::Exception)
    certificate /CN=kris.leech\/DC=gmail\/DC=com not valid after 2020-10-15 18:13:45 UTC   
$ gem cert --re-sign -C gem-public_cert.pem -K ~/.ssh/gem-private_key.pem
@krisleech
krisleech / spec.rb
Created April 24, 2023 16:10
ephemeral ActiveRecord model for specs
let(:model_class) do
Class.new(ApplicationRecord) do
self.table_name = "model_class_#{SecureRandom.uuid.delete('-')}"
def self.up
connection.execute("CREATE TABLE #{table_name}(id INTEGER PRIMARY KEY AUTOINCREMENT)")
end
def self.down
ApplicationRecord.connection.execute("DROP TABLE #{table_name}")
@krisleech
krisleech / RES-async-sketches.md
Last active April 20, 2021 12:05
Rails Event Store same event handler async and sync
class MyEventHandler
  include BackgroundEventHandler
  
  def call(event)  
  end
end

class MyOtherEventHandler
  include ForegroundEventHandler
Add = ->(add, n) { n + add }
Times = ->(times, n) { n * times }
AddOne = Add.curry.call(1)
TimesFour = Times.curry.call(4)
AddOneTimesFour = AddOne >> TimesFour
AddOneTimesFour.(2) # => 12
@krisleech
krisleech / rspec.rb
Last active July 6, 2020 08:51
RSpec gotcha
require "bundler/inline"
gemfile(false) do
source "https://rubygems.org"
gem "rspec"
gem "pry-byebug"
end
require 'rspec/autorun'
@krisleech
krisleech / spec.rb
Last active June 23, 2020 09:01
dry-Struct
require "bundler/inline"
gemfile(false) do
source "https://rubygems.org"
gem "dry-struct", '0.5'
gem "dry-types", '0.14'
gem 'rails_event_store-rspec', '1.0.0'
gem "pry-byebug"
gem 'activesupport'
end
@krisleech
krisleech / stats.md
Last active April 20, 2020 08:23
Run + Blood Glucose
  • 10:30 BG 4.5 mmol/litre
  • Run:
    • 6k
    • 5:11 mins/km pace
    • Elevation gain: 76m
    • Max elevation: 107m
  • 11:10 BG 6.2 mmol.litre
  • Food (carbs)
  • 11:50 BG 5.5 mmol/litre
  • 12:30 BG 6.3 mmol/litre
@krisleech
krisleech / 00_README.md
Created February 18, 2020 16:21
Playing with Rails Event Store
ruby basic.rb

ruby aggregate_root.rb
@krisleech
krisleech / service_authorized.rb
Created February 17, 2020 16:35
services and action policy
require "bundler/inline"
gemfile(false) do
source "https://rubygems.org"
gem "rspec"
gem "action_policy"
gem "pry-byebug"
end
require "action_policy"
@krisleech
krisleech / ActionPolicy_and_SimpleDelegator.md
Created February 17, 2020 16:08
ActionPolicy and SimpleDelegator

Problem: When wrapping a model using SimpleDelegator and passing to authorize! an undefined method _policy_cache_key error occurs.

This is, I think, because ActionPolicy uses refinements to add a method _policy_cache_key to Object.

However SimpleDelegator does not inherit from Object, but maybe BasicObject.

To fix this we need to pass the unwrapped model to authorize! or add the missing method, _policy_cache_key, to our wrapper object.

In controller or mutation: