Skip to content

Instantly share code, notes, and snippets.

View nzjrs's full-sized avatar

John nzjrs

View GitHub Profile
@nzjrs
nzjrs / dotdict.py
Created September 7, 2011 03:12
Namespaced foo.bar.baz dict wrapper
import UserDict
class DotDict(UserDict.IterableUserDict):
def __init__(self):
UserDict.IterableUserDict.__init__(self)
def __setitem__(self, key, val):
bits = key.split(".")
if bits[0] not in self.data:
@nzjrs
nzjrs / Makefile
Created February 11, 2012 23:12
Testing ORC - The Oil Runtime Compiler
all: testc testorc
clean:
rm -f testc testorc out.c out.h
testc: out.c test.c
$(CC) -DDISABLE_ORC=1 -o $@ $^
testorc: out.c test.c
$(CC) -o $@ $^ `pkg-config --cflags --libs orc-0.4`
@nzjrs
nzjrs / .gitmodules
Created March 29, 2012 05:00
University of Canterbury Thesis Template
[submodule "documents/latex-makefile"]
path = documents/latex-makefile
url = git://gist.github.com/503886.git
@nzjrs
nzjrs / caironumpy.py
Last active October 10, 2016 04:04
Mixing Cairo, Gtk, and numpy
# http://stackoverflow.com/a/10031877
import numpy
import cairo
import math
from gi.repository import Gtk,Gdk
data = numpy.zeros((200, 200, 4), dtype=numpy.uint8)
surface = cairo.ImageSurface.create_for_data(
@nzjrs
nzjrs / denumpy.py
Created September 19, 2012 16:48
Recursively convert dicts containg np types into primitive equivs
import numpy as np
def fix(d):
#d = d.copy()
for k,v in d.items():
if type(v) == dict:
d[k] = fix(v)
elif isinstance(v,np.floating):
d[k] = float(v)
elif isinstance(v,np.integer):
@nzjrs
nzjrs / bomb.py
Created September 28, 2012 09:37
Macgyver Bomb
import threading
import time
import serial
from gi.repository import Gtk, Gdk, GObject
GObject.threads_init()
Gdk.threads_init()
@nzjrs
nzjrs / gtkmodebutton.py
Last active December 11, 2015 20:59
A PyGObject / GTK implementation of a ModeButton / ModeButtonBox
from gi.repository import Gtk
class _ButtonBoxMixin(object):
def add(self, widget):
self.pack_start(widget)
def pack_start(self, widget, *args, **kwargs):
if type(widget) is Gtk.RadioButton:
widget.props.draw_indicator = False
@nzjrs
nzjrs / gtkcolorbutton.py
Created February 24, 2013 12:15
A PyGObject / GTK implementation of a solid color GtkButton
import numpy
import cairo
from math import pi
from gi.repository import Gtk,Gdk
def draw_rounded(cr, area, radius):
a,b,c,d=area
cr.arc(a + radius, c + radius, radius, 2*(pi/2), 3*(pi/2))
cr.arc(b - radius, c + radius, radius, 3*(pi/2), 4*(pi/2))
@nzjrs
nzjrs / detect.py
Last active December 16, 2015 19:08
Python Point Detect
import cv2
import numpy as np
import scipy.ndimage.measurements
cv2.startWindowThread()
for iname,t in (("img",45),("img2",230), ("img3",230), ("img4",250)):
i = cv2.imread("%s.png" % iname)
cv2.namedWindow(iname)
@nzjrs
nzjrs / exp.sh
Created July 19, 2013 11:30
Gstreamer x264 Experiments
gst-launch-0.10 videotestsrc ! video/x-raw-yuv,format=\(fourcc\)I420,width=640,height=480,framerate=25/1 ! x264enc byte-stream=true ! filesink location=foo.mp4