Skip to content

Instantly share code, notes, and snippets.

View adammichaelwood's full-sized avatar
🦄
Flying with unicorns.

Adam Michael Wood adammichaelwood

🦄
Flying with unicorns.
View GitHub Profile
@adammichaelwood
adammichaelwood / distance_calculator.py
Created September 22, 2020 18:56
Distance Calculator
import math
def distance_calculator(points):
""" Takes an ordered list of points (tuple), and returns the total path distance.
>>> points = [(-7,-3), (6,1), (4, 10), (2, -5), (-8, 5), (8, 3)]
>>> distance = distance_calculator(points)
>>> distance = round(distance, 2)
68.22
"""
@adammichaelwood
adammichaelwood / music21_helpers.py
Created September 11, 2019 15:23
music21 helpers
import music21 as m
import copy
# replace x.show('midi') with play(x)
# to solve problem of first note(s) not playing
# in many web browsers
def play(x):
"""Returns nothing. Outputs a midi realization of x, a note or stream.
Primarily for use in notebooks and web environments.
;;; amw_init --- Summary
;; My shit.
;;; Commentary:
;; This is all my things.
;;; Code:
(package-initialize)
(elpy-enable)
@adammichaelwood
adammichaelwood / amw_input.py
Created January 11, 2018 05:10
Better Input
import re
class AMW_input():
def __init__(
self, prompt, typ, constraint, constraint_msg,
default, feedback=None, before=lambda x: x.strip(), after=None
):
self.prompt = prompt
self.typ = typ
@adammichaelwood
adammichaelwood / add-exts.py
Created October 9, 2017 21:59
Adds image filename extensions to Sphinx image directives that previously used the wildcard syntax
import os, re
# make a dict of names:extensions
img_exts = dict()
for _,_,f in os.walk("img"):
for name in f:
n, x = name.split(".")
img_exts[n] = x
import sys
import google
import time
import random
from bs4 import BeautifulSoup
import urllib.request
import http.cookiejar
from selenium import webdriver
import subprocess
import blessings
@adammichaelwood
adammichaelwood / bash_profile
Created August 9, 2016 13:34
My bash profile. Work in progress.
export PATH=$PATH:~/bin
export PATH=/usr/local/bin:$PATH
alias rm='rm -i'
alias reset='source ~/.bash_profile'
md () { touch "$1.md" && atom "$1.md" ;}
trash () { command mv "$@" ~/.Trash ; }
gdir () { mkdir -p "$1" && echo "# $1" >> "$1/readme.md" ; }
import blessings
import time
import random
t = blessings.Terminal()
name = input(t.yellow("What is your name? "))
aff_prefix = "I, " + name + ", "