Skip to content

Instantly share code, notes, and snippets.

skeeto / .gitignore
Created October 18, 2009 15:41
Multithreaded Monte Carlo pi calculator
skeeto / collatz.c
Created June 2, 2011 20:45
Collatz experiment
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <gmp.h>
#define S(n) mpz_get_str(NULL, 10, n)
#define EQ(z, n) (mpz_cmp_ui(z, n) == 0)
/* Print out collatz path for given number. */
int path(char *str)
skeeto / decimalize.el
Created November 30, 2011 01:20
emacs lisp exercise: latitude-longitude-decimalize
(defun latitude-longitude-decimalize (str)
(destructuring-bind (lath latm lats latd lonh lonm lons lond)
(split-string str "[^0-9.NEWS]+" t)
(vector (latlon-helper latd lath latm lats)
(latlon-helper lond lonh lonm lons))))
(defun latlon-helper (d &rest hms)
(* (if (or (equal d "N") (equal d "E")) 1 -1)
skeeto / perlin.m
Created May 8, 2012 02:20
Octave Perlin noise function
## Returns the Perlin noise value for the given point. Accepts 2D
## arrays for x and y, i.e. from meshgrid(). For example,
## [x y] = meshgrid(0:0.1:10, 0:0.1:10);
## d = perlin(x, y);
## The special thing here is it's entirely vectorized: no loops!
function v = perlin(x, y)
## Find the nearest grid points (2D)
x0 = floor(x);
skeeto / .gitignore
Created May 10, 2012 01:29
JFreeChart demo
skeeto / javap-handler.el
Created July 25, 2012 21:21
Automatically open .class files in Emacs with javap
(add-to-list 'file-name-handler-alist '("\\.class$" . javap-handler))
(defun javap-handler (op &rest args)
"Handle .class files by putting the output of javap in the buffer."
((eq op 'get-file-buffer)
(let ((file (car args)))
(with-current-buffer (create-file-buffer file)
(call-process "javap" nil (current-buffer) nil "-verbose"
"-classpath" (file-name-directory file)
skeeto / maxima.c
Created July 28, 2012 02:07
Compute local maxima using Newton's method
#include <stdio.h>
#include <math.h>
#include <float.h>
#define N 3
typedef struct {
double x[N];
} vector;
skeeto / .gitignore
Created July 30, 2012 05:01
Throwaway N-body Sim
skeeto / coin-flip.el
Created July 30, 2012 14:55
Monte Carlo Elisp throwaways
;; Minimum Number Of Coin Tosses Such That Probability Of Getting 3
;; Consecutive Heads Is Greater Than 1/2
(require 'cl)
(defun flip ()
"Flip a coin."
(if (< 0 (random)) 'H 'T))
skeeto / .gitignore
Created July 31, 2012 22:24
Compute 100,000 digits of sqrt(2) in pure ANSI C