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 / 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', './')
@encima
encima / supabase-api-logger.py
Last active November 15, 2023 10:53
Supabase API to rsyslog
import requests
import datetime
import config # create file with necessary vars (or use env)
headers = {
'Authorization': f'Bearer {config.supabase_token}',
'Content-Type': 'application/json'
}
response = requests.get(
@encima
encima / inspect_snapshot.sh
Created November 6, 2023 13:09
Supabase DB Inspect Snapshot (requires Supabase CLI)
#!/bin/zsh
# Run as ./inspect_snapshot.sh $DB_URI $OUTPUT_DIR
inspect_help=$(supabase inspect db -h)
cmds=("${(@f)$(echo "$inspect_help" | awk '/^[[:space:]]{2}[[:alpha:]]+/{print $1}')}")
shift cmds #remove supabase at index 0
current_date=$(date +%F)
@encima
encima / cpu.py
Created October 9, 2023 06:32
CPU Usage Visualization using Bokeh
import time
import psutil
from bokeh.plotting import figure, show
from bokeh.io import curdoc
from bokeh.models import ColumnDataSource
from bokeh.layouts import layout
from threading import Thread
# Prepare empty data source
source = ColumnDataSource(data=dict(time=[], cpu=[]))
@encima
encima / tefter_convert.py
Created May 27, 2023 08:15
Convert bookmarks exported from tefter.io from JSON to Netscape HTML format
import json
data = json.load(open('bookmarks.json','r'))
html = """
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!--This is an automatically generated file.
It will be read and overwritten.
DO NOT EDIT! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
@encima
encima / nvim
Created August 4, 2020 21:34
Minimal Configs
call plug#begin('~/.vim/plugged')
Plug 'junegunn/fzf.vim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
set hidden
nnoremap <Leader>f :Files<CR>
nnoremap <Leader>b :buffers<CR>:buffer<Space>