Skip to content

Instantly share code, notes, and snippets.

View huntfx's full-sized avatar

Peter Hunt huntfx

View GitHub Profile
@huntfx
huntfx / set_date_from_name.py
Created August 11, 2019 15:23
Figure out the date an image was created, and set the created/modified time to match. Run the Python file from inside a folder to apply to all images.
import os
import time
from contextlib import suppress
if os.name == 'nt':
from ctypes import windll, wintypes, byref
def set_creation_time(path, timestamp):
"""Set the creation time of files in Windows.
"""Qt script editor for Python with syntax highlighting.
Author: Peter Hunt
Updated: 5/9/2019
"""
try:
import builtins
except ImportError:
import __builtin__ as builtins
@huntfx
huntfx / hl2_lambda.py
Created November 24, 2019 22:03
Find the missing lambda cache locations in Half Life 2.
"""Find the missing lambda cache locations in Half Life 2."""
import os
# Change this line if you have games installed elsewhere
STEAMAPPS = 'C:/Program Files (x86)/Steam/steamapps/common/'
GAMESTATE = os.path.join(STEAMAPPS, 'Half-Life 2/hl2/gamestate.txt')
# Locations from https://steamcommunity.com/sharedfiles/filedetails/?id=145616679
"""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()
@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."""
@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
@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 / 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()]):
"""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 / 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()
"""