Skip to content

Instantly share code, notes, and snippets.

View theodox's full-sized avatar

Steve Theodore theodox

View GitHub Profile
@theodox
theodox / melpatch.py
Last active July 6, 2024 22:55
Support functions for patching a mel command at runtime, presumably to extend the base functionality with some extra python
import maya.mel
import re
import logging
_logger = logging.getLogger("patchmel")
_logger.setLevel(logging.ERROR)
def log_patches(do_logging : bool):
def add_tool(name, exe, commandline, shortcut=''):
'''
Adds a command entry to a tools list container node.
* tool_list_element is ElementTree node representing the tools list
* exe is the path to the executable
* commandline is the arguments passed to the commandline.
* shortcut is a key shortcut
If a tool with the same name already exists, it will be overwritten
Perforce supports special characters in the command lines, which
will be replaced at call time. see
@theodox
theodox / UnrealQT.py
Last active February 3, 2023 02:46
Delegates UnrealEd draw ticks to a PySide2 Application, allowing non-blocking updates
"""
"""
import unreal
import PySide2.QtWidgets as widgets
import traceback
class UEQApplication (widgets.QApplication):
"""
Ensure that an application never tries to `exec_` inside of Unreal
@theodox
theodox / Matrix.hlsl
Created April 27, 2019 23:20 — forked from mattatz/Matrix.hlsl
Matrix operations for HLSL
#ifndef __MATRIX_INCLUDED__
#define __MATRIX_INCLUDED__
#define IDENTITY_MATRIX float4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
float4x4 inverse(float4x4 m) {
float n11 = m[0][0], n12 = m[1][0], n13 = m[2][0], n14 = m[3][0];
float n21 = m[0][1], n22 = m[1][1], n23 = m[2][1], n24 = m[3][1];
float n31 = m[0][2], n32 = m[1][2], n33 = m[2][2], n34 = m[3][2];
float n41 = m[0][3], n42 = m[1][3], n43 = m[2][3], n44 = m[3][3];
@theodox
theodox / QT_Ctx.py
Last active December 24, 2018 08:14
a mixin to use QT layouts as if they were context managers
def is_gui_item(obj):
return isinstance(obj, QWidget) or isinstance(obj, QLayout)
class LayoutCtxMixin(object):
PARENTED = set() # tracks all widgets that have already been added to avoid double counting
DEPTH = 0
def __enter__(self):
LayoutCtxMixin.DEPTH += 1
import random
import logging
logger = logging.getLogger("chess")
logger.addHandler(logging.StreamHandler())
import time
import itertools
# the board is a sparse dictionary of x-y addresses
# it contains a color key (W or B) and a generator
@theodox
theodox / rpath.py
Created November 23, 2018 20:36
a copy of os.path.ntpath which returns windows paths with right instead of left slashes -- you could patch this in to `os.path` and not have to do any replacements elsewhere in code
# Module 'rpath' -- windows paths but using right slashes
"""Common pathname manipulations, WindowsNT/95 version.
"""
# strings representing various path-related bits and pieces
# These are primarily for export; internally, they are hardcoded.
# Should be set before imports for resolving cyclic dependency.
curdir = '.'
pardir = '..'
@theodox
theodox / MayaPyHost
Created November 2, 2018 23:34
interactive mayapy subprocess
"""
MayaPy.py
Remote control of a mayapy session with a simple proxy interface. This is not intended as a complete RPC server or anything of the sort; the primary use case is as an isolation chamber (since you can manipulate paths and environment variables) for use in testing.
"""
import subprocess
import cPickle as pickle
import os
import maya.cmds as cmds
from functools import wraps
from collections import Iterable
class NamespaceError(RuntimeError):
"""raised when a namespace object does not reflect the reality of the scene"""
pass
class NamespaceNameError(ValueError):
@theodox
theodox / ping.py
Created July 10, 2018 07:41
Micropython pyboard code for cailbrating and sensing with an ultrasonic sensor
from pyb import Pin, ExtInt, LED
import time
import utime
import micropython
micropython.alloc_emergency_exception_buf(100)
global last_ping, delta, LAG