Skip to content

Instantly share code, notes, and snippets.


Dan Piponi dpiponi

View GitHub Profile
dpiponi / infill.glsl
Created May 18, 2022
View infill.glsl
// See
// Random numbers using code at
// A single iteration of Bob Jenkins' One-At-A-Time hashing algorithm.
uint hash( uint x ) {
x += ( x << 10u );
x ^= ( x >> 6u );
x += ( x << 3u );
View init.m
(** User Mathematica initialization file **)
(** See for info on instaling this file **)
(** Display graphics inline in iTerm2. I don't know an easy way to test if we're running in iTerm2 without looking at the process table. **)
WriteString[$Output, "\033]1337;File=inline=1:"<>ExportString[ExportString[image,"PNG"],"Base64"]<>"\007"];
View coupling.c
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
int bernoulli(float p, float r)
return r > 1 - p;
dpiponi /
Created Mar 27, 2021
Branched flow with taichi
import math
import numpy as np
import random
import matplotlib.pyplot as plt
medium_size = 1024
x = np.linspace(-1., 1., medium_size)
y = np.linspace(-1., 1., medium_size)
x, y = np.meshgrid(x, y, indexing='ij')
dpiponi / example.cpp
Last active Mar 15, 2021
Near minimal example of replacing explicit state machine with coroutine. (Compare Example1 class with Example2, not the supporting "library" code.)
View example.cpp
// Some platforms import from experimental/coroutine
// rather than coroutine.
// Controls whether the coroutine starts in a suspended state
// or runs to the first suspension point on construction.
// The two implementations should match.
#define INITIAL_RUN 1
dpiponi /
Created Feb 8, 2021
Workplace scheduling with Python-MIP
# From
from mip import *
m = Model(sense = MAXIMIZE)
num_slots = 10
num_workers = 5
num_tasks = 3
def slot_to_time(slot):
dpiponi / main.lhs
Created Dec 24, 2020
Branch relaxation with monotonic time travel
View main.lhs
Here's a block of code in some imaginary assembly language:
jmp A
jmp A
jmp A
.A ...
import csv
import math
import matplotlib.pyplot as plt
import locale
def frac(x):
return x - math.floor(x)
def first_digit(x):
return int(math.floor(math.pow(10, frac(math.log10(x))) + 0.0001))
dpiponi /
Created Aug 27, 2020
Are these runners?
# Python 3
import collections
Write = collections.namedtuple("Write", ["written"])
def hello_world():
yield Write("Hello, world!")
yield Write("Hello, world!")
return 1
def identity(gen):
dpiponi / quine.c
Created Jul 23, 2020
A quine using only one loop and arithmetic (+, -, *, /, %)
View quine.c
* This is a literate quine. That means that
* 1. the comments will tell you a little about how it works and
* 2. if you compile and run it its output will be identical to its source
* code even though it doesn't look at its original source. It literally
* contains within itself a complete recipe for how to display itself.
* Quines are ten a penny. This one is unusual because
* 1. its main loop consists solely of a loop to print characters
* generated by a function called programChar() and