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 /
Last active Jul 17, 2019
Script to manage searching, backing up, and collecting infinite clipboard history from the Alfred Clipboard History on macOS.
#!/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.
# Example Usage:
# backup
# status
# shell
# dump > ~/Desktop/clipboard_db.sqlite3
def get_master_from_obj_id(org, obj_type: str, obj_id: str):
from sync.models import Master, Version
version = Version.objects.filter(,
pirate /
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"
import sys
def current_function_name(above=1):
"""returns the calling function's __module__.__name__"""
frame = sys._getframe()
for frame_idx in range(0, above):
frame = frame.f_back
pirate /
Last active Jul 8, 2019
Bash script to remove accents and special characters from filenames recursively.
#!/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.:
pirate /
Last active Jul 3, 2019
Backup a docker-compose project, including all images, named and unnamed volumes, container filesystems, config, logs, and databases.
#!/usr/bin/env bash
# Fully backup a docker-compose project, including all images, named and unnamed volumes, container filesystems, config, logs, and databases.
project_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
cd "$project_dir"
project_name=$(basename "$project_dir")
backup_time=$(date +"%Y-%m-%d_%H-%M")
pirate /
Last active Jul 5, 2019
An extended HTTPResponse class for Django 2.2 adding support for streaming partial template responses incrementally, preload headers, HTTP2 server push, CSP headers, running post-request callbacks, and more (fully typed).
This is an extended HTTP response class for Django >=2.0 that adds lots of fancy features.
It's most useful when needing to accellerate slow view functions that return templates,
but it can be used anywhere where you need to return an HTTPResponse() or render(...).
It works by subclassing the builtin Django HttpResponse and StreamingHttpResponse,
and adding improvements in many areas, including functionality, speed, and security.
The most up-to-date version of this code can be found here:
# This is a decorator that checks the function parameters as runtime against their type hints.
# @enforce_types
# def example(a: str, b: int):
# return 'Success!'
# if __name__ == '__main__':
# example('abc', 123)
# example(123, 'abc') # this throws a TypeError
NoneType = type(None)
JsonValue = Union[str, int, float, bool, NoneType]
SocketMessage = Dict[str, JsonValue]
socket_routes = {
'/table/<table_id>/': [PresenceManager, TimeSync, PokerTable],
'/tournament/<table_id>/': [PresenceManager, Tournament, PokerTable],
'/speedtest/': [SpeedTest],
"""Run some code after the response is returned to the user in django
Great for analytics or other slow tasks that you don't want to block the response
to the user for.
class HttpResponseWithCallback(HttpResponse):
def __init__(self, *args, **kwargs):
self.callback = kwargs.pop('callback')
super().__init__(*args, **kwargs)
You can’t perform that action at this time.