Skip to content

Instantly share code, notes, and snippets.

View thomasballinger's full-sized avatar

Tom Ballinger thomasballinger

View GitHub Profile
@thomasballinger
thomasballinger / vtk2vtp.py
Created October 12, 2011 15:10
vtk2vtp.py
#!/usr/bin/env python
"""File format conversion
category: vtk, file conversion, tomb"""
import os, sys
import vtk
def vtk2vtp(invtkfile, outvtpfile, binary=False):
"""What it says on the label"""
reader = vtk.vtkPolyDataReader()
@thomasballinger
thomasballinger / gist:1336916
Created November 3, 2011 16:13
nifti2nrrd dwi conversion
#!/usr/bin/env python
#TODO
#1) Add measurement frame
#2) Save data part of nifti to its own file, and point to it in 'data file' field
import nibabel as nib
import sys
@thomasballinger
thomasballinger / gist:1628735
Created January 17, 2012 20:37
What I'd like to do at Hacker School

I'm most excited about collaborating with others and discussing interesting problems.

These are all just ideas

get deeper into javascript learn cool new languages (anything not Python, c, java, javascript) specifically, learn ruby continue project Euler problems (very exciting to collaborate with others on them) learn some css, client side javascript, and web page design

@thomasballinger
thomasballinger / gist:2918779
Created June 12, 2012 17:13
hacker school name quiz
javascript:(function(){if(document.timesClicked==undefined){document.timesClicked=0;};document.timesClicked++;var names=document.getElementsByClassName('name');for(var i=0;i<names.length;i=i+1){if(!names[i].savedName){names[i].savedName=names[i].innerHTML;}names[i].innerHTML=names[i].savedName;};setTimeout(function(){for(var i=0;i<names.length;i=i+1){names[i].innerHTML='?';};},1000);if(document.timesClicked==1){var ircs=document.getElementsByClassName('irc');for(var i=0;i<ircs.length;i=i+1){ircs[i].savedIRC=ircs[i].innerHTML;ircs[i].innerHTML='?';};var images=document.getElementsByClassName('profile-image');var remove=function(img){var toRemove=img.parentElement.parentElement;var parent=toRemove.parentElement;parent.removeChild(toRemove);};var addRemover=function(img){img.addEventListener('click',function(e){e.preventDefault();remove(img);return false;});};for(var i=0;i<images.length;i=i+1){addRemover(images[i])};};})()
# TODO: make mix-in functions return objects of the same type?
# Whatever objects they would return, but with the mix-in mixed in?
class enumerable(object):
def filter(self, f):
return filter(f, self)
def map(self, f):
return map(f, self)
def foreach(self, f):
return [f(x) for x in self]
#!/usr/bin/env python
"""An externally-accessible toy server whith several response strategies"""
import socket
import sys
from multiprocessing import Pool
def web_scrape(site):
s = socket.socket()
s.connect((site, 1333))
@thomasballinger
thomasballinger / gist:2991235
Created June 25, 2012 21:05
simple Python server
#!/usr/bin/env python
"""An externally-accessible toy server"""
import socket
def get_local_address_hack():
s = socket.socket()
s.connect(('google.com', 80))
address, port = s.getsockname()
return address
@thomasballinger
thomasballinger / gist:3037579
Created July 3, 2012 04:00
brew install -v portmidi, brew --config, brew doctor output
Thomass-MacBook-Air:~ tomb$ brew install -v portmidi
Warning: Experimental support for using the "Command Line Tools" without Xcode.
Some formulae need Xcode to be installed (for the Frameworks not in the CLT.)
==> Downloading http://downloads.sourceforge.net/project/portmedia/portmidi/200/portmidi-src-200.zip
Already downloaded: /Library/Caches/Homebrew/portmidi-200.zip
/usr/bin/unzip /Library/Caches/Homebrew/portmidi-200.zip
Archive: /Library/Caches/Homebrew/portmidi-200.zip
creating: portmidi/
inflating: portmidi/ALL_BUILD.vcproj
inflating: portmidi/CHANGELOG.txt
@thomasballinger
thomasballinger / dd.py
Created July 3, 2012 17:50 — forked from jasonLaster/dd.py
Dynamic Dispatch in Python
class FlexiDict(dict):
def get_gt(self, key):
return [v for k,v in d.iteritems() if k > key]
def __getattr__(self, name):
if name.startswith("find_"):
params = name.split("_")
if len(params) == 3:
def func():
@thomasballinger
thomasballinger / gist:3836154
Created October 4, 2012 20:18
functional regex engine in python by psykotic of reddit
from itertools import chain
def nil(s):
yield s
def seq(l, r):
return lambda s: (sr for sl in l(s) for sr in r(sl))
def alt(l, r):
return lambda s: chain(l(s), r(s))