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 / 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 / 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
# 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 / 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,