Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jnhmcknight on github.
  • I am jnhmcknight (https://keybase.io/jnhmcknight) on keybase.
  • I have a public key whose fingerprint is 6354 4B36 99BD 04CC 56B2 63F1 D2C8 64A5 BAC3 1834

To claim this, I am signing this object:

@jnhmcknight
jnhmcknight / headers.py
Created December 1, 2017 21:37
S3-website-cache-control-setter
# -*- coding: utf-8 -*-
from flask import Flask
import logging
import boto3
import os
from copy import deepcopy
@jnhmcknight
jnhmcknight / colour-inverter.py
Created June 15, 2018 14:09
Invert all colours in a CSS file.
#!/usr/bin/env python
# Concept taken from http://code.activestate.com/recipes/527747-invert-css-hex-colors/
# Modified to take the css filename as an argument and also handle rgb() and rgba() values
#
# To run:
# python ./colour-inverter.py <path/to/file.css>
import os
import re
@jnhmcknight
jnhmcknight / inject_ca.py
Created July 10, 2018 16:01
Inject an arbitrary certificate authority into a certifi bundle
#!/usr/bin/env python
"""
Usage: python ./inject_ca.py <path/to/new/ca.crt> [<path/to/other/new/ca.crt> [...]]
"""
import certifi
import os
import re
import sys
@jnhmcknight
jnhmcknight / mandrill-hook-utils.py
Last active April 27, 2020 15:02
Mandrill webhook decorator
"""
Utilities for use with Mandrill Webhooks
requirements:
- six
- email-reply-parser (git+https://github.com/atc0m/email-reply-parser.git#egg=email_reply_parser)
"""
import base64
#!/usr/bin/env python3
"""Show subnets information.
Given an IP network in CIDR notation and the minimum number of desired subnets,
this script will provide the relevant information about the desired subnets.
Example:
$ ./subnet-divider.py 10.10.0.34/16 4
$ ./subnet-divider.py fd3e:48fe:59b2:43ca::/64 15
@jnhmcknight
jnhmcknight / postgres_queries_and_commands.sql
Last active November 4, 2022 13:36 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show granted locks
SELECT blocked_locks.pid AS blocked_pid,
blocked_activity.usename AS blocked_user,
blocking_locks.pid AS blocking_pid,
blocking_activity.usename AS blocking_user,
blocked_activity.query AS blocked_statement,
blocking_activity.query AS current_statement_in_blocking_process
FROM pg_catalog.pg_locks AS blocked_locks
JOIN pg_catalog.pg_stat_activity AS blocked_activity ON blocked_activity.pid = blocked_locks.pid
JOIN pg_catalog.pg_locks AS blocking_locks
@jnhmcknight
jnhmcknight / repo-sercret.py
Last active May 25, 2022 13:56
Add or update repo secrets based on the contents of one or more .env files
#!/usr/bin/env python3
"""
Add or update repo secrets based on the contents of one or more .env files
To run this, you will need:
- Python3 installed
- have created a personal access token with the relevant privileges within GitHub
- copied this gist into a file named `repo-secret.py`
- and complete the following:
@jnhmcknight
jnhmcknight / s3.py
Last active August 9, 2022 14:21
S3 Bucket Point-In-Time Snapshot Creation
"""
This requires that you have versioning enabled on the S3 bucket. Without that, this script cannot do anything useful.
Install Dependencies: `pip3 install boto3 click dateparser pytz`
Run it: `python3 ./s3.py bucket-snapshot [OPTIONS] BUCKET-NAME UTC-DATE-TIME DESTINATION-FOLDER`
"""
import json
import os
@jnhmcknight
jnhmcknight / get-out-of-debt.py
Last active October 6, 2022 17:17
Debt clearing month calculator
#!/usr/bin/env python3
"""
This takes a JSON file of your current debts, and does a rollover calculation to see how long it will
take to pay off all of it, based on clearing the smallest debt first and merging that payment into
the next smallest debt's payment, and then repeating that process until all debts have been paid.
This calculator assumes that you are not increasing any of the debts in any way (ie: not still using
your credit card or credit line to pay for any things.)
Save this file locally, and run: