Skip to content

Instantly share code, notes, and snippets.

View jcchurch's full-sized avatar

James Church jcchurch

View GitHub Profile
@jcchurch
jcchurch / oneliners.txt
Created April 5, 2011 23:38
Oneliners
And that judge wasn't gonna look at the twenty-seven eight-by-ten color glossy pictures with the circles and arrows and a paragraph on the back of each one, explainin' what each one was to be used as evidence against us. And we was fined fifty dollars and had to pick up the garbage in the snow, but that's not what I came to tell you about.
All your base are belong to us.
Support your local medievalist.
The three kinds of people: Those who can count and those who can't.
Must be user error.
Close Cover Before Striking
The light at the end of the tunnel is usually a train.
42
First pants THEN your shoes.
BSA HandBook, 2nd Ed,: "Scouts as a rule do not go into the big woods."
@jcchurch
jcchurch / processMysterBits.py
Created April 11, 2011 14:02
This function fails to decipher a listing of binary digits using the ASCII tables.
import re
text = "101011011101010001101101011011101010100010101101010001101100101011011101010001110100111011010101101110110110101110110101000011010101101110110100111011010101101011010100110101001000100100011010100101011100110101001000101011010100110101001010100111010101101001001010101110100101010001010101101001001010100111010101101010101010110001010001110100101011010101010010010100011101000110101010110001010000101001001101010011101011011101010100101011010100111010110100101001001101010011010101000101001010110111010100011111010110110010101101110111010101000101001010111101101010001101001110110101011101101101101011010011101101011101101010001101000101001010111010110101001101010001101001000110101101010011010101001010111010110101001010100010101001110101011010100010101010101010011101011101001010100010101010101110100101101010101100010100010101001010011010101011010110101110100101101010101011"
def bin2ascii(binary_form):
"""Converts binary strings of length 8 to ASCII"""
if len(binary_form) != 8:
retur
@jcchurch
jcchurch / quickPlot.m
Created April 20, 2011 03:16
Quickly plot graphs in Matlab
function quickPlot(varargin)
% This function is useful for printing point
% cloud data quickly. This function accepts
% one or more vectors, in either 2D or 3D,
% and either row-order or column-order format.
n = size(varargin, 2);
colors = char('r.', 'g.', 'b.', 'c.', 'm.');
num_colors = size(colors, 1);
@jcchurch
jcchurch / monty.java
Created April 20, 2011 03:19
Monty Hall Problem solved with Monte Carlo Simulations
/*
* The Monty Hall Problem is a famous teaching problem
* in statistics. It works like this:
*
* Imagine that you are on the show "Let's Make a Deal"
* with Monty Hall. Monty shows you three doors and says
* that a car exists behind one of them. You may pick
* one door and if the car is behind it, you win the car.
*
* You pick a door. Monty then chances the rules. He opens
@jcchurch
jcchurch / mpipypi.py
Created April 20, 2011 03:20
Compute Pi using Python and MPI4PY
"""
This code computes pi. It's not the first python
pi computation tool that I've written. This program
is a good test of the mpi4py library, which is
essentially a python wrapper to the C MPI library.
To execute this code:
mpiexec -np NUMBER_OF_PROCESSES -f NODES_FILE python mpipypi.py
@jcchurch
jcchurch / diskstra.m
Created April 20, 2011 03:22
Dijkstra's Algorithm in Matlab
function D = dijkstra(G, pairs)
% This function takes an adjacency matrix called G
% and a p-by-2 matrix called pairs.
% The pairs matrix will contain pairs of indices.
% This function will determine the shortest distance from
% the first index in the pair to the second index for
% every pair in matrix pairs.
%
% The function will only return a p-by-1 matrix of shortest
% distances. I could use it to also return the shortest path,
@jcchurch
jcchurch / gplot3.m
Created April 20, 2011 03:32
3D Version of Matlab's GPLOT
function gplot3(A, xyz)
% GPLOT3(A, xyz) is nearly the same as GPLOT(A, xy) except
% that the xyz variable requires a third dimension.
% This function takes an adjacency matrix and visualizes it
% in 3D.
[d e] = size(A);
if d ~= e
error('A matrix must be square.');
end
@jcchurch
jcchurch / spline3d.m
Created April 21, 2011 16:55
This function computes the 3D spline interpolation of a 3D dataset. I did not write this code.
function newCurve = spline3d(curve, dt)
% interpote a 3d curve using spline
% path 3*x
% newPath 3*x
x = curve(1, :);
y = curve(2, :);
z = curve(3, :);
t = cumsum([0;sqrt(diff(x(:)).^2 + diff(y(:)).^2 + diff(z(:)).^2)]);
sx = spline(t,x);
sy = spline(t,y);
@jcchurch
jcchurch / rotationMatrix.m
Created May 4, 2011 19:55
Perform the 3 axis rotation on a set of points.
function V = rotationMatrix(P, x, y, z)
% rotationMatrix performs the 3 axis rotation on a
% matrix P, which is a 3-by-p set of points, where
% d is equal to 3 and represents the dimensionality
% of the data and p represents the total number of
% observations.
%
% x represents the amount of rotation along the x axis in radians
% y represents the amount of rotation along the y axis in radians
% z represents the amount of rotation along the z axis in radians
@jcchurch
jcchurch / connected.m
Created June 16, 2011 14:53
Quickly determine if a graph is connected
function result = connected(A)
% connected(A)
%
% This function takes an adjacency matrix A
% and returns if the graph is connected.
% 1 means connected.
% 0 means not connected.
% We assume that the starting result is connected.
% In lawyer terms, the graph is connected until proven