This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
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 |
# 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(): |
#!/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++) { |
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)) { |
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: |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
#!/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 |