Skip to content

Instantly share code, notes, and snippets.

@tgarc
tgarc / plot_interactive.py
Created February 18, 2015 18:42
Barebones manual animations in matplotlib
"""
Using matplotlib for manually creating animations. Works similar to FuncAnimation. Manual animation is a bit simpler than using the animations API in general since it is still capable of handling some events (like window resizing) automatically.
"""
import matplotlib.pyplot as plt
import numpy as np
# Create a figure and axis for plotting on
@tgarc
tgarc / goldensearch.py
Created February 27, 2015 21:59
Golden section search for finding the minimum of a function
# Example usage
# f = lambda x: 3*(x**2)+4*x+ 5
# xhat = findmin(f,-3,2)
from scipy.constants import golden
def goldensearch(f,a,b,tol=1e-6):
xl = b - (b-a)/golden
xu = a + (b-a)/golden
@tgarc
tgarc / opencv_cygwin
Last active August 29, 2015 14:16
Compiling opencv 2.4.10 for cygwin with ffmpeg 2.5.3
# download the opencv-2.4.10 for unix
# unzip the library to some temporary folder; let's say it's ~/opencv
# see http://hvrl.ics.keio.ac.jp/kimura/opencv/opencv-2.4.10.html
# for build patch
#build ffmpeg
$ cd /tmp/
$ tar xvjf ffmpeg-2.5.3.tar.bz2
$ cd ffmpeg-2.5.3/
$ ./configure --disable-yasm --disable-iconv
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# A short tutorial on pandas MultiIndexing with DataFrames"
]
},
{
@tgarc
tgarc / libusb1.spec
Created December 15, 2015 23:04
libusb1.0.20.spec file for building RPM
# Modified version of libusb1.spec from libusb1-1.0.9-0.6.rc1.el6.rpm
# to create an RPM package for libusb-1.0.20
Summary: A library which allows userspace access to USB devices
Name: libusb1
Version: 1.0.20
Release: 0
Source0: libusb-1.0.20.tar.bz2
#Source0: http://downloads.sourceforge.net/libusb/libusb-%{version}.tar.bz2
License: LGPLv2+
@tgarc
tgarc / parse_fspec.py
Last active July 21, 2016 15:50
Parse the format specification (https://docs.python.org/2.7/library/string.html#format-specification-mini-language) from a .format style python string
import re
from string import Formatter
_fspecre = ("((?P<fill>{fill})?(?P<align>{align}))?"
"(?P<sign>{sign})?"
"(?P<prefix>#)?"
"(?P<zeropad>0)?"
"(?P<width>{width})?"
"(?P<thousands>,)?"
"(?:\.(?P<precision>{precision}))?"
@tgarc
tgarc / win.patch
Last active September 16, 2016 06:23
updated patch for compiling pyaudio for windows with msvc
diff --git a/setup.py b/setup.py
index cccebeb..1472d06 100755
--- a/setup.py
+++ b/setup.py
@@ -79,7 +79,9 @@ if not STATIC_LINKING:
else:
include_dirs = [os.path.join(portaudio_path, 'include/')]
extra_link_args = [
- os.path.join(portaudio_path, 'lib/.libs/libportaudio.a')
+ os.path.join(portaudio_path, 'portaudio_static_x64.lib')
@tgarc
tgarc / mpex.py
Last active November 18, 2016 00:09
Multiprocessing example: feeding a low rate I/O stream
"""
Example of keeping a simulated IO callback thread fed using separate master and daemon (I/O) processes.
"""
import multiprocessing, threading, Queue
import time
import sys
import urllib2
IOBLOCKSZ = 4096 # made up IO block size
IPCBLOCKSZ = 8192 # a size that is guaranteed to be larger than BLOCK_SZ
@tgarc
tgarc / ioproc.py
Last active November 28, 2016 02:14
Extension of mpex.py: Keep the io process alive so that multiple file may be sent
"""
Example of keeping a simulated IO callback thread fed using separate master and daemon (I/O) processes.
Builds off of mpex.py: https://gist.github.com/tgarc/7120c00eb3eb5f736be93c70ade1d68a
"""
import multiprocessing, threading, Queue
import time
import sys
import urllib2
@tgarc
tgarc / padaemon.py
Last active December 1, 2016 06:50
daemon for portaudio
#!/usr/bin/env python2
"""
Daemon for full duplex streaming with PyAudio
Note that recordings are always delayed by some amount and are therefore longer than the input file
Builds off of mpex.py: https://gist.github.com/tgarc/7120c00eb3eb5f736be93c70ade1d68a
"""
import multiprocessing, threading, Queue
import time