Skip to content

Instantly share code, notes, and snippets.

View scottwater's full-sized avatar

Scott Watermasysk scottwater

View GitHub Profile
@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 / curl
Last active February 15, 2021 04:07
Quick KickoffLabs API
curl -d 'email=scott@kickofflabs.com&api_key=your_api_key' https://api.kickofflabs.com/v1/1905/subscribe
curl -G -d "email=scott@kickofflabs.com" https://api.kickofflabs.com/v1/1905/info
@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")
@scottwater
scottwater / code.rb
Last active December 2, 2020 15:07
2020 Advent of Code Day 2
unless RUBY_VERSION.start_with?("2.7")
puts "Please use Ruby 2.7.x"
return
end
data = File.open("input.txt").map { |line|
parts = line.split(" ")
p1, p2 = parts[0].split("-").map(&:to_i)
{
p1: p1,
@scottwater
scottwater / day1.rb
Created December 2, 2020 05:06
Day1 Advent Code Ruby
numbers = File.open("input.txt").map(&:to_i)
combinations = ENV.fetch("COMBOS", 2).to_i
puts numbers
.combination(combinations)
.find { |pair| pair.sum == 2020 }
.reduce(:*)