Skip to content

Instantly share code, notes, and snippets.

View kljensen's full-sized avatar
😵‍💫
0101010101

Kyle L. Jensen kljensen

😵‍💫
0101010101
View GitHub Profile
@kljensen
kljensen / bipartite-perfect-match-plpgsql.sql
Created April 30, 2024 21:01
Perfect matching check in a bipartite graph using PL/pgSQL
/**
This file shows how to do a perfect matching check in a bipartite graph using PL/pgSQL.
*/
-- Use the pg_temp schema to avoid conflicts with other sessions
SET search_path TO pg_temp;
CREATE EXTENSION IF NOT EXISTS plpgsql;
CREATE TABLE IF NOT EXISTS lhs (
@kljensen
kljensen / delete-github-repos.sh
Created August 15, 2022 17:48
Bulk Delete GitHub Repos
#!/bin/sh
# This shell script will search for all repos matching a
# provided organization and regex. It will list those for
# you and, if you confirm, DELETE YOUR REPOS. 🔥🔥🔥⚠️⚠️⚠️
# It requires 'gh', the GitHub command line interface.
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Illegal number of parameters $*"
echo "Usage: $0 USER/ORG REGEX"
@kljensen
kljensen / install-postgresql-from-source.sh
Created March 30, 2021 00:25
Install PostgreSQL from source on GNU/Linux systems (likely also bsd)
#!/bin/sh
# Create a temprary directory
tmp_dir=$(mktemp -d -t pg-install-XXXXXXXXXX)
printf "Using tmp directory $tmp_dir\n"
# Remove that directory upon exit
trap 'cd && rm -rf -- "$tmp_dir"' EXIT
# Change to tmp dir
@kljensen
kljensen / postgresql-drop-role-loop.sql
Last active March 9, 2021 21:11
Postgresql command to drop a role after removing all privileges in a loop
/* This function loops over all schemas and drops a role's
privileges in those schemas and then drops the role. Call
it like `SELECT drop_role('foo');` where 'foo' is the role
you want to drop. Would be nice to have exception handling
😎😜
Inspiration:
https://stackoverflow.com/questions/3023583/how-to-quickly-drop-a-user-with-existing-privileges
*/
@kljensen
kljensen / README.md
Last active March 8, 2021 11:56 — forked from dlage/README.md
Namecheap DNS to zone file
@kljensen
kljensen / pre-commit
Created January 5, 2021 23:17
Git pre-commit hook to check/lint YAML format before committing
#!/bin/sh
# This file, or contents like below, should be in
# .git/hooks/pre-commit. If you have a YAML file
# with invalid formatting, the commit will be aborted.
# Check formatting of all yaml files.
# Uses yq v4. For v3 use 'r' instead of 'e'
fd -t f --regex '.*\.yaml' -x yq e {}
#!/usr/bin/env zsh
# This is a zsh shell script for uploading files to s3 in order to share
# them via email, sms, or similar. The uploaded files are purged from your
# s3 bucket after 30 days so that you don't incur storage costs. After upload
# the public URLs for your files are copied to the clipboard (if you're using
# a mac and have `pbcopy`). The only zsh-specific part of the code is the
# array append/join (I think). You can likely port this to a different shell
# with relative ease. This requires the AWS CLI, AWS credentials (`aws configure`),
# and an existing bucket (see `$BUCKET` below).
@kljensen
kljensen / pf-whitelist-google-ip-addresses
Last active April 18, 2020 11:57
download google ip addresses in order to whitelist in your firewall, e.g. pf.
#!/bin/sh
dig TXT +short _spf.google.com | \
tr ' ' '\n'| \
grep 'include:' | \
sed 's/include://' | \
xargs -Ixxx dig TXT +short xxx | \
tr ' ' '\n' | \
grep '^ip[46]:' | \
cut -c5-
# Outputs something like
@kljensen
kljensen / remove-spaces-before-citations.lua
Last active January 7, 2020 20:37
A Pandoc Lua filter that removes Spaces before Cite elements
local function remove_citation_space(para)
local table elements = {}
i = 0
local function logel(el)
i = i + 1
elements[i] = el.t
end
pandoc.walk_block(para, {Inline = logel})

I don't why c9 has such ancient node versions some times. To get something more recent, do

nvm install 8
nvm alias default 8