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 / gpu_array_example.cpp
Created March 3, 2023 21:28
Implements a simple ndarray class template on CPU/GPU with C++17 standard (Apple Clang 14.0 or nvcc CUDA 11.6)
#include <cstdlib>
#include <utility> // swap
#ifdef GPU
#define HD __host__ __device__
#else
#define HD
#endif
using uint = unsigned int;
@jzrake
jzrake / glut_ppm.c
Created May 1, 2012 18:10
PPM screenshot with GLUT
void TakeScreenshot(const char *fname)
{
printf("writing a screenshot to %s\n", fname);
int dimx = glutGet(GLUT_WINDOW_WIDTH);
int dimy = glutGet(GLUT_WINDOW_HEIGHT);
size_t imsize = 3*dimx*dimy;
char *pixels = (char*) malloc(imsize*sizeof(char));
glReadPixels(0, 0, dimx, dimy, GL_RGB, GL_UNSIGNED_BYTE, pixels);
@jzrake
jzrake / class.lua
Last active March 31, 2022 02:56
Partial implementation of the Python class model for Lua
--------------------------------------------------------------------------------
--
-- Partial implementation of the Python class model for Lua
--
-- Copyright (c) 2012, Jonathan Zrake
--
--------------------------------------------------------------------------------
--
-- Exports the following functions:
--
@jzrake
jzrake / mapping.cpp
Last active November 16, 2018 15:41
An proof-of-concept for operator chaining in constructing algorithms
#include <functional>
// ============================================================================
namespace detail
{
template <typename T>
struct function_traits : public function_traits<decltype(&T::operator())>
@jzrake
jzrake / animation.py
Created November 16, 2017 00:05
Starter Python script for making animations with matplotlib
import argparse
import numpy as np
import h5py
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
class TrackFigure(object):
def __init__(self, fig, filename):
self.file = h5py.File(filename, 'r')
@jzrake
jzrake / mathjax-server.js
Created August 9, 2017 20:57
A node.js server that uses mathjax to produce an SVG response.
var http = require('http')
var qs = require('querystring');
var mj = require("mathjax-node");
var socketio = require('socket.io');
var server = http.createServer(function(req, res)
{
req.on('data', function (chunk)
{
var equation = qs.parse(chunk.toString('utf8'))['equation'];
@jzrake
jzrake / tetrun.cpp
Created April 28, 2012 22:21
Example code demonstrating use of tetgen
/* -----------------------------------------------------------------------------
*
* AUTHOR: Jonathan Zrake, NYU CCPP: zrake@nyu.edu
*
*
* USAGE: $> ./tetrun [number of trials]
*
*
* DESCRIPTION:
@jzrake
jzrake / cow-example.c
Created July 24, 2013 05:09
Short example of using cow functions with parallel write and FFT's. This example is from the CAL group meeting on Wednesday 7/24, after Jonathan's going away party.
#include <stdio.h>
#include "cow.h"
double cheese_function(double x, double y, double z)
{
return x + y + z;
}
double butter_function(double x, double y, double z)
{
return x + y + z;
@jzrake
jzrake / glut-template.c
Created July 22, 2013 22:51
Minimal skeleton for a C program that opens a GLUT window
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
#define ESCAPE_KEY 27
static void GLUTDisplayFunc();
static void GLUTIdleFunc();
static void GLUTReshapeFunc(int width, int height);
static void GLUTKeyboardFunc(unsigned char key, int x, int y);