Skip to content

Instantly share code, notes, and snippets.

Avatar

Douglas Duhaime duhaime

View GitHub Profile
@duhaime
duhaime / phyllotaxis.py
Created Jul 21, 2021
Phyllotaxis in Python
View phyllotaxis.py
%matplotlib inline
from math import cos, sin, sqrt, pi
import numpy as np
import matplotlib.pyplot as plt
# golden angle definition
ga = 360/((1+sqrt(5))/2)**2
# initialize random array
a = np.zeros((1000, 2))
View links.txt
@duhaime
duhaime / imagenet1000_clsidx_to_labels.txt
Created Apr 7, 2021 — forked from yrevar/imagenet1000_clsidx_to_labels.txt
text: imagenet 1000 class idx to human readable labels (Fox, E., & Guestrin, C. (n.d.). Coursera Machine Learning Specialization.)
View imagenet1000_clsidx_to_labels.txt
{0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
9: 'ostrich, Struthio camelus',
@duhaime
duhaime / ingest_epo.py
Created Feb 20, 2021
Ingest EPO SQL data
View ingest_epo.py
import itertools
import argparse
import MySQLdb
import json
import glob
import os
# for usage run `python ingest_epo.py -h`
defaults = {
View turing.py
from machine import Pin
import serial
# serial: https://pythonhosted.org/pyserial/pyserial.html#overview
# create an output pin on pin #8
out_pin = Pin(8, Pin.OUT)
# set the output pin to high mode
out_pin.value(1)
@duhaime
duhaime / stream_in.py
Created Jul 16, 2020
Mido port streaming
View stream_in.py
import mido
with mido.open_input('mido_port', virtual=True) as in_port:
for msg in in_port:
print(msg)
View boids.py
# -----------------------------------------------------------------------------
# From Numpy to Python
# Copyright (2017) Nicolas P. Rougier - BSD license
# More information at https://github.com/rougier/numpy-book
# -----------------------------------------------------------------------------
from matplotlib.animation import FuncAnimation
from collections import namedtuple
import matplotlib.pyplot as plt
import numpy as np
import random
@duhaime
duhaime / flask-app.py
Created May 29, 2020
Flask and Starlette Servers for GPT-2
View flask-app.py
from flask import Flask, jsonify, request
import gpt_2_simple as gpt2
import tensorflow as tf
import os
if not os.path.exists('checkpoint'):
os.makedirs(os.path.join('checkpoint', 'run1'))
gpt2.download_gpt2(model_name='117M')
os.system('mv models/117M/* checkpoint/run1/')
View fetch_reddit_pushshift.py
from dateutil.relativedelta import relativedelta
from datetime import date, datetime
import json
import requests
import calendar
import time
import sys
end = date.today()
start = end - relativedelta(years=3)
@duhaime
duhaime / play.py
Last active May 23, 2020
play midi file
View play.py
# conda install -c cogsci pygame
import pygame, base64
def midi_to_base64(midi_filename):
return base64.encodestring(open(midi_filename, 'rb').read())
def play_music(midi_filename):
'''Stream music_file in a blocking manner'''
clock = pygame.time.Clock()
pygame.mixer.music.load(midi_filename)