Skip to content

Instantly share code, notes, and snippets.

View alexbw's full-sized avatar

Alex Wiltschko alexbw

  • Google
  • Boston, MA
View GitHub Profile
function [tsOffsets, instantRate] = calcCrossCorrelogram(ts1, ts2, window)
% INPUT:
% ts1 - timestamp array, center of cross-correlogram
% ts2 - timestamp array
% window - the window of the timestamps to compute, e.g. [-0.1 0.1] for
% 0.1 seconds around each spike in ts1.
%
% OUTPUT:
% tsOffsets - the offsets from each spike in ts1 that has spikes nearby
% instantRate - 1/ISI of each spike in ts1 that has spikes nearby
// Setting up the Audio Session...
// Initialize and configure the audio session, and add an interuption listener
AudioSessionInitialize(NULL, NULL, sessionInterruptionListener, self);
UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory);
// Allow iPod audio to continue to play while the app is active.
UInt32 flag = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(flag), &flag);
@alexbw
alexbw / opencl_test.py
Created June 14, 2011 20:27
Benchmarking OpenCL
import pyopencl as cl
import pyopencl.array as cl_array
from pyopencl.elementwise import ElementwiseKernel
import numpy.linalg as la
import numpy as np
from time import clock
from pylab import *
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
@alexbw
alexbw / AutoEncoder.h
Created June 28, 2011 19:58
Autoencoder for Objective-C
//
// AutoEncoder.h
// QuartzTest
//
// Created by Alex Wiltschko on 6/27/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@alexbw
alexbw / .zshrc
Created August 24, 2011 21:32
ZSH profile
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
bindkey -e
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall
zstyle :compinstall filename '/Users/Alex/.zshrc'
autoload -Uz compinit
@alexbw
alexbw / opencv.rb
Created August 24, 2011 21:33
OpenCV Homebrew Formula
require 'formula'
class Opencv < Formula
url 'http://cdnetworks-us-2.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.3.1/OpenCV-2.3.1.tar.bz2'
version "2.3.1"
homepage 'http://opencv.willowgarage.com/wiki/'
md5 "827c9f8aa14384c531c73aa165f9b777"
depends_on 'cmake' => :build
depends_on 'pkg-config' => :build
@alexbw
alexbw / PythonInstallwithMacports
Created September 1, 2011 02:03
Python installation w/ MacPorts
# Install Macports
# We'll install a relatively high-level package first, with a lot of dependencies,
# so that we pick up everything along the way
# Chaco is an enthought plotting package that'll
sudo port install py26-chaco
sudo port select python python26
sudo port install py26-ipython
@alexbw
alexbw / repeatingtimer.py
Created September 1, 2011 20:11
A repeating timer in Python
class RepeatingTimer(object):
"""
USAGE:
from time import sleep
def myFunction(inputArgument):
print(inputArgument)
r = RepeatingTimer(0.5, myFunction, "hello")
r.start(); sleep(2); r.interval = 0.05; sleep(2); r.stop()
"""
@alexbw
alexbw / nearestNeighborInterpolation
Created September 6, 2011 02:00
Densify a sparse matrix with nearest-neighbor interpolation
import numpy as np
def densify(self, img):
windowSize = [3,3]
img = img.astype('float32')
img[np.isnan(img)] = np.inf
while np.isinf(img).sum() > 0:
idx = np.isinf(img)
@alexbw
alexbw / using_shelve.py
Created October 25, 2011 15:39
Using shelve for good, not for evil
import os, shelve
# Get the current module (for its namespace, so we can fill it with variables)
import sys
thismodule = sys.modules[__name__]
# Get the hidden directory holding our persistence files
persistenceDirectory = os.path.expanduser("~/.mySecretData/") # The directory for our persistent data
os.system("mkdir -p " + persistenceDirectory) # Make sure the directory exists
pathToStateFile = os.path.join(persistenceDirectory, "stateVariables.db") # a persistent set of variables