Skip to content

Instantly share code, notes, and snippets.

@nathansgreen
nathansgreen / gs-resample.sh
Created December 22, 2022 16:17 — forked from lkraider/gs-resample.sh
Ghostscript PDF quality downsample
#!/bin/sh
# It seems it's very hard to set resample output quality with Ghostscript.
# So instead rely on `prepress` preset parameter to select a good /QFactor
# and override the options we don't want from there.
gs \
-o resampled.pdf \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
@nathansgreen
nathansgreen / config
Created February 13, 2023 20:21
.ssh/config
IdentitiesOnly=yes
ConnectTimeout=10
ConnectionAttempts=1
Host *
UseKeychain yes
GSSAPIAuthentication no
Host 10.245.*
User ec2-user
IdentityFile ~/.ssh/aws.pem
@nathansgreen
nathansgreen / icloud-evict.sh
Last active May 25, 2023 17:28
Fix macOS not enough free space to update
#!/bin/sh
# Manually free up local copies of files backed up to iCloud.
path=${1:-*}
pushd "~/Library/Mobile Documents/com~apple~CloudDocs" \
&& brctl evict $path
@nathansgreen
nathansgreen / last_insert_test.sql
Last active August 4, 2023 04:42
MySQL LAST_INSERT_ID used with On Duplicate Key Update
/*
* Quick demonstration of `id = LAST_INSERT_ID(id)` being the key to returning
* the existing id when doing `ON DUPLICATE KEY UPDATE`. The unfortunate side
* effect of this approach is that the sequence number for `id` increments on
* every update, even though the value for the updated row does not change. On
* update-heavy systems with 32-bit id`s, the sequence could be exhausted in a
* fairly short amount of time.
*
* Just switch to MariaDB and use `RETURNING id` instead. PostgreSQL got this
* keyword in 2006. Oracle was doing this in procedural code no later than 1997.
@nathansgreen
nathansgreen / docker-compose.yml
Created December 4, 2023 17:39
UniFi Network Application with FerretDB
version: "3.8"
services:
unifi-controller:
image: lscr.io/linuxserver/unifi-network-application:7.5.187
restart: unless-stopped
depends_on:
- ferretdb
environment:
PUID: 1000
PGID: 1000
@nathansgreen
nathansgreen / new-mac-iinit.sh
Last active February 26, 2024 15:02
Initial setup for a new MacOS install
#!/usr/bin/env sh
# stuff to do when setting up a fresh install of MacOS
set -o errexit -o nounset -o noclobber
[ -e /etc/pam.d/sudo_local ] || \
echo 'auth sufficient pam_tid.so' \
| sudo tee /etc/pam.d/sudo_local
softwareupdate --install-rosetta --agree-to-license
@nathansgreen
nathansgreen / example.sql
Last active January 24, 2024 23:06
Postgres Sequence Bulk Increment
-- I needed a way to safely pull a bunch of sequence values to my client in order to bulk
-- insert many thousands of rows. I'm doing this because I don't want to use 128-bit keys.
-- I found this:
-- https://www.depesz.com/2008/03/20/getting-multiple-values-from-sequences/
select pg_advisory_lock(123);
alter sequence seq increment by 1000;
select nextval('seq');
alter sequence seq increment by 1;
select pg_advisory_unlock(123);