Skip to content

Instantly share code, notes, and snippets.

View jamiebullock's full-sized avatar

Jamie Bullock jamiebullock

View GitHub Profile
@jamiebullock
jamiebullock / no_abstraction.java
Created January 23, 2020 20:12
Not separate levels of abstraction
public String render() throws Exception
{
StringBuffer html = new StringBuffer("<hr");
if (size > 0)
html.append(" size="").append(size + 1).append("\"");
html.append(">");
return html.toString();
}
@jamiebullock
jamiebullock / introspect.py
Last active January 14, 2020 20:45
Introspection Function
class Test:
def __init__(self):
self.x = 1
self.y = 2
def introspect(obj):
for func in [type, id, dir, vars, callable]:
print("%s(%s):\t\t%s" % (func.__name__, introspect.__code__.co_varnames[0], func(obj)))
@jamiebullock
jamiebullock / PyDub-Demo.py
Last active December 27, 2019 20:15
PyDub demo
import urllib.request
from pydub import AudioSegment
from pydub.playback import play
from pydub.generators import Sine
# Download an audio file
urllib.request.urlretrieve("https://tinyurl.com/wx9amev", "metallic-drums.wav")
# Load into PyDub
loop = AudioSegment.from_wav("metallic-drums.wav")
#import <Foundation/Foundation.h>
@interface SimpleURL : NSObject<NSURLSessionDataDelegate> {
NSURLSession *session;
dispatch_semaphore_t semaphore;
}
-(void)connectWithDelegate:(NSString *)url;
@jamiebullock
jamiebullock / urltest.m
Created March 20, 2017 15:22
Test for Cocoa connecting to a remote URL
#import <Foundation/Foundation.h>
@interface SimpleURL : NSObject {
NSURLSession *session;
}
-(void)connect:(NSString *)url;
@jamiebullock
jamiebullock / urltest.cpp
Created March 20, 2017 15:19
Test for JUCE connecting to a remote URL
#include "../JuceLibraryCode/JuceHeader.h"
int connect(const String& source)
{
URL url(source);
ScopedPointer<WebInputStream> stream = url.createInputStream(false);
if (stream == nullptr) return -1;
return 0;
}
@jamiebullock
jamiebullock / LiveAudioProcessing.swift
Created June 19, 2014 07:45
Live coding audio with Swift Playgrounds
import Cocoa
import AVFoundation
// Setup engine and node instances
var engine = AVAudioEngine()
var delay = AVAudioUnitDelay()
var reverb = AVAudioUnitReverb()
var mixer = engine.mainMixerNode
var input = engine.inputNode
@jamiebullock
jamiebullock / fibonacci.c
Last active August 29, 2015 14:02
WWDC 404 Fibonacci example in C
long fibonacci(long n)
{
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
}
int main(int argc, char const **argv)
{
double phi = fibonacci(45) / (double)fibonacci(44);
@jamiebullock
jamiebullock / au_input_create
Last active September 24, 2022 10:27
Set up RemoteIO or HALOutput Audio Unit for recording
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
#define INPUT_BYTES_PER_SAMPLE sizeof(SInt16)
#define AU_IO_COMPONENT kAudioUnitSubType_RemoteIO
#define AU_DEFAULT_COMPONENT AU_IO_COMPONENT
#elif TARGET_OS_MAC
#define INPUT_BYTES_PER_SAMPLE sizeof(Float32)
#define AU_IO_COMPONENT kAudioUnitSubType_HALOutput
#define AU_DEFAULT_COMPONENT kAudioUnitSubType_DefaultOutput
#endif
@jamiebullock
jamiebullock / gist:6882862
Created October 8, 2013 10:43
Gist for libsndfile failed install with Homebrew
Error: No available formula for pkg-config
Making install in M4
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
Making install in man
ln -s ./sndfile-metadata-get.1 sndfile-metadata-set.1
ln -s ./sndfile-interleave.1 sndfile-deinterleave.1
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/Cellar/libsndfile/1.0.25/share/man/man1" || ../Cfg/install-sh -c -d "/usr/local/Cellar/libsndfile/1.0.25/share/man/man1"