Skip to content

Instantly share code, notes, and snippets.

@tgarc
tgarc / Makefile
Created February 17, 2023 15:07
C++ Makefile template
# Thanks to Job Vranish (https://spin.atomicobject.com/2016/08/26/makefile-c-projects/)
TARGET_EXEC := a
BUILD ?= release
BUILD_DIR ?= ./build
SRC_DIRS ?= ./src
CC ?= gcc
CXX ?= g++
@tgarc
tgarc / startup.py
Last active August 22, 2023 15:52
Launch ipython terminal magic
'''
Adds %ipython magic command to launch a bash terminal and connect to the current jupyter session because coding in jupyter sucks.
To be placed in ~/.ipython/profile_default/startup/
'''
import os, sys
import ipykernel
from IPython.core.magic import register_line_magic
@register_line_magic
def ipython(line):
@tgarc
tgarc / merge_load.py
Last active April 28, 2017 00:21
Load a yaml stream (src) and merge it with another yaml stream (dst) allowing *dst* to use aliases defined in *src*.
import sys
import yaml
def merge_load(src, dst, loadfunc=yaml.load, **kwargs):
'''\
Load a yaml stream (src) and merge it with another yaml stream
(dst) allowing *dst* to use aliases defined in *src*.
Other Parameters
----------------
@tgarc
tgarc / mask2runs.py
Last active November 6, 2018 17:57
find runs of constant value, returning their indices
import numpy as np
def mask2runs(mask):
'''
mask2runs
Turns a boolean array into an array of indices indicating the start and end indices of each run of 1's.
'''
runflip = np.nonzero(mask[1:] ^ mask[:-1])[0]+1
runflip[1::2] -= 1 # Note that the prior step returns end indices as the end of a run plus 1
@tgarc
tgarc / findfile.py
Created February 2, 2017 21:06
python file finder
import os
import glob
import errno
try:
from itertools import ifilter as filter
except ImportError:
pass
def findfile(filepath, find_all, search_path='', recursive=False, allowglob=False, rel_path='.', follow_links=False):
filelist = []
@tgarc
tgarc / .asoundrc
Last active February 5, 2017 21:38
portaudio/libsndfile for half and full duplex audio streaming
# sets up a full duplex alsa loopback device
pcm.loophw00 {
type hw
card Loopback
device 0
subdevice 0
format S32_LE
rate 48000
channels 8
}
@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
@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 / 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 / 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')