Skip to content

Instantly share code, notes, and snippets.

View stuarteberg's full-sized avatar

Stuart Berg stuarteberg

  • Ashburn, Virginia, USA
View GitHub Profile
@stuarteberg
stuarteberg / draggable_graphicsitem.py
Last active May 3, 2016 23:19
Draggable QGraphicsItem
from PyQt4.QtCore import Qt, QPointF, QRectF
from PyQt4.QtGui import QApplication, QWidget, QGraphicsView, QGraphicsScene, QGraphicsItem, QVBoxLayout, QSpacerItem, QSizePolicy, QCursor
class DraggableBox( QGraphicsItem ):
"""
A simple QGraphicsItem that can be dragged around the scene.
Of course, this behavior is easier to achieve if you simply use the default
event handler implementations in place and call
QGraphicsItem.setFlags( QGraphicsItem.ItemIsMovable )
@stuarteberg
stuarteberg / relabel_benchmarks.py
Last active December 21, 2015 10:49
Benchmarking alternate implementations for relabeling a label image with a mapping specified as a dict.
import numpy
original_labels = None
mapping = None
# TODO: Ensure that all labels are present in mapping dict
# because none of these functions work otherwise.
def using_index_array():
consecutivized_labels = numpy.searchsorted( sorted( mapping.iterkeys() ), original_labels )
@stuarteberg
stuarteberg / show-git-branch-in-bash-prompt
Last active October 10, 2021 17:55
Code for your .bashrc file. Show current git branch on bash shell prompt....with color! (This was copied and modified from similar code you can find out there on the 'tubes.)
# Colors for the prompt
blue="\033[0;34m"
white="\033[0;37m"
green="\033[0;32m"
# Brackets needed around non-printable characters in PS1
ps1_blue='\['"$blue"'\]'
ps1_green='\['"$green"'\]'
ps1_white='\['"$white"'\]'