Skip to content

Instantly share code, notes, and snippets.

View scottwater's full-sized avatar

Scott Watermasysk scottwater

View GitHub Profile
@scottwater
scottwater / turbo.rb
Created November 4, 2024 20:08
Render Components from TurboStreams
module TurboStreamsBroadcastExtensions
def broadcast_action_later_to(*streamables, action:, target: nil, targets: nil, attributes: {}, **rendering)
render_component_to_html(rendering)
super
end
def broadcast_action_to(*streamables, action:, target: nil, targets: nil, attributes: {}, **rendering)
render_component_to_html(rendering)
super
end
@scottwater
scottwater / demo_stepped_job.rb
Created September 30, 2024 10:28
Using JobInterator to build a multi-step Job with ActiveJob
class DemoSteppedJob < SteppedJob
# without a retry_on, the job will not be retried where it failed
retry_on StandardError, attempts: 4
def steps = %i[step_one step_two step_three]
private
def step_one(arg1, arg2)
Rails.logger.info("Step one with args #{arg1} and #{arg2}")
end
@scottwater
scottwater / search_deleted_files.sh
Created July 20, 2024 19:31
Search Git for a string of text in recently deleted files (number of files is the second paramemter, defaults to 20)
#!/bin/bash
string_to_search=$1
num_commits=${2:-20}
if [ -z "$string_to_search" ]; then
echo "Usage: $0 <string_to_search> [<num_commits>]"
exit 1
fi
@scottwater
scottwater / backup.sh
Created February 22, 2024 18:40
SQLite Backup Script
#!/bin/bash
set -e
s3_key=$BACKUP_S3_KEY
s3_secret=$BACKUP_S3_SECRET
bucket=$BACKUP_S3_BUCKET
backup_db_passphrase=$BACKUP_S3_DB_PASSPHRASE
data_directory=$SQLITE_DATABASE_DIRECTORY
# ensure each backup has the same date key
date_key=$(date '+%Y-%m-%d-%H-%M-%S')
@scottwater
scottwater / utm_cookie.js
Created October 11, 2023 15:55
Save UTM's to a Cookie
@scottwater
scottwater / html.serb
Last active May 3, 2023 15:39
Serb component example
{%@ Shared::Card::Card as: :article do %}
{%@ Shared::Card::Title as: :h2, href: article.relative_url do %}
{{article.data.title}}
{% end %}
{%@ Shared::Card::Eyebrow as: :time, dateTime: article.data.date, decorate: true do %}
{{article.data.date}}
{% end %}
{%@ Shared::Card::Description do %}
{{article.data.description}}
{% end %}
@scottwater
scottwater / clsx.rb
Created March 14, 2023 00:58
Quick Ruby implementation of https://www.npmjs.com/package/clsx
module Clsx
def clsx(*args)
process_args = args.map do |arg|
if arg.is_a?(Array)
clsx(*arg)
elsif arg.is_a?(Hash)
arg.map do |key, value|
key if value
end
else
@scottwater
scottwater / page.htm
Created March 16, 2021 00:10
Setting the email address based on a query string
<script>
document.addEventListener("DOMContentLoaded", () => {
const url = new URL(window.location)
const email = url.searchParams.get("email_address")
if (email) {
document.querySelectorAll("input[type='email']").forEach((el) => el.value = email);
}
});
</script>
@scottwater
scottwater / kol_form_email.js
Created February 25, 2021 18:49
For those who cannot use standard input types. We recommend using type=email and type=tel
window.kolOptions = {
form: {
mappings: {
email: {
selector: "input[name='you_custom_selector']"
}
}
}
};
@scottwater
scottwater / fly_graphql.rb
Created February 9, 2021 16:06
FlyGraphql For Domains
class FlyGraphql
include HTTParty
debug_output $stderr if Rails.env.development?
base_uri "api.fly.io:443/graphql"
headers "Authorization" => "Bearer #{ENV["FLY_API_KEY"]}"
format :json
attr_reader :app_id
class FlyGraphqlError < StandardError
def initialize(message = "Error in FlyGraphql")