Skip to content

Instantly share code, notes, and snippets.

@TimSC
TimSC / image-to-v4l2loopback.py
Created September 12, 2013 02:00
Send image data to v4l2loopback using python. Remember to do "sudo modprobe v4l2loopback" first! Released under CC0 by Tim Sheerman-Chase, 2013
#Send image data to v4l2loopback using python
#Remember to do sudo modprobe v4l2loopback first!
#Released under CC0 by Tim Sheerman-Chase, 2013
import fcntl, sys, os
from v4l2 import *
import time
import scipy.misc as misc
import numpy as np
@TimSC
TimSC / mjpeg.py
Last active April 5, 2020 01:59
Python code to parse a JPEG structure and to convert Motion JPEG/MJPG binary data to standard JPEG. This code may be used under CC0.
import struct
huffmanSegment = '\xFF\xC4\x01\xA2\x00\x00\x01\x05\x01\x01\x01\x01'\
'\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02'\
'\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x01\x00\x03'\
'\x01\x01\x01\x01\x01\x01\x01\x01\x01\x00\x00\x00'\
'\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09'\
'\x0A\x0B\x10\x00\x02\x01\x03\x03\x02\x04\x03\x05'\
'\x05\x04\x04\x00\x00\x01\x7D\x01\x02\x03\x00\x04'\
@TimSC
TimSC / trim.py
Last active December 29, 2015 10:29
Extract a small area from an OSM file by Tim Sheerman-Chase, 2013. You may reuse this file under the terms of CC0 https://creativecommons.org/publicdomain/zero/1.0/
#Extract a small area from an OSM file
#by Tim Sheerman-Chase, 2013
#You may reuse this file under the terms of CC0
#https://creativecommons.org/publicdomain/zero/1.0/
import xml.parsers.expat as expat
import pickle, bz2
from xml.sax.saxutils import escape, quoteattr
@TimSC
TimSC / mjpegcli.py
Last active January 2, 2016 15:29
Demonstration of multipart/x-mixed-replace decoding to get MJPEG frames from web server
#Demonstration of multipart/x-mixed-replace decoding to get MJPEG frames from web server
#by Tim Sheerman-Chase 2014
#This code may be used under the terms of the CC0 license
#https://creativecommons.org/publicdomain/zero/1.0/
import pycurl
class HandleJpegData(object):
def __init__(self):
self.count = 0
@TimSC
TimSC / bz2recover.py
Created January 23, 2014 14:17
This program is bzip2recover.py, a program to parse and extract bz2 blocks. This may be used to salvage a damaged bz2 file. Ported from C to python.
import struct, sys, os
#-----------------------------------------------------------
#--- Block recoverer program for bzip2 --
#--- bzip2recover.py --
#-----------------------------------------------------------
# This program is bzip2recover, a program to attempt data
# salvage from damaged files.
@TimSC
TimSC / file-soak-test.cpp
Created May 2, 2014 22:05
This program does test reads and writes to a file.
//Reading and writing tests
//Release under CC0 by Tim Sheerman-Chase, 2014
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <list>
#include <iostream>
#include <string>
using namespace std;
@TimSC
TimSC / file-soak-test.py
Last active August 29, 2015 14:00
This script does test reads and writes to a file.
#This script does test reads and writes to a file.
#Release under CC0 by Tim Sheerman-Chase, 2014
#This script fails on my computer but not on others. Weird.
import random, time, pickle, sys
import numpy as np
def MultiRead(handle, maxLen):
buff = []
@TimSC
TimSC / primes.py
Last active August 29, 2015 14:00
Find prime numbers. Good for giving the CPU some exercise!
import random, math
def FindPrimes(lowLimit, highLimit):
cand = list(range(lowLimit, highLimit))
for i in range(2,lowLimit):
current = i * int(math.floor(lowLimit / i))
while current < highLimit:
if current in cand:
cand.remove(current)
@TimSC
TimSC / compare-folders.py
Created May 11, 2014 12:27
Recursively compare files in two folders
#Recursively compare files in two folders
#by Tim Sheerman-Chase, 2014
#Released under the CC0 license
import sys, os, hashlib
def CheckFolderPair(fo1, fo2, stats):
fiList1 = os.listdir(fo1)
for fina in fiList1:
@TimSC
TimSC / iir.cpp
Last active August 29, 2015 14:04
IIR Filtering
void NaiveIir(const vector<float> &b, const vector<float> &a, const vector<float> &in, vector<float> &out)
{
//IIR filtering, unoptimised
//Call like scipy's lfilter
//http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.lfilter.html
out.resize(0);
out.resize(in.size());
for(int i=0; i < in.size(); i++)