Skip to content

Instantly share code, notes, and snippets.

View SpotlightKid's full-sized avatar

Christopher Arndt SpotlightKid

View GitHub Profile
@SpotlightKid
SpotlightKid / timebase.py
Last active November 8, 2019 01:32
Query and manipulate JACK transport state and provide timebase information using jackclient-python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# timebase.py
#
"""A simple JACK timebase master."""
import argparse
import sys
import time
@SpotlightKid
SpotlightKid / alsa-query.c
Created April 29, 2019 15:49
Print hardware capabilities of ALSA device
/*
* alsa-query.c - print hardware capabilities of ALSA device
*
* compile with: gcc -o alsa-query alsa-query.c -lasound
*/
#include <stdio.h>
#include <alsa/asoundlib.h>
#define ARRAY_SIZE(a) (sizeof(a) / sizeof *(a))
@SpotlightKid
SpotlightKid / graph.py
Created March 19, 2019 18:43
Modelling source file dependencies with a graph in Python
# -*- coding: utf-8 -*-
"""A very basic general graph library."""
from __future__ import print_function
__all__ = ('Edge', 'Graph', 'Node')
import uuid
@SpotlightKid
SpotlightKid / gh-get.py
Created October 19, 2018 15:09
Download a single file from a GitHub repository
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# gh-get.py
#
"""Download a single file from a GitHub repository."""
import shutil
from os.path import expanduser
@SpotlightKid
SpotlightKid / urlparse.py
Last active September 24, 2018 18:38
Reduced urllib.parse_qsl implementation for MicroPython
# -*- coding: utf-8 -*-
def parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
encoding='utf-8', errors='replace'):
"""Parse a query given as a string argument.
Arguments:
qs: percent-encoded query string to be parsed. May be a unicode
string or a UTF-8 encoded byte-string.
@SpotlightKid
SpotlightKid / sendmail-smtp.py
Last active October 4, 2019 09:29
Simple command line mailer
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Simple command line mailer.
Send text-only email via SMTP with message text read from stdin to all email addresses given as
arguments.
"""
import sys
@SpotlightKid
SpotlightKid / example_program_change_map.py
Last active April 11, 2024 14:00
Change program number of MIDI Program Change events according to given mapping
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Example script which maps program change numbers."""
from miditk.smf import MidiFileReader, MidiFileWriter
class ProgramChangeMapper(MidiFileWriter):
"""Change program number of Program Change events according to given mapping."""
@SpotlightKid
SpotlightKid / file2h.py
Last active August 5, 2018 14:48
Convert a file to a C char array representation. Outputs a C header on standard output.
#!/usr/bin/env python
"""Convert a file to a C char array representation.
Outputs a C header on standard output.
"""
from sys import argv, exit, stdout
from os.path import basename, isfile
@SpotlightKid
SpotlightKid / debounce.py
Last active December 23, 2024 20:17
Debounced switch using pin and timer IRQs on MicroPython
#
# inspired by: https://forum.micropython.org/viewtopic.php?t=1938#p10931
#
import micropython
try:
from machine import Timer
timer_init = lambda t, p, cb: t.init(period=p, callback=cb)
except ImportError:
from pyb import Timer
@SpotlightKid
SpotlightKid / pipe.py
Last active December 12, 2017 00:44
Handy utility function to get output of shell command piping input to stdin (requires Python 3.5+).
>>> pipe('md5sum', 'This is a test')
--> 'ce114e4501d2f4e2dcea3e17b546f339 -\n'
>>> pipe('md5sum', b'This is a test')
--> b'ce114e4501d2f4e2dcea3e17b546f339 -\n'
>>> pipe(['gzip', '-c'], b'This is a test')
b'\x1f\x8b\x08\x00\xd6\x91\x13Z\x00\x03\x0b\xc9\xc8,V\x00\xa2D\x85\x92\xd4\xe2\x12\x002\x9fz\xc0\x0e\x00\x00\x00'
>>> pipe('bash', 'ls').splitlines()