Skip to content

Instantly share code, notes, and snippets.

View huntfx's full-sized avatar

Peter Hunt huntfx

View GitHub Profile
@huntfx
huntfx / decrypt-mysql-workbench-user-data.py
Created August 1, 2023 12:58
Read and decrypt the user data from MySQL workbench.
import os
import re
import win32crypt # Requires pywin32 package
WORKBENCH_REGEX = re.compile(
'(?P<dbm>[A-z]+)'
'@'
'(?P<host>[A-z0-9._-]+)'
':'
@huntfx
huntfx / kelpergl-location-history.py
Created July 17, 2023 08:02
Quick script to convert the Google Location History "Records.json" into a format compatible with kepler.gl
import csv
import json
# Open the JSON file and read its contents
print('Loading data...')
with open('Records.json') as json_file:
data = json.load(json_file)
# Create a CSV file and write the headers
print('Processing data...')
@huntfx
huntfx / reddit-user-downloader.py
Last active April 2, 2024 23:21
Download all the media on a Reddit user profile.
"""This is a basic script I mashed together to download all the media on a users profile.
Nothing else I found seemed to work well, so I added support for all the media types I came across.
The code isn't particularly clean or optimised, it just gets the job done.
Usage:
UserDownloader(username).download()
It will download to `current_dir/username/filename.ext`.
An SQLite database saved in the same folder is used to ignore duplicate urls and file hashes.
@huntfx
huntfx / blender_menus.py
Created June 7, 2022 12:10
Menu context manager for Blender.
"""Menu context manager for Blender.
Example:
>>> with Menu('Custom Menu') as menu:
... with menu.add_submenu('Submenu') as submenu:
... submenu.add_operator('mesh.primitive_cube_add')
... menu.add_operator(lambda: 1/0, 'Raise Exception')
>>> menu.register()
>>> menu.unregister()
"""
@huntfx
huntfx / git-restore-mtime.py
Created April 25, 2022 21:02
Use past commits to restore the modified date on files
# Very small changes to an existing script, copying here for personal use
# Run file from next to the .git folder
import subprocess, shlex
import sys, os.path
os.chdir(os.path.dirname(__file__))
filelist = set()
for path in (sys.argv[1:] or [os.getcwd()]):
@huntfx
huntfx / format_bytes.sql
Created April 22, 2021 09:44
Function to convert bytes to KB/MB/TB etc in SQL
CREATE FUNCTION `format_bytes` (val float)
RETURNS varchar(20)
DETERMINISTIC
CONTAINS SQL
BEGIN
DECLARE pw smallint;
IF val < 1024 THEN
return CONCAT(val, ' B');
END IF;
SET pw = LEAST(7, FLOOR(LOG(val) / LOG(1024)));
@huntfx
huntfx / quicksync.py
Created April 4, 2021 12:07
Quick script to mirror folders across multiple computers using Google Drive File Sync.
# Quick script to mirror folders using Google Drive File Sync.
# Built for transferring VR game saves from a laptop to my main PC.
# For example, to keep Firefox in sync, create a "G:/My Drive/Firefox"
# directory, copy this script and create two batch files:
# upload.bat: py quicksync.py upload %APPDATA%/Mozilla/Firefox
# download.bat: py quicksync.py download %APPDATA%/Mozilla/Firefox
import sys
"""Get import dependencies using PyInstaller.
The node types can be used to check for instances.
A brief description of the main ones are below:
MissingModule: An imported module that cannot be found.
Attributes:
identifier (str)
Example:
MissingModule('invalid.module',)
@huntfx
huntfx / ciphers_of_the_monks.py
Last active January 11, 2021 00:26
Convert numbers to and from the Cistercian numeral system
"""Convert numbers to the Cistercian monk numeral system.
https://en.wikipedia.org/wiki/The_Ciphers_of_the_Monks
"""
import numpy as np
def horizontal_reverse(n):
"""Horizontally reverse a number index."""
"""Grab the test count and grader setup from the EdX Python exercises."""
import os
import sys
mod = __import__(sys.argv[1][:-3])
def __fn__(*args, **kwargs):
print('Number of tests:', len(mod.grader.tests()))
print()