Skip to content

Instantly share code, notes, and snippets.

View alexbw's full-sized avatar

Alex Wiltschko alexbw

  • Google
  • Boston, MA
View GitHub Profile
@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 / 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 / .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 / 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 / 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
@alexbw
alexbw / run_lines_in_terminal.py
Created October 31, 2011 00:34
A simple TextMate command to run things in iPython
pbcopy | "$TM_SELECTED_TEXT"
osascript << END
tell application "Terminal"
activate
do script with command "%paste" in window 1
end tell
tell application "TextMate"
activate
end tell
END
@alexbw
alexbw / roi_selector.py
Created January 18, 2012 23:05
ROI Selector
import SimpleCV as scv
import pygame
def selectroi(numpyArray):
"""
upperLeft, lowerRight, twoOrFourPartitions = selectroi(numpyArray)
"""
roiSelector = ROISelector(numpyArray)
upperLeft, lowerRight, twoOrFourPartitions = roiSelector.doDisplay()
@alexbw
alexbw / gist:1736829
Created February 4, 2012 09:54
Quick B-Spline
contour = np.array([[182, 181, 180, 179, 179, 178, 178, 177, 177, 178, 178, 179, 179,
180, 180, 181, 181, 184, 185, 186, 187, 188, 190, 192, 193, 195,
195, 199, 199, 200, 201, 203, 208, 211, 211, 210, 210, 209, 209,
208, 208, 207, 207, 205, 205, 196, 195, 194, 193, 182],
[206, 207, 207, 208, 209, 210, 211, 212, 213, 214, 217, 218, 221,
222, 224, 225, 226, 229, 229, 230, 230, 231, 231, 233, 233, 235,
236, 240, 241, 242, 242, 244, 244, 241, 233, 232, 229, 228, 225,
224, 223, 222, 220, 218, 217, 208, 208, 207, 207, 206]])