Skip to content

Instantly share code, notes, and snippets.

@jzrake
jzrake / Makefile
Created April 17, 2012 20:10
Wrapping C++ classes with Lua
LUAHOME = $(HOME)/Work/lunum/lua-5.2.0
CFLAGS = -Wall
default : luawrap
luawrap : luawrap.cpp
$(CXX) $(CFLAGS) -o $@ $^ -L$(LUAHOME)/lib -I$(LUAHOME)/include -llua
clean :
@jzrake
jzrake / fitline.py
Created March 17, 2012 20:10
Fitting a smeared line model
#!/usr/bin/env python
import numpy as np
from matplotlib import pyplot as plt
from scipy.optimize import leastsq
from scipy.ndimage import binary_closing, grey_closing
def LineModel(pt1, pt2, Nx=100, Ny=100, h=1.0, sig=0.1):
"""
@jzrake
jzrake / tee.py
Created March 8, 2012 21:47
Tee's program that loads some data
#!/usr/bin/env python
def load_from_many(pattern):
"""
Take a pattern and return a numpy array containing the concatenation of all
the files matching that pattern. Only the first column and rows after the
first are returned, and the data values are offset by the difference between
the first and second columns of the first row.
"""
@jzrake
jzrake / quantile.py
Created February 16, 2012 00:56
Quantile in Python
#!/usr/bin/env python
import numpy as np
def Quantile(data, q, precision=1.0):
"""
Returns the q'th percentile of the distribution given in the argument
'data'. Uses the 'precision' parameter to control the noise level.
"""
@jzrake
jzrake / gnuplot.lua
Created February 2, 2012 02:46
Calling gnuplot from Lua
local function plot(series, tpause)
local gp = io.popen("gnuplot", 'w')
local lines = { }
for k,v in pairs(series) do
table.insert(lines, string.format(" '-' u 1:2 title '%s'", k))
end
gp:write("plot" .. table.concat(lines, ",") .. "\n")
for k,v in pairs(series) do