Skip to content

Instantly share code, notes, and snippets.

@matthewadams
matthewadams / supabase-sql.ts
Created July 9, 2025 12:42
Typescript cli file to execute sql against supabase returning results as json
#!/usr/bin/env tsx
// Usage: $0 your-sql-statement
// Prerequisites: npx, npm package `pg`, SUPABASE_DB_URL env var
import { Client } from 'pg'
const SUPABASE_DB_URL: string = process.env.SUPABASE_DB_URL || ''
@matthewadams
matthewadams / new-supabase-cloud-project.sh
Last active July 12, 2025 16:08
Node.js npx cli to create new Supabase cloud project & update local .env file
# Creates a brand new supabase project and updates the .env to point to it.
#
# Prerequisites:
#
# * Required: npx
#
# * Required: A .env.min file with the following content:
# SUPABASE_ORG_ID=yourorgid
# SUPABASE_REGION=us-east-1 # or whatever
# SUPABASE_DB_PASSWORD=thenewdbpassword
@matthewadams
matthewadams / reset.sql
Created June 8, 2025 12:01
Raw SQL to effectively reset a Supabase project to the same state as when it was first created using SQL Editor; script created 2025-06-08, will need updates as supabase adds features
CREATE OR REPLACE FUNCTION reset_supabase_project()
RETURNS void
LANGUAGE plpgsql
AS '
DECLARE
r RECORD;
BEGIN
-- Drop all user-created tables in public schema
FOR r IN (
SELECT tablename FROM pg_tables
@matthewadams
matthewadams / ghfetch.sh
Created June 8, 2025 11:46
Fetch via curl a subdirectory recursively from a github repo
#!/bin/bash
# GitHub subdirectory recursive fetcher
# Usage: ./fetch_github_subdir.sh <owner> <repo> <subdirectory> [branch]
set -e
if [ $# -lt 3 ]; then
echo "Usage: $0 <owner> <repo> <subdirectory> [branch]"
echo "Example: $0 facebook react packages/react main"
@matthewadams
matthewadams / ddclient.conf
Created January 24, 2025 15:47
Namecheap dynamic dns ddclient.conf for multiple domains & subdomains
# Sample namecheap /etc/ddclient.conf
# These are defaults applicable to the remainder of the file
daemon=300
ssl=yes
use=web
web=dynamicdns.park-your-domain.com/getip
protocol=namecheap
server=dynamicdns.park-your-domain.com
login=your-root-domain.com # NOT your namecheap.com account name!
@matthewadams
matthewadams / LoggingSupport.kt
Created May 19, 2022 19:54
Convenient logback json support using Kotlin extensions
// NOTE: inspired by https://www.innoq.com/en/blog/structured-logging/#structuredarguments
import net.logstash.logback.argument.StructuredArguments.kv
import org.slf4j.Logger
const val DEFAULT_KEY = "ctx"
internal fun o(ctx: Any? = null) = kv(
DEFAULT_KEY,
object {
@matthewadams
matthewadams / hid-remap
Created July 9, 2020 17:57
macOS HID remap script
#!/usr/bin/env bash
usage() {
cat <<EOF
usage:
$0 -p productId remappings
options:
-p,--product-id: productId The keyboard product id (from Menu Bar\\⌥\SystemInformation...\Hardware)
// stolen from https://gist.github.com/mikeal/1840641#gistcomment-3126524
import { createServer } from 'net'
export default function getPort (port = 80, maxPort = 65535) {
if ((maxPort = parseInt(maxPort)) < (port = parseInt(port)) || isNaN(port) || isNaN(maxPort) || port < 0 || port > 65535 || maxPort < 0 || maxPort > 65535) {
return Promise.reject((() => {
const e = new Error('EPORTSPEC')
e.code = e.message
return e
'use strict'
/**
* Function that returns a `Promise` that `await`s an `async` function's completion.
*
* @param {Object} [arg={}] The argument to be destructured.
* @param {function} [arg.asyncFn=AwaitingPromise.DEFAULT_FN] An `async` function whose completion is to be `await`ed.
* Defaults to a no-op function.
* @param {boolean} [arg.positive=true] If truey, the returned `Promise` will resolve if `asyncFn` does not throw, and will reject with the error that `asyncFn` throws.
* If falsey, the returned `Promise` will reject with parameter `err`'s value if `asyncFn` does not throw, and will resolve with the error that `asyncFn` throws.
@matthewadams
matthewadams / npm-update.sh
Created December 28, 2018 17:11
Update all npm packages to their latest versions
#!/usr/bin/env bash
NPM_UPDATE_DEFAULT_PACKAGE_FILE=package.json
NPM_UPDATE_PACKAGE_FILE=$NPM_UPDATE_DEFAULT_PACKAGE_FILE
usage() {
cat<<EOF
Update outdated npm packages to the latest available
$(basename "$0")