Skip to content

Instantly share code, notes, and snippets.

View hughrawlinson's full-sized avatar

Hugh Rawlinson hughrawlinson

View GitHub Profile
@hughrawlinson
hughrawlinson / psk31.js
Last active September 21, 2016 14:45
An implementation of PSK31 encoding in Web Audio
const ENERGY_PER_BIT = 100;
const CARRIER_FREQUENCY = 440;
const PAYLOAD = 'Test Payload';
const getAsciiArrayFromChar = (character) => (character.charCodeAt(0) >>> 0).toString(2).split('');
// Parameter names come from the equation for BPSK here:
// https://en.m.wikipedia.org/wiki/Phase-shift_keying#Binary_phase-shift_keying_.28BPSK.29
const binaryPhaseShiftKeyingOscillator = (
// This may or may not help you understand what's going
// on in week one of the Stanford Machine Learning course
// particulary if you're coming from Javascript programming.
// The lecture deals with linear regression. You may remember
// a concept called "line of best fit" from middle school.
// A refresher: you have a set of points with x and y co-ordinates
// and you have to draw a straight line through them. It doesn't
// have to intersect all (or any) of the points, but it does need
// to represent the general layout of your dataset. The idea is
@hughrawlinson
hughrawlinson / microspotipy.py
Last active August 5, 2016 19:18
Spotipy for MicroPython
import http_client
import ujson
endpoint = 'https://api.spotify.com/v1'
def get(url):
print(url)
r = http_client.get(url)
r.raise_for_status()
return ujson.loads(r.text)
@hughrawlinson
hughrawlinson / importantIssues.sh
Created July 30, 2016 18:54
Get a list of important issues from a GitHub repo
#!/bin/bash
# A program to parse GitHub issues as a list sorted by engagement
HELP="Get a list of important issues from a GitHub repo
Usage: importantIssues.sh repo user [count sort]
repo: GitHub repo containing the issues
user: GitHub user/org containing the repo
count: Number of issues to return
sort: If defined will reverse sort by comment count + reactions count"
@hughrawlinson
hughrawlinson / README.md
Created June 23, 2016 21:21
Functional Staples, in ChucK

Functional Functions in ChucK

Here's a set of iterative solutions to map, reduce, and filter, in ChucK. Should probably have gone recursive. Next time.

Somewhat hampered by ChucK missing a higher-order function feature, and the fact that the ChucK type system doesn't support generics or typeclasses, so I implemented classes to wrap them from which they can be extended.

I'd almost consider attempting to implement higher-order functions in ChucK myself after this, except that I'd almost definitely need to do a lot of type-inference code.

@hughrawlinson
hughrawlinson / HelloWebAudio.js
Last active February 28, 2016 16:51
Links from my Sthlm.js Talk on Web Audio
(function(){
var audioContext = new AudioContext();
window.osc = audioContext.createOscillator();
osc.connect(audioContext.destination);
osc.start();
})();
@hughrawlinson
hughrawlinson / catch.php
Created February 11, 2016 14:33
PHP Error Handling
// Excellent work, Simon O'Shea. 😂
<?php
try {
// Something
} catch (Exception $e) {
header("location: https://stackoverflow.com/search?q=[php] ".$e->getMessage());
}
?>
@hughrawlinson
hughrawlinson / reduce.js
Created February 11, 2016 11:16
I love functional Javascript and the chrome developer tools.
a=Array.prototype.map.bind(document.querySelectorAll('.row>.col-lg-3'))(function(a){
return [
a.children[0].innerText,
Array.prototype.map.bind(a.children[1].children)(function(b){
var anchor = b.children[0];
return {name:anchor.innerText,href:anchor.href};
})
];
}).reduce(function(acc,el){
acc[el[0]] = el[1];
@hughrawlinson
hughrawlinson / extractor.py
Created February 1, 2016 21:01
High Resolution Audio Databasing
import librosa
import jams
import os
import mutagen
import argparse
import requests
n_fft = 4096
hop_length = n_fft/2
@hughrawlinson
hughrawlinson / Histogram.java
Last active February 11, 2016 11:39
A histogram class in Java using Lambdas that I was quite proud of
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.function.Function;