Skip to content

Instantly share code, notes, and snippets.

@skeeto
skeeto / .gitignore
Created October 18, 2009 15:41
Multithreaded Monte Carlo pi calculator
log
pi
state
state~
@skeeto
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
skeeto / decimalize.el
Created November 30, 2011 01:20
emacs lisp exercise: latitude-longitude-decimalize
;; http://xahlee.blogspot.com/2011/11/emacs-lisp-exercise-latitude-longitude.html
(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
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
skeeto / .gitignore
Created May 10, 2012 01:29
JFreeChart demo
build
dist
cache.properties
TAGS
@skeeto
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."
(cond
((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
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
skeeto / .gitignore
Created July 30, 2012 05:01
Throwaway N-body Sim
galaxy
output.*
*.png
@skeeto
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
;; http://blog.eduflix.tv/2012/05/contest-answer-minimum-number-of-coin-tosses-such-that-probability-of-getting-3-consecutive-heads-is-greater-than-12/
(require 'cl)
(defun flip ()
"Flip a coin."
(if (< 0 (random)) 'H 'T))
@skeeto
skeeto / .gitignore
Created July 31, 2012 22:24
Compute 100,000 digits of sqrt(2) in pure ANSI C
sqrt2
*.txt