Skip to content

Instantly share code, notes, and snippets.

View mortenson's full-sized avatar
💧
Did you try to clear cache?

Samuel Mortenson mortenson

💧
Did you try to clear cache?
View GitHub Profile
@mortenson
mortenson / test-migrations.sh
Last active January 4, 2024 00:21
Example script that tests if migrations added in current working tree will break tests when applied to master. Good for PRs but can be used locally "safely"
#! /bin/bash
# Assumes migrations are stored in ./db/migrations as single files.
# Also assumes migrations are in (alphanumeric) order.
set -e
rm -rf /tmp/test-migrations
mkdir /tmp/test-migrations
cp -r db/migrations/* /tmp/test-migrations/
@mortenson
mortenson / wait-for-render.sh
Created January 2, 2024 00:33
Bash script to wait for the given Render services to finish deploying. Useful for triggering deploy hooks sequentially, or tracking deploy status in GitHub actions.
#! /bin/bash
# RENDER_SERVICE_NAMES should be a newline-separated list of service IDs (ex: srv-...)
# RENDER_API_TOKEN is your personal Render API token
max_attempts=200
while IFS= read -r RENDER_SERVICE_NAME; do
echo "Checking $RENDER_SERVICE_NAME ..."
attempt_counter=0
@mortenson
mortenson / block.js
Last active December 18, 2023 19:15
Very simple and stupid chrome extension to block arbitrary sites
document.body.innerHTML = 'get back to work'
@mortenson
mortenson / composelist.sh
Last active November 5, 2023 13:38
List all Docker Compose projects currently running
#!/bin/bash
docker ps --filter "label=com.docker.compose.project" -q | xargs docker inspect --format='{{index .Config.Labels "com.docker.compose.project"}}'| sort | uniq
@mortenson
mortenson / sams_portland_stuff.md
Last active August 30, 2023 23:54
Sam's fun things to do in Portland

Portland recommendations by Sam

Sorted by location-ish. I tried to reduce the list to places I think are good for visitors vs. my absolute favorites, but I put a section at the bottom for places that may not be for everyone.

Breakfast / Brunch

Toki Restaurant (Downtown)

580 SW 12th Ave

My order: Grilled mackerel breakfast with a bloody mary. Their Dalgona coffee is quite good too.

@mortenson
mortenson / notes.md
Last active August 26, 2023 03:35
Dell XPS 13 9300 Ubuntu setup notes

Random notes from woring with a new XPS 13 9300 with Ubuntu

Notes from when I was on the default Dell OEM Ubuntu

Disable trackpad middle click:

sudo vim /usr/share/X11/xorg.conf.d/40-libinput.conf

Add Option "ButtonMapping" "1 1 3 4 5" under

@mortenson
mortenson / composer.json
Last active August 20, 2023 10:39
Example composer.json file for File Browser
{
"name": "mortenson/example",
"minimum-stability": "dev",
"authors": [
{
"name": "Samuel Mortenson",
"email": "samuel.mortenson@acquia.com"
}
],
"repositories": [
@mortenson
mortenson / create_migration.go
Last active June 19, 2023 13:31
Create sqlc migrations automatically using pg-schema-diff
package main
import (
"context"
"database/sql"
"flag"
"fmt"
"os"
"path/filepath"
"strings"
@mortenson
mortenson / metatag_example.php
Created February 26, 2019 23:29
OR statements in metatags...
<?php
/**
* Implements hook_metatags_attachments_alter().
*
* This function allows you to define fallback tokens in case a field is empty.
*
* If all fallback values are empty, the tag will be empty.
*
* Example: [node:field_image:medium]||[node:field_legacy_image:medium]||/fallback.png
@mortenson
mortenson / autosave.js
Created January 14, 2023 18:45
Minimal form autosave functionality using vanilla JS
document.querySelectorAll("form").forEach((formEl) => {
const key = location.pathname + formEl.id;
const json = localStorage.getItem(key);
if (json) {
const data = JSON.parse(json);
Object.keys(data).forEach((inputId) => {
formEl.elements[inputId].value = data[inputId];
});
} else {
localStorage.setItem(