Skip to content

Instantly share code, notes, and snippets.

John Stowers nzjrs

View GitHub Profile
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():
@nzjrs
nzjrs / test_crc.py
Created Oct 28, 2014
Non-table based implementations of crc16 and crc8-maxim
View test_crc.py
import crcmod.predefined
def _crc16(crc, c):
crc ^= ord(c)
for i in range(8):
if crc & 0x1:
crc = (crc >> 1) ^ 0xA001
else:
crc = (crc >> 1)
return crc
@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 / 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
}
View timestamp.py
##
## http://emilics.com/blog/article/python_time.html
## http://www.saltycrane.com/blog/2008/11/python-datetime-time-conversions/
######################################################################
# CURRENT AWARE LOCAL DATETIME
######################################################################
from datetime import datetime
@nzjrs
nzjrs / changer.py
Created Oct 5, 2013
Timed background changer for gnome
View changer.py
import argparse
import random
import glob
import os.path
import time
from gi.repository import Gio
class Changer:
def __init__(self, directory, interval):
self._pics = glob.glob(os.path.join(directory,"*.jpg"))
@nzjrs
nzjrs / env.sh
Last active Dec 21, 2015
Lame virtualenv / jhbuild clone
View env.sh
#get the current directory. from
#http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
pushd . > /dev/null
DIR="${BASH_SOURCE[0]}";
if ([ -h "${DIR}" ]) then
while([ -h "${DIR}" ]) do cd `dirname "$DIR"`; DIR=`readlink "${DIR}"`; done
fi
cd `dirname ${DIR}` > /dev/null
DIR=`pwd`;
popd > /dev/null
@nzjrs
nzjrs / driveGnuPlotStreams.pl
Created Jul 28, 2013
Plotting data with gnuplot in real-time
View driveGnuPlotStreams.pl
#!/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 / exp.sh
Created Jul 19, 2013
Gstreamer x264 Experiments
View exp.sh
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
@nzjrs
nzjrs / detect.py
Last active Dec 16, 2015
Python Point Detect
View detect.py
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)
You can’t perform that action at this time.