Skip to content

Instantly share code, notes, and snippets.

🗃
Archiving all the things!

Nick Sweeting pirate

🗃
Archiving all the things!
Block or report user

Report or block pirate

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pirate
pirate / internet_archiving_talk.md
Created Oct 18, 2019
Slides outline for my internet archiving talk at Open Network & PyGotham.
View 2019 Toronto Open Networks Ligtning Talks.md

2019 Toronto Open Networks Ligtning Talks

Nick Sweeting @theSquashSH (Twitter) @pirate (Github) Monadical.com


Internet Archiving (3min)

  • 1 min: Intro to internet archiving
    • Why is preserving information important? why does humanity create libraries and museums?
    • How has it been done so far?
@pirate
pirate / argo.sh
Created Aug 12, 2019
Cloudflare Argo Tunnel helper script that waits for the server to come up before starting the tunnel.
View argo.sh
#!/usr/bin/env bash
# usage:
# ./bin/argo cloud.monadical.com http://127.0.0.1:9089
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
DOMAIN="$1" # e.g. "cloud.monadical.com"
URL="$2" # e.g. "https://127.0.0.1:9089"
read SCHEME HOST PORT <<<$(IFS="://"; echo "$URL")
@pirate
pirate / ssl.sh
Last active Aug 14, 2019
SSL certificate generation script supporting openssl, mkcert, and letsencrypt with manual/standalone/webroot/cloudflare-dns/digitalocean-dns.
View ssl.sh
#!/usr/bin/env bash
# set -o xtrace
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
SCRIPTNAME="$0"
HELP_TEXT="
@pirate
pirate / dns.sh
Last active Aug 12, 2019
Dynamic DNS updater script for DigitalOcean and CloudFlare (using bash, curl, and jq)
View dns.sh
#!/usr/bin/env bash
# set -o xtrace
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
SCRIPTNAME="$0"
HELP_TEXT="
@pirate
pirate / safe_number.py
Last active Aug 4, 2019
A SafeNumber type for Python that implements the fractions.Fraction interface with guards to prevent implicit operand type casting leading to a loss of precision.
View safe_number.py
# For more info on math safety and data integrity in Python see here:
# https://github.com/pirate/django-concurrency-talk/blob/master/README.md#-the-correct-approach-with-a-custom-safenumber-type
from typing import Union, Any
from decimal import Decimal
from fractions import Fraction
SAFE_NUM_TYPES = (int, str, Fraction, Decimal)
SAFE_NUM_TYPES_STR = 'Union[int, str, Fraction, Decimal, SafeNumber]'
@pirate
pirate / alfred-clipboard.sh
Last active Sep 30, 2019
Script to manage searching, backing up, and collecting infinite clipboard history from the Alfred Clipboard History on macOS.
View alfred-clipboard.sh
#!/usr/bin/env bash
# This is a script that provides infinite history to get around Alfred's 3-month limit.
# It works by regularly backing up and appending the items in the alfred db to a
# sqlite database in the user's home folder. It also provides search functionality.
# https://www.alfredforum.com/topic/10969-keep-clipboard-history-forever/?tab=comments#comment-68859
# https://www.reddit.com/r/Alfred/comments/cde29x/script_to_manage_searching_backing_up_and/
# Example Usage:
# alfred-clipboard.sh backup
View chronosync_heart.py
def get_master_from_obj_id(org, obj_type: str, obj_id: str):
from sync.models import Master, Version
try:
version = Version.objects.filter(
source__organization_id=org.id,
obj_type=obj_type,
obj_id=obj_id,
mapping__isnull=False,
mapping__master_id__isnull=False,
@pirate
pirate / get_python_function_name.py
Created Jul 9, 2019
Efficiently return the full module path and function name of the calling function in Python e.g. "app.module.class.method"
View get_python_function_name.py
import sys
def current_function_name(above=1):
"""returns the calling function's __module__.__name__"""
# https://gist.github.com/JettJones/c236494013f22723c1822126df944b12#gistcomment-2962311
frame = sys._getframe()
for frame_idx in range(0, above):
frame = frame.f_back
@pirate
pirate / strip_bad_filename_characters.sh
Last active Jul 8, 2019
Bash script to remove accents and special characters from filenames recursively.
View strip_bad_filename_characters.sh
#!/usr/bin/env bash
# Recursively remove all special characters from filenames by renaming them to their ASCII normalized forms.
#
# By default it does a dry run, to actually move the files uncomment the `mv -vi ...` line.
#
# This is useful for cleaning up network shares that will be shared via SMB/NFS between Unix/macOS/Windows
# where non-ASCII filenames can sometimes cause "file does not exist" errors when trying to access the files.
#
# This script removes leading/trailing whitespace in filenames and replaces accents and non-english
# characters with their ASCII equivalent, if no ASCII equivalent exists, it removes the character e.g.:
You can’t perform that action at this time.