Skip to content

Instantly share code, notes, and snippets.

John Stowers nzjrs

Block or report user

Report or block nzjrs

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nzjrs
nzjrs / Makefile
Created May 25, 2011
Python ctypes example
View Makefile
all: test libtest.so testmodule
libtest.so: libtest.c
$(CC) -Wall -g -fPIC -shared -o $@ $? -lc
test: test_main.c libtest.o
$(CC) -o $@ $?
testmodule: testmodule.c
python setup.py build
@nzjrs
nzjrs / datedifference.py
Created Oct 11, 2009
Humanize date differences
View datedifference.py
#!/usr/bin/env python
# This function prints the difference between two python datetime objects
# in a more human readable form
#
# Adapted from: http://www.chimeric.de/blog/2008/0711_smart_dates_in_python
def humanize_date_difference(now, otherdate=None, offset=None):
if otherdate:
dt = otherdate - now
offset = dt.seconds + (dt.days * 60*60*24)
@nzjrs
nzjrs / gdk-gstappsrc-stream.c
Created Dec 2, 2010
GStreamer Streaming AppSrc Example
View gdk-gstappsrc-stream.c
/* gcc gdk-gstappsrc-stream.c -Wall `pkg-config --cflags --libs gstreamer-app-0.10 gdk-pixbuf-2.0` -o gdkstream */
#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
@nzjrs
nzjrs / skype-notify.py
Created Jun 3, 2011
Python script to make Skype co-operate with GNOME3 notifications
View skype-notify.py
#!/usr/bin/env python
# Python script to make Skype co-operate with GNOME3 notifications.
#
#
# Copyright (c) 2011, John Stowers
#
# Adapted from skype-notify.py
# Copyright (c) 2009, Lightbreeze
#
#
@nzjrs
nzjrs / rospy_logging.py
Created Jan 30, 2014
Reconnect python logging calls with the ROS logging system
View rospy_logging.py
class ConnectPythonLoggingToROS(logging.Handler):
MAP = {
logging.DEBUG:rospy.logdebug,
logging.INFO:rospy.loginfo,
logging.WARNING:rospy.logwarn,
logging.ERROR:rospy.logerr,
logging.CRITICAL:rospy.logfatal
}
@nzjrs
nzjrs / fix-update-copyright-headers.py
Created Oct 13, 2009
Update or add copyright headers to source files.
View fix-update-copyright-headers.py
@nzjrs
nzjrs / mtu.py
Created Feb 11, 2014
Get and set the MTU for an interface
View mtu.py
import re
import socket
import struct
import logging
import subprocess
from fcntl import ioctl
SIOCGIFMTU = 0x8921
SIOCSIFMTU = 0x8922
@nzjrs
nzjrs / FooThread.py
Created Jan 25, 2009
PyGtk threading example
View FooThread.py
# Demo application showing how once can combine the python
# threading module with GObject signals to make a simple thread
# manager class which can be used to stop horrible blocking GUIs.
#
# (c) 2008, John Stowers <john.stowers@gmail.com>
#
# This program serves as an example, and can be freely used, copied, derived
# and redistributed by anyone. No warranty is implied or given.
import gtk
import gobject
@nzjrs
nzjrs / .gitmodules
Created Mar 29, 2012
University of Canterbury Thesis Template
View .gitmodules
[submodule "documents/latex-makefile"]
path = documents/latex-makefile
url = git://gist.github.com/503886.git
View dict_diff.py
def dict_diff1(first, second, NO_KEY='<KEYNOTFOUND>'):
""" Return a dict of keys that differ with another config object. If a value is
not found in one fo the configs, it will be represented by NO_KEY.
@param first: Fist dictionary to diff.
@param second: Second dicationary to diff.
@return diff: Dict of Key => (first.val, second.val)
"""
diff = {}
# Check all keys in first dict
for key in first.keys():
You can’t perform that action at this time.