Skip to content

Instantly share code, notes, and snippets.

View haldean's full-sized avatar

Haldean Brown haldean

View GitHub Profile
@haldean
haldean / gist:1905595
Created February 25, 2012 03:06
Spline evaluation
float safeDiv(float a, float b) {
if (abs(a) < 1e-10 && abs(b) < 1e-10) return 0;
else return a / b;
}
float b(vector<float> kn, int i, int n, float t) {
if (n == 0) {
return (kn[i] <= t < kn[i+1]) ? 1 : 0;
}
return
@haldean
haldean / while_test.py
Created February 14, 2012 17:22
Test "while 1" vs. "while True" in Python
# Testing results (lower number is faster):
# while True while 1
# pypy 1.7.0: 0.0733 0.0201
# cpython 2.7.1 0.146 0.109
# cpython 3.2.2 2.79 2.72
loops = 10000
trials = 1000
def while_True():
@haldean
haldean / umqra.py
Created January 10, 2012 08:16
UMQRA
#!/usr/bin/env pypy
a = ord('a')
for offset in range(26):
print ''.join(
map(lambda char: chr((ord(char) - a + offset) % 26 + a), 'umqra'))
void StableFluidsSimWithMarkers::project(
int N, ArrayXs * u, ArrayXs * v, ArrayXs * u0, ArrayXs * v0) {
// Set velocities on solid boundaries to zero
zeroSolidBoundaries(u, v);
// Compute discrete divergence on velocity field
ArrayXs div(N+1, N+1);
div.setZero();
for (int i=1; i<N; i++) {
@haldean
haldean / gist:1444549
Created December 7, 2011 20:43
Pressure solve for velocity projection
for (int k=0; k<20; k++) {
for (int i=1; i<N+1; i++) {
for (int j=1; j<N+1; j++) {
if (!m_has_fluid(i, j)) continue;
int adj_fluid_cells = 0;
scalar p = pressure(i, j);
pressure(i, j) = div(i, j);
if (!m_has_solid(i-1, j)) {
@haldean
haldean / gentoc.py
Created November 7, 2011 20:44
Generate HTML Table of Contents
def gen_toc(html, ignore_h1_in_toc=False):
if ignore_h1_in_toc:
first_level = 2
else:
first_level = 1
soup = BeautifulSoup.BeautifulSoup(html)
headers = soup.findAll(re.compile('^h[%d-6]' % first_level))
output = []
for header in headers:
@haldean
haldean / about.md
Created August 9, 2011 14:16 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@haldean
haldean / bootstrap.sh
Created May 11, 2011 00:35
Bootstrap new Linux and OSX systems with my dotfiles and packages
#!/bin/bash
GITREPO=ssh://haldean@haldean.org/srv/dotfiles.git
APT_PACKAGES='emacs awesome zsh biblatex texlive-latex-extra emacs-goodies-el'
BREW_PACKAGES=
cd
HOMEDIR=`pwd`
GITDIR=$HOMEDIR/.dotfiles