Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View rickychilcott's full-sized avatar

Ricky Chilcott rickychilcott

View GitHub Profile
@rickychilcott
rickychilcott / pm.rb
Last active March 27, 2024 12:33
Ruby Pattern Matching Shenanigans
def example(label)
puts "## #{label}"
yield
puts
puts
end
example("Foo.===(v)") do
class Foo
def self.===(v)
require "active_support/all"
Resource = Struct.new(:absolute_path)
paths = [
Resource.new("/bread/crumbs/three"),
Resource.new("/bread"),
Resource.new("/bread/crumbs"),
Resource.new("/bread/crumbs/one"),
Resource.new("/bread/crumbs/two"),
@rickychilcott
rickychilcott / avo-test-helpers.rb
Created December 8, 2022 17:39
Some Example Avo Test Helpers
def avo_flatpickr_pick(selector, with:)
base_field = find(selector, visible: false)
flatpickr_field_identifier = base_field["data-resource-edit-target"]
flatpickr_field = find("[data-resource-edit-target='#{flatpickr_field_identifier}'].flatpickr-input", visible: false)
new_selector_id = flatpickr_field["id"]
flatpickr_pick("##{new_selector_id}", with: with)
end
def avo_tagify_select(field_selector, with:, retries: 3)
raise("Unable to select '#{with}' from '#{field_selector}'") if retries == 0
# frozen_string_literal: true
class SalesListOrganizationCsvDownload < Avo::BaseAction
self.name = "CSV Download"
self.may_download_file = true
self.confirm_button_label = "Download"
def handle(**args)
_models, _fields, _current_user, resource = args.values_at(:models, :fields, :current_user, :resource)
@rickychilcott
rickychilcott / goal_and_strategies.rb
Created July 13, 2022 13:28
Fun with Goals and Strategies
class Base
def initialize(id)
@id = id
end
def name
"#{self.class.name} #{@id}"
end
end
@rickychilcott
rickychilcott / render.com.log
Created March 11, 2022 03:00
Bridgetown render.com log
Mar 10 09:56:57 PM ==> Cloning from https://github.com/mission-met/bridgetown-test...
Mar 10 09:56:57 PM ==> Checking out commit 8942612de1fb5c174fbbf51067e51ca6172d6f5d in branch main
Mar 10 09:56:59 PM ==> Downloading cache...
Mar 10 09:57:10 PM ==> Downloaded 177MB in 5s. Extraction took 4s.
Mar 10 09:57:15 PM ==> Installing dependencies with Yarn...
Mar 10 09:57:15 PM yarn install v1.22.17
Mar 10 09:57:15 PM [1/4] Resolving packages...
Mar 10 09:57:15 PM success Already up-to-date.
Mar 10 09:57:15 PM Done in 0.16s.
Mar 10 09:57:15 PM ==> Installing dependencies with bundler...
@rickychilcott
rickychilcott / trace.log
Created February 23, 2022 00:14
Thredded DB Pool Exhaustion Stacktrace
Feb 21 18:20:41 app-name app/web.1 #<Thread:0x00007fe73838ea10 /app/vendor/bundle/ruby/3.0.0/bundler/gems/thredded-9a7158d4a307/lib/thredded/collection_to_strings_with_cache_renderer.rb:84 run> terminated with exception (report_on_exception is true):
Feb 21 18:20:41 app-name app/web.1 /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:210:in `block in wait_poll': could not obtain a connection from the pool within 5.000 seconds (waited 5.000 seconds); all pooled connections were in use (ActionView::Template::Error)
Feb 21 18:20:41 app-name app/web.1 from /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:199:in `loop'
Feb 21 18:20:41 app-name app/web.1 from /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:199:in `wait_poll'
Feb 21 18:20:41 app-name app/web.1 from /app/vendor/bundle/ruby/3.0.0/gem
@rickychilcott
rickychilcott / newsletter-signup-trigger.html
Created August 25, 2021 00:03
Trigger a newsletter signup popup every 30 days
<link rel="stylesheet" href="https://s.electerious.com/basicLightbox/dist/basicLightbox.min.css" />
<script src="https://s.electerious.com/basicLightbox/dist/basicLightbox.min.js"></script>
<script type="text/javascript">
const storage = window.localStorage
const NEWSLETTER_KEY = "newsletter-signup-trigger"
const DAYS_IN_MS = 86_400_000
const RESHOW_DAYS = 30 * DAYS_IN_MS
const DELAY_POP_SECONDS = 20 * 1_000
@rickychilcott
rickychilcott / slim_select_controller.js
Last active December 28, 2021 05:10
Slim-select stimulus controller
import { Controller } from "stimulus"
import SlimSelect from "slim-select"
import "slim-select/dist/slimselect.min.css"
import "../style/slimselect-customized.css"
export default class extends Controller {
connect() {
const limit = this.data.get("limit")
const placeholder = this.data.get("placeholder")
const searchText = this.data.get("no-results")
@rickychilcott
rickychilcott / slim_select_helper.rb
Last active February 22, 2024 13:23
slim-select capybara helpers
## from @dinshaw in https://github.com/brianvoe/slim-select/pull/246
## Assumption is that you have a label who's parent also contains the select list you are choosing from.
def js_select(item_text, options)
container = find(:xpath, "//parent::*[label[text()='#{options[:from]}']]")
within "##{container[:id]}", visible: false do
find('.ss-arrow').click
input = find(".ss-search input").native
input.send_keys(item_text)
find('div.ss-list').click