Skip to content

Instantly share code, notes, and snippets.

View jcchurch's full-sized avatar

James Church jcchurch

View GitHub Profile
@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 / turtleFlowers.py
Last active June 2, 2025 17:07
This Python script (for Python 3) demonstrates how to draw flowers at random places, colors, and sizes around the screen using the turtle library built into Python 3.
import turtle
import random
import math
def drawPolygon(myTurtle, sides, length):
angle = 360 / sides
for side in range(sides):
myTurtle.forward(length)
myTurtle.left(angle)
@jcchurch
jcchurch / today.py
Last active August 22, 2024 02:08
Adds line to let bash know that this is a python 3 script.
#!/usr/bin/env python3
import datetime
import argparse
import re
def createDate(stringDate):
if re.match("\d\d\d\d-\d\d-\d\d$", stringDate) is None:
raise ValueError("This is not in the correct date format. Use YYYY-MM-DD")
@jcchurch
jcchurch / dierolling.py
Created October 12, 2022 02:38
My exploration of different die rolling stats for D&D and Risk.
print()
print()
print()
print("D&D")
totals = [0] * 19
for a in range(1, 7):
for b in range(1, 7):
for c in range(1, 7):
@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,
#include <unistd.h>
int main(v,c)
int v;
char **c;
{
for(v[(*&c)++]="Hello, world!\n)";
(!!!!c)[*c] && (v-- || --(*&c) && execlp(*c, *c, c[!!c] + !!c, !c));
**c = !c)
write(!!*c, **&c, !!**c);
class MyClass {
myVar: string = "Hello ";
greet(name: string) {
return this.myVar + name;
}
}
let x = new MyClass();
console.log(x.greet("James"));
let y = x.greet;
#!/usr/bin/env python3
import subprocess
import glob
import os
import os.path
import sys
def getProcessOutput(myCommand):
call = subprocess.Popen(myCommand, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
call.wait()
@jcchurch
jcchurch / buffon_needle.processing
Created March 14, 2019 20:35
Buffon's Needle Drop Experiment in Processing
int needles = 0;
int crossings = 0;
int needleLength = 50;
int linegap = 64;
int min = 0 + needleLength;
int max = width - needleLength;
void setup() {
size(640, 640);
//frameRate(5);
@jcchurch
jcchurch / .vimrc
Last active November 22, 2018 06:19
" .vimrc
" James's vim configuration file.
" This configuration makes James happy to program.
let mapleader=" "
set autoindent
set backspace=indent,start
set nocompatible
set expandtab