Skip to content

Instantly share code, notes, and snippets.

View nzjrs's full-sized avatar

John nzjrs

View GitHub Profile
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 October 28, 2014 10:48
Non-table based implementations of crc16 and crc8-maxim
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 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 / 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 / timestamp.py
Last active December 26, 2015 00:59 — forked from ju-popov/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 October 5, 2013 19:19
Timed background changer for gnome
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 December 21, 2015 07:08
Lame virtualenv / jhbuild clone
#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 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 / 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
@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)