Skip to content

Instantly share code, notes, and snippets.

View mathandy's full-sized avatar

Andrew Port mathandy

View GitHub Profile
mathandy /
Created August 5, 2018 07:59
A real-time analog to midi converter
"""A real-time analog to midi converter.
Listens to you system's microphone and does its best to convert the
sounds it hears to a sequence of musical notes. It works ok... play
with the sampling settings to get results that fit your needs.
Usage Example:
>>> from mic_listen import list_devices, MicListener
>>> list_devices() # to list system devices
mathandy /
Last active November 11, 2023 10:53
Use OpenCV to draw grid lines on an image.
"""Draw grid lines on an image.
# To draw a 3x4 grid on an image
$ python <path/to/image> <num_rows> <num_cols> -o <output/dir-or-path>
$ python image.png 3 4 -o output.png
# for more options, see
$ python --help
mathandy /
Created December 10, 2016 04:07
An example of how to determine if an SVG Path is contained in another SVG Path in Python.
An example of how to determine if an svg path is contained in another
svg path in Python.
Note: for discontinuous paths you can use the svgpathtools
Path.continuous_subpaths() method to split a paths into a list of its
continuous subpaths.
from svgpathtools import *
#!/usr/bin/env python3
import tensorflow as tf
import pathlib
data_dir = pathlib.Path.home() / 'datasets' / 'dogs-v-cats' / 'train'
# data_dir = pathlib.Path.home() / 'datasets' / '10flowers' / 'images'
batch_size = 32
img_height = 224
img_width = 224
mathandy /
Last active August 11, 2021 04:15
script to make terminal flash until any key is pressed (works inside tmux also)
# script to make terminal flash until any key is pressed
# credit:
# check if tmux version is < 2.1
tmux_is_old=$(awk -v n1="$(tmux -V| cut -d' ' -f2)" -v n2="2.1" 'BEGIN {printf (n1<n2?"1":"0")}')
mathandy /
Last active February 6, 2021 07:57
Parses Dominion ( log to get decks.
"""Parses Dominion ( log to get decks.
To use: create text file in your Downloads folder called "log.txt"
and copy/paste the log into that file. Then run this script with python.
from collections import deque
import re
from pathlib import Path
firstname = input("What is your first name? ")
lastname = input("What is your last name? ")
fullname = firstname + " " + lastname
age = int(input("What is your age? "))
address = input("What is your address? ")
print("Hi {}.".format(fullname))
print("Your address is {}.".format(address))
if age >= 18:
mathandy /
Created May 5, 2020 03:11
A copy of TensorFlow's for use in Nick's bug classifier Colab
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# probably about right
def variance(samples):
mean = sum(samples) / len(samples)
return sum((x - mean)**2 for x in samples) / len(samples)
# probably too short
def var(s):
m = sum(s) / len(s)
return sum((x - m)**2 for x in s) / len(s)
mathandy / roi_pooling
Created May 9, 2019 02:04
Implementation of RoI Pooling from tutorial @
"""Implementation of RoI Pooling
Credit: This is from tutorial available at
import tensorflow as tf
from tensorflow.keras.layers import Layer