Skip to content

Instantly share code, notes, and snippets.

View nzjrs's full-sized avatar

John nzjrs

View GitHub Profile
@nzjrs
nzjrs / gdk-gstappsrc-stream.c
Created December 2, 2010 10:47
GStreamer Streaming AppSrc Example
/* 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 / datedifference.py
Created October 11, 2009 11:38
Humanize date differences
#!/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 / rospy_logging.py
Created January 30, 2014 16:06
Reconnect python logging calls with the ROS logging system
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 / driveGnuPlotStreams.pl
Created July 28, 2013 17:30
Plotting data with gnuplot in real-time
#!/usr/bin/perl -w
#Salvaged from archive.org
#http://web.archive.org/web/20100309204315/http://www.lysium.de/blog/index.php?/archives/234-Plotting-data-with-gnuplot-in-real-time.html
#The input (on stdin or from a file) looks like this, as for the original version:
#0:0.09983
#1:0.99500
#2:0.69314
@nzjrs
nzjrs / Makefile
Created May 25, 2011 07:09
Python ctypes example
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 / mtu.py
Created February 11, 2014 13:32
Get and set the MTU for an interface
import re
import socket
import struct
import logging
import subprocess
from fcntl import ioctl
SIOCGIFMTU = 0x8921
SIOCSIFMTU = 0x8922
@nzjrs
nzjrs / FooThread.py
Created January 25, 2009 04:43
PyGtk threading example
# 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 / Makefile
Last active May 20, 2020 21:12
LaTeX Makefile
# Makefile for LaTeX files
# Original file from http://www.acoustics.hut.fi/u/mairas/UltimateLatexMakefile
# please check http://www.takeonthecity.nl/roels-latex-makefile/ (Roel)
# current version http://gist.github.com/503886 (John)
# Copyright (c) 2009,2010 (in order of appearance):
# Roel Meeuws <r.j.meeuws@gmail.com>
# John Stowers <john.stowers@gmail.com>
# ChangeLog:
@nzjrs
nzjrs / curses-demo.py
Created August 8, 2009 03:26
Helper for using curses from python
#!/usr/bin/env python
# This module provides a 'with' for using curses in Python.
# from: http://www.finalcog.com/python-with-curses-with_curses
from __future__ import with_statement
import curses
class WithCurses(object):
"""
@nzjrs
nzjrs / skype-notify.py
Created June 3, 2011 13:14
Python script to make Skype co-operate with GNOME3 notifications
#!/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
#
#