Skip to content

Instantly share code, notes, and snippets.

Avatar

Douglas Duhaime duhaime

View GitHub Profile
@duhaime
duhaime / client.py
Last active Oct 20, 2021
Communication between supercollider and python via osc. Just run `python osc_music.py` and the `supercollider_music`
View client.py
import time
import socket
for pings in range(10):
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client_socket.settimeout(1.0)
message = b'test'
addr = ("127.0.0.1", 12000)
start = time.time()
View get_dbpedia_people.py
from SPARQLWrapper import SPARQLWrapper, JSON
import html, datetime, os, json, glob, time
def send_sparql_query(q, timeout=None, sleep=0):
time.sleep(sleep)
try:
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setReturnFormat(JSON)
if timeout: sparql.setTimeout(timeout)
sparql.setQuery(q)
View functions.py
from fractions import Fraction
import music21
import glob
# remove leading / trailing whitespace
music21.defaults.ticksAtStart = 0
notes = set([12*j + i for i in [0,2,4,5,7,9,11] for j in [0,1,2,3,4,5,6,7,8,9,10] ])
def constrain_pitch(val):
View get_wiki_people.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View chopin.txt
This file has been truncated, but you can view the full file.
View gist:aa132323aca8aa50587331267def162d
from SPARQLWrapper import SPARQLWrapper, JSON
from collections import defaultdict
from bs4 import BeautifulSoup
import numpy as np
import json, os, glob, subprocess, string
import nltk, codecs, re, shutil, sys
##################################################
# Wrapper to find nested location of stored data #
##################################################
@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))
@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)