Skip to content

Instantly share code, notes, and snippets.

View bensheldon's full-sized avatar
🏊‍♂️
Swimming through code.

Ben Sheldon [he/him] bensheldon

🏊‍♂️
Swimming through code.
View GitHub Profile
# frozen_string_literal: true
# config/initializers/view_component.rb
#
# Instantiate a ViewComponents that is (optionally) serializable by Active Job
# but otherwise behaves like a normal ViewComponent. This allows it to be passed
# as a renderable into `broadcast_action_later_to`.
#
# To use, include the `ViewComponent::Serializable` concern:
#
# class ApplicationComponent < ViewComponent::Base
class BaseController < ApplicationController
include Flowable
self.form_flow = [
"AppliesController",
# Initial "can we help you" questions
"Apply::LocationsController",
"Apply::RecentlyAppliedsController",
"Apply::LanguagesController",
<% require_relative File.expand_path("git_worktree", __dir__) %>
default: &default
adapter: postgresql
encoding: unicode
pool: 20
connect_timeout: 5
checkout_timeout: 5
development:
# frozen_string_literal: true
# https://www.twilio.com/docs/glossary/what-is-gsm-7-character-encoding
class SmsCounter
MAX_SEGMENTS = 10
GSM7_SINGLE_SEGMENT_LENGTH = 160
GSM7_MULTI_SEGMENT_LENGTH = 153
USC2_SINGLE_SEGMENT_LENGTH = 70
USC2_MULTI_SEGMENT_LENGTH = 67
@bensheldon
bensheldon / i18n-tasks-normalize.rb
Last active July 28, 2025 22:56
Normalize the YAML output of i18n-tasks so that strings are always doublequoted, or strings with newlines use YAML Literations (e.g. `key: |` style)
# frozen_string_literal: true
module I18nTaskYamlExt
UNMASKED_EMOJI = /
(?:
(?:\p{Emoji_Presentation}|\p{Emoji}\uFE0F) # base emoji
(?:\u200D(?:\p{Emoji_Presentation}|\p{Emoji}\uFE0F))* # + ZWJ parts
)
/ux
# Benchmark performance differences between "require" and "Autoload"
#
# $ for run in {1..3}; do ZEITWERK=0 AUTOLOAD=0 ruby scripts/autoload.rb && ZEITWERK=0 AUTOLOAD=1 ruby scripts/autoload.rb; done
# REQUIRE 0.208000 0.360310 0.568310 ( 0.568952)
# AUTOLOAD 0.242265 0.374332 0.616597 ( 0.617540)
# REQUIRE 0.214861 0.360820 0.575681 ( 0.576603)
# AUTOLOAD 0.225601 0.364912 0.590513 ( 0.590673)
# REQUIRE 0.214296 0.359103 0.573399 ( 0.574008)
# AUTOLOAD 0.224972 0.359481 0.584453 ( 0.584926)
# $ for run in {1..3}; do ZEITWERK=1 AUTOLOAD=0 ruby scripts/autoload.rb && ZEITWERK=1 AUTOLOAD=1 ruby scripts/autoload.rb; done
❯ OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES bin/test test/application/loading_test.rb:560
Run options: --seed 3148
# Running:
/Users/bensheldon/Repositories/rails/rails/railties/test/application/loading_test.rb:571: warning: constant Gem::Specification::NOT_FOUND is deprecated
/Users/bensheldon/Repositories/rails/rails/railties/test/application/loading_test.rb:571: warning: constant Gem::RubyGemsVersion is deprecated
/Users/bensheldon/Repositories/rails/rails/railties/test/application/loading_test.rb:571: warning: constant Gem::ConfigMap is deprecated
/Users/bensheldon/Repositories/rails/rails/railties/test/application/loading_test.rb:571: warning: constant Gem::List is deprecated
/Users/bensheldon/Repositories/rails/rails/railties/test/application/loading_test.rb:571: warning: constant Gem::SpecificGemNotFoundException is deprecated
import { Controller } from "@hotwired/stimulus"
import { debounce } from "lib/utils"
export default class extends Controller {
static values = {
resizeDebounceDelay: {
type: Number,
default: 100,
}
}
import {Controller} from "@hotwired/stimulus"
// Warns if form fields have unsaved changes before leaving the page.
// Changes are stored in Session Storage to restore un-warnable events
// like using the back button
//
// To use:
// <form data-controller="unsaved-changes">
// <input type="text" name="name" data-unsaved-changes-target="field">
export default class extends Controller {
# frozen_string_literal: true
# Reduce the amount of quote churn in the YAML files that results from
# i18n-tasks attempting to normalize the quotes itself.
# Always attempt to preserve the pre-existing quote style.
require 'psych'
class I18nTasksWrapper
def self.i18n_files
locales_path = File.expand_path('./locales', File.dirname(__FILE__))