Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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);
@jzrake
jzrake / isentropic.c
Last active December 15, 2015 15:59
Solve the compressible Navier-Stokes equation in 1d with a polytropic equation of state.
/*
* AUTHOR: Jonathan Zrake
*
* DATE: 3/31/2013
*
* PURPOSE: Solve the compressible Navier-Stokes equation in 1d with a
* polytropic equation of state.
*
* SCHEME: semi-implicit Runge-Kutta / Backward Euler
*
@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 / poisson.py
Created November 19, 2012 00:09
Code demonstrates solving an elliptic equation using an iterative solver
"""
Author: Jonathan Zrake, NYU CCPP
Code demonstrates solving an elliptic equation using an iterative solver.
"""
import itertools
import numpy as np
import matplotlib.pyplot as plt