Skip to content

Instantly share code, notes, and snippets.

View mathandy's full-sized avatar

Andrew Port mathandy

View GitHub Profile
@mathandy
mathandy / draw-grid-lines-on-image.py
Last active November 11, 2023 10:53
Use OpenCV to draw grid lines on an image.
"""Draw grid lines on an image.
Usage:
# To draw a 3x4 grid on an image
$ python draw_grid_lines.py <path/to/image> <num_rows> <num_cols> -o <output/dir-or-path>
$ python draw_grid_lines.py image.png 3 4 -o output.png
# for more options, see
$ python draw_grid_lines.py --help
@mathandy
mathandy / mic_listener.py
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
mathandy / determine-if-svg-path-is-contained-in-other-path-example.py
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
mathandy / flash.sh
Last active August 11, 2021 04:15
script to make terminal flash until any key is pressed (works inside tmux also)
#!/bin/bash
# script to make terminal flash until any key is pressed
# credit:
# https://stackoverflow.com/questions/25532773/change-background-color-of-active-or-inactive-pane-in-tmux/33553372#33553372
# https://stackoverflow.com/questions/32009787/bash-how-can-the-terminal-be-set-to-flash
# https://stackoverflow.com/questions/5297638/bash-how-to-end-infinite-loop-with-any-key-pressed
# 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
mathandy / dominion.py
Last active February 6, 2021 07:57
Parses Dominion (dominion.games) log to get decks.
"""Parses Dominion (dominion.games) 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
mathandy / retrain.py
Created May 5, 2020 03:11
A copy of TensorFlow's retrain.py 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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
mathandy / roi_pooling
Created May 9, 2019 02:04
Implementation of RoI Pooling from tutorial @ https://medium.com/xplore-ai/992508b6592b
"""Implementation of RoI Pooling
Credit: This is from tutorial available at
https://medium.com/xplore-ai/992508b6592b
"""
import tensorflow as tf
from tensorflow.keras.layers import Layer