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 / dramatiq_dashboard_server.py
Created Nov 8, 2019
Standalone HTTP webserver serving the Dramatiq-Dashboard WSGI using bjoern and a redis broker to read dramatiq task state.
View dramatiq_dashboard_server.py
#!/usr/bin/env python3
# Dramatiq dashboard server script.
# pip install dramatiq[redis] dramatiq-dashboard bjoern
import bjoern
import argparse
import dramatiq
from dramatiq.brokers.redis import RedisBroker
from dramatiq_dashboard import DashboardApp
@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 Nov 15, 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
You can’t perform that action at this time.