Skip to content

Instantly share code, notes, and snippets.

View pat's full-sized avatar
🇵🇸
free Palestine 🇵🇸

Pat Allan pat

🇵🇸
free Palestine 🇵🇸
View GitHub Profile
@pat
pat / README.md
Last active November 28, 2023 22:50
Dry-driven settings

To ensure it's available for all initialisers, you can require the file within config/application.rb by adding require_relative "settings" as the last line within the Application class definition.

The defined settings will be available via the Settings constant: e.g. Settings.default_host

  • Does not pay attention to Rails.configuration / Rails.application.credentials - it's expecting all secrets as ENV variables.
  • Requires dry-types and dry-system gems.
  • Allows for typed values (even if the above examples are all strings 😅).
  • Allows for optional values and defaults.
  • Inspired by Hanami's approach to such things.
@pat
pat / reading_recommendations.md
Created April 24, 2023 19:53
RailsConf 2023: Upgrading the Ruby Community
# frozen_string_literal: true
VCR.configure do |config|
config.cassette_library_dir = Rails.root.join("spec/cassettes")
config.hook_into :webmock
config.ignore_hosts "127.0.0.1", "analytics-api.buildkite.com"
end
# Re-use directory structure within spec/features, to keep cassettes namespaced.
VCRAssistant.namer = Class.new(VCRAssistant::FileName) do
@pat
pat / webmock_json_helpers.rb
Created December 14, 2021 06:52
Helpers for stubbing JSON requests with Webmock
# frozen_string_literal: true
require "delegate"
require "webmock/rspec"
module WebmockJSONHelpers
def stub_request(method, uri)
RequestStub.new(super)
end
@pat
pat / settings.rb
Created December 14, 2021 06:52
Using dry-system for typed and verified Rails configuration settings
# frozen_string_literal: true
require "dry/system/errors"
require "dry/system/settings"
require "dry/types"
module Types
include Dry.Types()
end
@pat
pat / README.md
Last active December 17, 2021 09:45
Using MySQL 5.7 libraries on Heroku

Edit 2021-02-21: I've confirmed this solution works with both heroku-18 and heroku-20 stacks.


What follows is my solution for having mysql2 gem compiled and working against MySQL v5.7 (rather than v8+) on the heroku-20 stack. This is how I've managed to make it work:

  • Add the apt buildstack ahead of your standard buildpack (in my case, that's Ruby):
$ heroku buildpacks:add --index 1 heroku-community/apt
@pat
pat / letter.markdown
Created October 21, 2019 03:15
Letter to Senator Lambie about Medevac Repeal Bill

Dear Senator Lambie,

I am writing in regards to the Medevac Repeal Bill, and to strongly urge you to not allow the repeal to happen.

It is our Government that has imprisoned these people in these remote and unsafe situations, and thus it is our Government that should be providing medical support, especially given the imprisonment is a significant cause in the mental health issues so many of these detainees.

While I’m sure you’re aware of this already, it’s worth noting that the legislation that was passed earlier this year is only for the current set of detainees - it does not apply to any new arrivals, and I feel our Government has been rather obtuse in any suggestions otherwise. Any suggestion that the lack of a repeal makes our country any less safe is a cruel lie.

There have been clear cases of deaths in custody that could have been prevented had proper medical assistance been provided promptly and genuinely, rather than turning these detainees into political pawns. If the repeal goes ahead, it’s quit

require "openssl"
require "digest/sha2"
require "base64"
require "ostruct"
# Just like Aws::KMS::Client, this responds to decrypt and encrypt,
# using the same parameters and output objects (well, at least for
# the purposes of what I've used it for).
#
# So, you can inject this class in instead for test environments
function ruby_files() {
xargs ls -1 2>/dev/null | grep '\.rb$'
}
function spec_files() {
xargs ls -1 2>/dev/null | grep '_spec\.rb$'
}
function uncommitted() {
# first command is staged changes, second is new files and unstaged changes