Skip to content

Instantly share code, notes, and snippets.

View kcha's full-sized avatar

Kevin Ha kcha

View GitHub Profile
@kcha
kcha / colorbar.R
Last active November 28, 2015 22:56 — forked from johncolby/colorbar.R
An R function to generate color bar legends for neuroimaging plots
# Source: http://stackoverflow.com/a/9314880
color.bar <- function(lut, min, max=-min, nticks=11, ticks=seq(min, max, len=nticks), title='') {
scale = (length(lut))/(max-min)
# dev.new(width=1.75, height=5)
plot(c(0,10), c(min,max), type='n', bty='n', xaxt='n', xlab='', yaxt='n', ylab='', main=title)
axis(2, round(ticks, 2), las=1)
for (i in 1:(length(lut))) {
y = (i-1)/scale + min
rect(0,y,10,y+1/scale, col=lut[i], border=NA)
}
@kcha
kcha / multiprocessing_template.py
Last active August 29, 2015 14:02 — forked from ngcrawford/multiprocessing_template.py
Modified with options. Compatible with python 2.6.
#!/usr/bin/env python
# encoding: utf-8
import sys
import fileinput
from optparse import OptionParser, OptionGroup
import multiprocessing
import time
from itertools import izip_longest, izip, repeat