Skip to content

Instantly share code, notes, and snippets.

View theodox's full-sized avatar

Steve Theodore theodox

View GitHub Profile
@theodox
theodox / KMeans.py
Created June 28, 2017 00:21
A simple implementation of the KMeans algorithm
from collections import defaultdict, namedtuple
import operator
import random
from functools import reduce
import math
class Vector(namedtuple('vector', 'x y z')):
"""A generic Vector object"""
@theodox
theodox / Canvas.py
Created May 4, 2017 17:51
a simple set of tools for working with images using the Maya api
from array import array
from itertools import islice, izip, imap, izip_longest, tee, chain, product, ifilter
from maya.api.OpenMaya import MImage
import ctypes
def image_to_bytearray(img):
"""
@theodox
theodox / cython_compile.py
Created December 22, 2016 23:14
takes some of the typing out of compiling a Python27 exe using Cython. Expects that you've got https://www.microsoft.com/en-us/download/details.aspx?id=44266 installed
import os
import sys
import subprocess
PYHOME = os.environ.get("PY27", "C:\\ul\\tools\\python\\python27\\")
PYLIB = PYHOME + "libs"
PYINC = PYHOME + "include"
subprocess.call(("cython", sys.argv[-1], "--embed" ))
scriptfile = sys.argv[-1].replace(".pyx", ".py").replace(".py", ".c")
import os
class UPathError(ValueError):
pass
class PathIsNotRelative(UPathError):
pass
@theodox
theodox / EnvSetting.py
Created September 26, 2015 00:23
A simple set of classes for dealing with environment variables.
__author__ = 'Steve'
import os
class EnvSetting(object):
"""
Set and unset an environemnt variable. If the variable did not exist at set time, it will be deleted at unset time
setter = EnvSetting('var', value)
@theodox
theodox / github-like.css
Created March 18, 2015 05:23
A pygments-friendly CSS code hightlighting scheme. Works with the default `.codehilite` tags produced by Sublime text MarkdownPreview
/*
* GitHub style for Pygments syntax codehiliteer, for use with Pygments. Note the ".codehilite" tag names
* Courtesy of GitHub.com
*/
.codehilite pre, pre, .codehilite .hll { background-color: #f8f8f8; border: 1px solid #ccc; padding: 6px 10px; border-radius: 3px; }
.codehilite .c { color: #999988; font-style: italic; }
.codehilite .err { color: #a61717; background-color: #e3d2d2; }
.codehilite .k { font-weight: bold; }
.codehilite .o { font-weight: bold; }
def add(vect, other):
return tuple(a + b for a, b in zip(vect, other))
def sub(vect, other):
return tuple(a - b for a, b in zip(vect, other))
def mul(vect, other):
if hasattr(other, '__iter__'):
return tuple(a * b for a, b in zip(vect, other))
return tuple(a * b for a, b in zip(vect, [other] * len(vect)))
from collections import namedtuple
import math
class Vector(object):
"""
generic vector operations
"""
def __add__(self, other):
return type(self)(*(a + b for a, b in zip(self, other)))
using UnityEngine;
using System.Collections;
/*
This is a simple example of the PIDContoller class.
For a discussion of PID theory see http://techartsurvival.blogspot.com/-address-tbd
Legalese:
@theodox
theodox / melfunction.py
Last active August 25, 2019 19:49
Tools for wrapping rogue mel commands
melfunction.py
"""
Provides tools for wrapping mel commands for more Pythonic access.
Note this is a supplement to maya.cmds, not a replacement for it! This is intended to provide
similar coverage for un-translated MEL or commands fron plugins which don't respect the
ordinary cmds conventions.
Legalese: