Skip to content

Instantly share code, notes, and snippets.

View justinfx's full-sized avatar

Justin Israel justinfx

View GitHub Profile
@justinfx
justinfx / py_cudart_memory.py
Last active January 18, 2016 16:05
Get memory usage of CUDA GPU, using ctypes and libcudart
import ctypes
# Path to location of libcudart
_CUDA = "/Developer/NVIDIA/CUDA-5.5/lib/libcudart.5.5.dylib"
cuda = ctypes.cdll.LoadLibrary(_CUDA)
cuda.cudaMemGetInfo.restype = int
cuda.cudaMemGetInfo.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
cuda.cudaGetErrorString.restype = ctypes.c_char_p
@justinfx
justinfx / mayaQtEmbedRenderView.py
Last active August 29, 2015 13:56
Maya / PyQt: A variation of https://gist.github.com/justinfx/1381489 where we embed the Render View, instead
from PyQt4 import QtCore, QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as mui
import sip
global app
@justinfx
justinfx / errors.out
Last active December 29, 2015 18:49
Broken cgo / C++ test for Go, trying to wrap OpenColorIO
$ go build -x -v .
# swigtest/ocio
ocio/ocio.cpp:24:16: error: no viable conversion from 'OCIO::ConstConfigRcPtr' (aka 'shared_ptr<const OpenColorIO::v1::Config>') to 'Config *' (aka 'void *')
/usr/include/c++/4.2.1/tr1/boost_shared_ptr.h:678:7: note: candidate function
@justinfx
justinfx / colorpot.py
Last active December 16, 2017 12:59
ColorPot widget, with tree widget example for keeping background color in sync
from PyQt4 import QtGui, QtCore
# from PySide import QtGui, QtCore
class ColorPot(QtGui.QFrame):
# colorChanged = QtCore.Signal(QtGui.QColor)
colorChanged = QtCore.pyqtSignal(QtGui.QColor)
def __init__(self, color=None, parent=None):
super(ColorPot, self).__init__(parent)
@justinfx
justinfx / weakmethod_callbacks_qt.py
Last active December 20, 2015 19:29
Example of having thread-safe callbacks from threads back to the main event loop, in PySide/PyQt4. Also adds support for weak method references to the callback, so as not to call something when the original object might have been deleted. Merges forked examples from both: http://code.activestate.com/recipes/81253/#c5 and http://code.activestate.…
"""
ActiveState:
http://code.activestate.com/recipes/578634-pyqt-pyside-thread-safe-callbacks-main-loop-integr/
ref and proxy classes are based on:
http://code.activestate.com/recipes/81253/#c5
Modified proxy to support a quiet concept for callbacks that can
simply pass if they were not valid, instead of raising an exception.
@justinfx
justinfx / child_window_test.py
Last active December 19, 2015 14:39
Showing a test, inside and outside of Maya, of child windows still remaining alive after being closed. Test can toggle the WA_DeleteOnClose attribute on each child widget:
#!/usr/bin/env python
"""
Showing a test, inside and outside of Maya,
of child windows still remaining alive after being closed.
Test can toggle the WA_DeleteOnClose attribute on each child widget:
# Command line (dont delete)
$ ./child_window_test.py
@justinfx
justinfx / plow_rebuild.sh
Created June 27, 2013 10:43
A helper shell script to completely rebuild Plow server / client, along with dropping the Postgres plow schema, and building it again. Run with the path to the root of the plow source location as the first argument. Adjust the psql host/port to suit
#!/bin/bash
if [ -z $1 ] || [ ! -d ${1}/server ]; then
echo "plow_rebuild.sh <path to plow source>"
exit 1
fi
realpath1() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
@justinfx
justinfx / colordialog.py
Created June 16, 2013 20:26
Example of having QColorDialog remember the last color selection Corrected from: http://pastebin.com/L9ge14k0
from PyQt4 import QtCore, QtGui
class ColorBox(QtGui.QFrame):
def __init__(self,parent=None):
super(ColorBox,self).__init__(parent)
self.bgColor = QtCore.Qt.white
self.setFixedHeight(20)
self.setFrameStyle(1)
@justinfx
justinfx / mm_pushbutton.py
Created June 14, 2013 00:28
Attaching a Maya Marking Menu to the right click of a PyQt QPushButton widget
from PyQt4 import QtCore, QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as mui
import sip
def getMayaWindow():
ptr = mui.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QtCore.QObject)
widget = QtGui.QDialog(getMayaWindow())
// Preferences.sublime-settings
{
// ...
"auto_complete_triggers": [{"selector": "source.python", "characters": "."}],
"auto_complete_selector": "-"
}