Skip to content

Instantly share code, notes, and snippets.

@nicelifeBS
nicelifeBS / timer.py
Created March 28, 2018 05:33 — forked from bradmontgomery/LICENSE.txt
A python decorator that logs execution time.
from functools import wraps
import logging
logger = logging.getLogger(__name__)
def timed(func):
"""This decorator prints the execution time for the decorated function."""
@wraps(func)
def wrapper(*args, **kwargs):
start = time.time()
@nicelifeBS
nicelifeBS / double2single.py
Created March 12, 2018 09:13
Replace double quotes with single quotes in string
import re
def replace(obj):
print(obj.groups())
if obj.group(0) == '\'':
return '"'
if obj.group(0) == '"':
return '\''
if obj.group(0) == '"""':
@nicelifeBS
nicelifeBS / README.md
Created December 19, 2017 20:11 — forked from mottosso/README.md
Minimal QML SceneGraph

untitled

Usage

python main.py --amount 100
  • Panning by left-click + drag
  • Scale by rotating the mouse wheel
@nicelifeBS
nicelifeBS / k_eval_cel.py
Created November 3, 2017 00:42
Katana - Eval cel with python
prod = NodegraphAPI.GetGeometryProducer()
root = prod.getRootProducer()
cel = root.getAttribute('collections.test.cel').getValue()
node = NodegraphAPI.GetNode('CollectionCreate')
collector = Widget.CollectAndSelectInScenegraph(str(cel), '/root/world/geo')
result = collector.collectAndSelect(select=False, node=node)
@nicelifeBS
nicelifeBS / db_upload.py
Created June 25, 2017 10:06
dropbox: upload large files
f = open(file_path)
file_size = os.path.getsize(file_path)
CHUNK_SIZE = 4 * 1024 * 1024
if file_size <= CHUNK_SIZE:
print dbx.files_upload(f, dest_path)
else:
@nicelifeBS
nicelifeBS / teleparam.py
Created February 25, 2017 02:14
Katana: Create a teleparameter
def CreateTeleParam(parentParam, targetParam):
teleParam = parentParam.createChildString(
'%sTeleParam' % targetParam.getName(), '')
teleParam.setExpression('getParam("%s").param.getFullName()'
% targetParam.getFullName())
teleParam.setHintString(repr({'widget': 'teleparam'}))
@nicelifeBS
nicelifeBS / katana_layout_widgets.py
Created February 24, 2017 09:47
KATANA: How to layout widget like Katana does it
import UI4.FormMaster.PythonValuePolicy
# Create a node for which to create parameter widgets
node = NodegraphAPI.CreateNode('Alembic_In', NodegraphAPI.GetRootNode())
# Get a couple of parameters from the node
addForceExpandParameter = node.getParameter('addForceExpand')
addBoundsParameter = node.getParameter('addBounds')
fpsParameter = node.getParameter('fps')
@nicelifeBS
nicelifeBS / QItemDelegate.py
Created September 5, 2016 09:53
QItemDelegate and QAbstractListModel
import sip
sip.setapi('QVariant', 2)
from PyQt4 import QtCore, QtGui
class SpinBoxDelegate(QtGui.QItemDelegate):
def createEditor(self, parent, option, index):
editor = QtGui.QSpinBox(parent)
editor.setMinimumHeight(100)
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
from PyQt4 import QtCore, QtGui
class TableModel(QtCore.QAbstractTableModel):
"""
A simple 5x4 table model to demonstrate the delegates
@nicelifeBS
nicelifeBS / channelRead.py
Created July 28, 2016 17:23
modo channel reading API
# @author David Ballesteros
#
# @brief Helper classes to deal with the read and write of Item Channels.
# Based on a ChannelRead class sample code provided by Matt Cox
import lx
class ChannelRead:
def __init__(self, item):
"""