This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
import os | |
import click | |
@click.group() | |
def cli(): | |
"""A grouping of commands""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Include this file in your project, and then import it instead of the real `boto3`, | |
wherever you need to create a `boto3.client` or `boto3.resource` | |
i.e.: | |
import wrapped_boto3 | |
s3 = wrapped_boto3.client('s3') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
import typing as t | |
import click | |
from click._compat import _get_argv_encoding | |
class RegexOption(click.ParamType): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
chunk_size = 4096 | |
filename = "logo.png" | |
document_url = "https://wasi0013.files.wordpress.com/2018/11/my_website_logo_half_circle_green-e1546027650125.png" | |
with requests.get(document_url, stream=True) as r: | |
with open(filename, 'wb') as f: | |
for chunk in r.iter_content(chunk_size): | |
if chunk: | |
f.write(chunk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enum import Enum, EnumMeta | |
from flask import Flask, current_app | |
from werkzeug.routing import BaseConverter, ValidationError | |
def setup_enum_converter(enum_to_convert): | |
if not isinstance(enum_to_convert, (Enum, EnumMeta,)): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
NewerOlder