Skip to content

Instantly share code, notes, and snippets.

View purcell's full-sized avatar

Steve Purcell purcell

View GitHub Profile
@purcell
purcell / wrap-pg-auth
Created August 17, 2023 14:23
Invoke a postgres command via a bastion host with auth obtained from 1password
#!/bin/bash -e
error_exit() {
echo "$@" >&2
exit 1
}
usage_exit() {
cat <<EOF >&2
Allows you to run a local postgres command, e.g. psql or pg_dump,
@purcell
purcell / access-log-to-parquet.sql
Created September 4, 2023 19:23
Use DuckDB to convert a compressed web access log in Combined Log Format to Parquet
COPY (
WITH
-- Read the raw log line by line by abusing CSV parser
raw_log AS (
FROM read_csv_auto('/tmp/log/access.log-20230904.gz', header=false, delim='\0')
)
, combined_log AS (
SELECT regexp_extract(column0
, '^(\S+) (\S+) (\S+) \[(.*?)\] "([A-Z]+?) (.*?) HTTP/(.*?)" (\d+) (\d+) "(.*?)" "(.*?)"$'
, [ 'ip', 'identity', 'userid', 'timestamp', 'method'
@purcell
purcell / install.log
Created April 1, 2025 13:59
pg_query installation failure
# Latest ruby from homebrew:
$ ruby --version
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]
$ cat Gemfile
source "https://rubygems.org"
gem "pg_query"
$ bundle update --verbose
Running `bundle update --verbose` with bundler 2.6.3