Skip to content

Instantly share code, notes, and snippets.

View mathandy's full-sized avatar

Andrew Port mathandy

View GitHub Profile
@mathandy
mathandy / tool4c.py
Created October 5, 2016 22:17
Converts a color image to a matrix and 3-tensor and stores them as CSV files (by default scales image to thumbnail-size).
"""
Description:
Takes in a color image and creates a two CSV files storing downsized
matrix (grayscale) and 3-tensor representations of the image.
Instructions:
Put your image in the same folder as this file (tool4c.py),
then open a terminal in that folder and enter:
python tool4c <your_image>
@mathandy
mathandy / distance-between-two-svg-paths-example.py
Created December 10, 2016 03:57
An example of how to compute the distance between two svg path elements in Python with svgpathtools
from svgpathtools import *
# create some example paths
path1 = CubicBezier(1,2+3j,3-5j,4+1j)
path2 = path1.rotated(60).translated(3)
# find minimizer
from scipy.optimize import fminbound
def dist(t):
return path1.radialrange(path2.point(t))[0][0]
@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 *
@mathandy
mathandy / xfinity_att_debate.rst
Last active January 4, 2017 02:23
We're getting ripped off. No matter what, we need to do something about it.

A Fake Scientific Analysis of this Xfinity/AT&T bullshit

Abstract

We're getting ripped off. No matter what, we need to do something about it.

Introduction

@mathandy
mathandy / compute-many-points-quickly-using-numpy-arrays.py
Last active March 30, 2017 09:21
An svgpathtools example: computing many points quickly with and numpy arrays
"""The goal of this gist is to show how to compute many points on a path
quickly using NumPy arrays. I.e. there's a much faster way than using, say
[some_path.point(t) for t in many_tvals]. The example below assumes the
`Path` object is composed entirely of `CubicBezier` objects, but this can
easily be generalized to paths containing `Line` and `QuadraticBezier` objects
also.
Note: The relevant matrix transformation for quadratics can be found in the
svgpathtools.bezier module."""
import numpy as np
@mathandy
mathandy / define.py
Created June 6, 2017 04:02
Scrape the definition of a word (or phrase) from dictionary.com using Python
"""Scrape the definition of a word (or phrase) from dictionary.com
Usage:
======
python define.py onomatopoeia
Warning:
========
Sometimes (at least with phrases) you'll be unexpectedly redirected
to the definition of another only loosely related word,
@mathandy
mathandy / getpdfs.py
Last active February 14, 2018 03:04
Downloads (and renames by title) ArXiv papers linked to in a Google Doc converted to HTML.
"""Downloads ArXiv papers linked to in a Google Doc converted to HTML.
Notes:
------
* tested on OS X with Python 3
* Requires arxiv (`pip install arxiv`)
* Names of PDFs will be the papers' titles on ArXiv (with some
slight formatting changes).
"""
@mathandy
mathandy / build-tensorflow-from-source.md
Created July 26, 2018 01:12 — forked from Brainiarc7/build-tensorflow-from-source.md
Build Tensorflow from source, for better performance on Ubuntu.

Building Tensorflow from source on Ubuntu 16.04LTS for maximum performance:

TensorFlow is now distributed under an Apache v2 open source license on GitHub.

On Ubuntu 16.04LTS+:

Step 1. Install NVIDIA CUDA:

To use TensorFlow with NVIDIA GPUs, the first step is to install the CUDA Toolkit as shown:

@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 / 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