Skip to content

Instantly share code, notes, and snippets.

@jzrake
jzrake / glut-minimal.py
Created June 23, 2014 23:18
Minimal template to run GLUT from Python
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
rotationX = 0.0
rotationY = 0.0
last_x = 0
last_y = 0
@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
@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 / 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 / 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 / vbo.c
Created April 20, 2012 04:24
OpenGL VBO example
void draw_vbo()
{
GLuint vbo,ibo;
GLfloat verts[8][3] = {{0.0, 0.0, 0.0},
{0.0, 0.0, 0.1},
{0.0, 0.1, 0.0},
{0.0, 0.1, 0.1},
{0.1, 0.0, 0.0},
{0.1, 0.0, 0.1},
{0.1, 0.1, 0.0},
@jzrake
jzrake / srevec.py
Created May 7, 2012 21:43
SR hydrodynamics eigenvectors
#!/usr/bin/env python
# ------------------------------------------------------------------------------
#
# Authors: Jonathan Zrake, Bez Laderman: NYU CCPP
# Date: May 7th, 2012
#
# This piece of code implements the left and right eigenvectors of the ideal
# special relativistic hydrodynamics equations. The formulas are an exact
# translation of those given in the literature:
@jzrake
jzrake / zexcept.cpp
Created May 8, 2012 17:01
Quick tutorial on runtime exceptions in C++
#include <iostream>
#include <stdexcept>
class ZrakeFailed : public std::runtime_error
{
public:
ZrakeFailed(const std::string &msg) : std::runtime_error("zraker failed. " + msg) { }
@jzrake
jzrake / euler1d.c
Created May 15, 2012 20:05
Solves the 1-dimensional Euler equations using the method of lines and HLL Riemann solver
/*------------------------------------------------------------------------------
* FILE: euler.c
*
* Copyright (C) 2011 Jonathan Zrake, NYU CCPP: zrake <at> nyu <dot> edu
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
@jzrake
jzrake / h5_safe_Lexists.c
Created June 30, 2012 21:44
HDF5 safe, recursive H5Lexists
int H5Lexists_safe(hid_t base, const char *path)
// -----------------------------------------------------------------------------
// The HDF5 specification only allows H5Lexists to be called on an immediate
// child of the current object. However, you may wish to see whether a whole
// relative path exists, returning false if any of the intermediate links are
// not present. This function does that.
// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Exists
// -----------------------------------------------------------------------------
{