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
@pat
pat / LICENSE.txt
Last active February 4, 2023 21:02
Running Setup SQL scripts on an RDS instance within a VPC, via Terraform
The MIT License (MIT)
Copyright (c) 2018 Pat Allan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
module ThinkingSphinx
class Search
# rough implementation of what the code actually does.
CoreMethods = %w( == class class_eval extend frozen? id instance_eval
instance_of? instance_values instance_variable_defined?
instance_variable_get instance_variable_set instance_variables is_a?
kind_of? member? method methods nil? object_id respond_to? send should
type )
instance_methods.select { |method|
# 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 / thinking_sphinx.yml
Last active April 23, 2022 03:49
Thinking Sphinx Configuration
# Extended configuration for Thinking Sphinx can be stored in the
# config/thinking_sphinx.yml file within your application (this file was
# previously known as config/sphinx.yml in TS v1/v2).
#
# Many settings from Sphinx itself can be set here, and they'll flow through to
# the appropriate section of the generated configuration. However, some are
# used for Thinking Sphinx behaviour, and so those are documented here first.
#
# Configuration is grouped by environment, just like config/database.yml in a
# standard Rails application.
@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 / 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