Skip to content

Instantly share code, notes, and snippets.

@floehopper
floehopper / Rollbar.svelte
Last active Jan 6, 2023
Rollbar configuration in a SvelteKit app - both client-side & server-side
View Rollbar.svelte
<script>
/* eslint-disable */
import { mode } from "$app/env";
import { onMount } from "svelte";
const rollbarAccessToken = import.meta.env
.VITE_ROLLBAR_POST_CLIENT_ITEM_ACCESS_TOKEN;
const codeVersion = import.meta.env.VITE_LATEST_SHA;
View run-migration-from-rails-console.rb
migration_context = ActiveRecord::Base.connection.migration_context
migration_context.migrate(target_version = nil)
migration_context.rollback(steps = 1)
migration_context.forward(steps = 1)
migration_context.up(target_version = nil)
migration_context.down(target_version = nil)
migration_context.current_version
@floehopper
floehopper / validate-parameters-against-method-signature.rb
Created Aug 14, 2022
Validate parameters against method signature
View validate-parameters-against-method-signature.rb
def valid?(method, ...)
signature = method.inspect
pattern = %r{(?:\.|#)#{method.name}\(([^\)]*)\)}
params = signature.match(pattern)[1]
params_with_nil_default_values = params.gsub('...', 'nil')
klass = Class.new
klass.class_eval "def self.#{method.name}(#{params_with_nil_default_values})\nend\n"
klass.public_send(method.name, ...)
true
rescue ArgumentError => e
@floehopper
floehopper / display_changed_row_counts.rb
Created Feb 1, 2022
Display changed row counts using ActiveRecord
View display_changed_row_counts.rb
def row_counts
Hash[*ApplicationRecord.connection.execute(%{
ANALYZE;
SELECT
pgClass.relname AS tableName,
pgClass.reltuples AS rowCount
FROM
pg_class pgClass
INNER JOIN
pg_namespace pgNamespace ON (pgNamespace.oid = pgClass.relnamespace)
@floehopper
floehopper / flatten
Created Dec 27, 2021
Flatten files in sub-directories into single directory
View flatten
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
pwd = Pathname.pwd
begin
source = Pathname.new(ARGV[0].nil? ? pwd : ARGV[0]).realpath
destination = Pathname.new(ARGV[1].nil? ? pwd: ARGV[1]).realpath
@floehopper
floehopper / zx81-print-hi.bas
Created Nov 22, 2020
ZX81 machine code program to print "HI"
View zx81-print-hi.bas
10 REM 000000000000
20 POKE 16514, 1
30 POKE 16515, 141
40 POKE 16516, 64
50 POKE 16517, 17
60 POKE 16518, 2
70 POKE 16519, 0
80 POKE 16520, 205
90 POKE 16521, 107
100 POKE 16522, 11
@floehopper
floehopper / ec2-iam-security-credentials.md
Last active Nov 7, 2020
Obtaining security credentials derived from IAM role on EC2 machine
View ec2-iam-security-credentials.md
@floehopper
floehopper / install.md
Last active Aug 31, 2020
Installing OSX Catalina from scratch
View install.md

List & install software updates

softwareupdate --list
sudo softwareupdate --verbose --install --all

Set computer name

COMPUTER_NAME="<computer-name>"
sudo scutil --set ComputerName $COMPUTER_NAME
@floehopper
floehopper / Vagrantfile
Last active Oct 22, 2021
Ubuntu Xenial with Ruby installed via rbenv
View Vagrantfile
PROVISION_SYSTEM = <<~EOS
set -e
apt-get update --yes
apt-get install --yes gcc
apt-get install --yes make
EOS
PROVISION_USER = <<~EOS
set -e
mkdir -p ~/.rbenv