Skip to content

Instantly share code, notes, and snippets.

View encima's full-sized avatar
🐴
selling spare horse kidneys. PM me

Chris Gwilliams encima

🐴
selling spare horse kidneys. PM me
View GitHub Profile
@encima
encima / Dockerfile
Last active November 18, 2025 10:17
pg_net 0.8.0 to 0.19.5 upgrade on debian
FROM postgres:15-bookworm
# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
postgresql-server-dev-15 \
libcurl4-openssl-dev \
git \
ca-certificates \
wget \
@encima
encima / conmon.sql
Last active November 17, 2025 13:42
Historical Postgresql Connection Monitoring
create schema if not exists conmon;
create table if not exists conmon.connection_activity_history (
snapshot_id bigint generated always as identity primary key,
sampled_at timestamptz not null default now(),
total_backends integer not null,
active_backends integer not null,
idle_backends integer not null,
waiting_backends integer not null,
app_connections jsonb not null,
@encima
encima / index.ts
Created June 13, 2025 07:12
Supabase User Impersonation Edge Function
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
import { createClient } from "jsr:@supabase/supabase-js@2";
Deno.serve(async (req)=>{
if (req.method === 'OPTIONS') {
return new Response('ok', {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, OPTIONS',
@encima
encima / mgmt-config.bash
Created March 26, 2025 08:53
Supabaase Management API to config - pulling from the Management API to match the config.toml reference
#!/bin/bash
set -e
# Default values
OUTPUT_FILE="config.toml"
# Function to display usage information
usage() {
echo "Usage: $0 --ref <project_ref> [--token <access_token>] [--output <output_file>]"
echo
@encima
encima / mgmt-config.bash
Created March 26, 2025 08:53
Supabaase Management API to config - pulling from the Management API to match the config.toml reference
#!/bin/bash
set -e
# Default values
OUTPUT_FILE="config.toml"
# Function to display usage information
usage() {
echo "Usage: $0 --ref <project_ref> [--token <access_token>] [--output <output_file>]"
echo
@encima
encima / index.ts
Created June 26, 2024 12:46
PG Faker Function - Fake data on the edge
import { HTTPException, Hono } from "https://deno.land/x/hono@v4.3.11/mod.ts";
import type { Context } from 'https://deno.land/x/hono/mod.ts';
import { faker } from "https://deno.land/x/deno_faker@v1.0.3/mod.ts";
import * as postgres from 'https://deno.land/x/postgres@v0.17.0/mod.ts'
const app = new Hono();
const dbURL = Deno.env.get('SUPABASE_DB_URL');
const pool = new postgres.Pool(dbURL, 3, true)
const schemas = {
@encima
encima / labeler.yaml
Created May 17, 2024 09:55
Auto Label Issues and PRs - Github Action
name: Auto Label PRs
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
check-external:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.is-member.outputs.result }}
steps:
@encima
encima / managing_connections.md
Last active February 7, 2024 07:13
Supabase and Supavisor - Postgres and Poolers

Supabase and Supavisor - Postgres and Poolers

There may come a time where you want more insight into your database; to understand who is doing what...and when. You might already be familiar with some of Postgres' system functions and views and, in this short guide, we will take a look at the catchy Cumulative Statistics System, providing insights into replication slots, connections, the WAL and more (that you can read about here)

Viewing Your Connections

All connections can be viewed using pg_stat_activity and you can simply start with:

@encima
encima / visualize.py
Created November 11, 2023 13:21
Github vs Linkedin Activity Visualizer Example
import requests
from datetime import datetime, timedelta
import dash
from dash import html, dcc
import plotly.graph_objs as go
from dash.dependencies import Input, Output
from bs4 import BeautifulSoup
# GitHub setup
GITHUB_TOKEN = 'your_github_token_here' # Replace with your GitHub token
@encima
encima / clone-hnl.py
Created November 9, 2023 10:29
clone-repo-from-tags
import requests
import subprocess
import os
# Personal access token from GitHub
# Replace 'your_token_here' with your actual GitHub personal access token.
GITHUB_TOKEN = os.getenv('GH_TOKEN')
# Directory where you want to clone the repositories
CLONE_DIR = os.getenv('CLONE_DIR', './')