Skip to content

Instantly share code, notes, and snippets.

/*
This script is pretty basic, but if you use it, please let me know. Thanks!
Andrew Hedges, andrew(at)hedges(dot)name
*/
var Haversine = {
Rm : 3961, // mean radius of the earth (miles) at 39 degrees from the equator
Rk : 6373, // mean radius of the earth (km) at 39 degrees from the equator
// convert degrees to radians
@rice2007
rice2007 / MonteCarloPi.py
Last active August 29, 2015 14:07
Monte Carlo Method for Calculating Pi
import math
import random
def coin_flip(flip_count):
total_in_circle = 0.0
for i in range(0, int(flip_count)):
x_coord = random.uniform(-1.0, 1.0)
import base64
import hmac
import json
import requests
import time
import urllib
import os
from hashlib import sha1
from hashlib import md5
@rice2007
rice2007 / Food.java
Created March 14, 2014 01:55
Sample food class with nested classed to determine unit of measure.
public class Food {
protected double price;
protected double quantity;
protected double volume;
protected double weight;
protected String foodType;
protected String volUnit;
protected String weightUnit;
@rice2007
rice2007 / gist:9221749
Last active August 29, 2015 13:56
Heapsort Comparator
package labthree.heapsort;
import java.util.Arrays;
import java.util.Comparator;
public class Driver {
private static long timeInitial;
private static long timeFinal;
private static long timeElapsed;
public class BST<T extends Comparable<T>> extends BinaryTree<T> {
public void insert(BinaryTreeNode<T> z) {
BinaryTreeNode<T> y = null;
BinaryTreeNode<T> x = this.getRoot();
while (x != null) {
y = x;
x = (z.getData().compareTo(x.getData()) == -1)
? x.getLeft()
: x.getRight();
import java.util.ArrayList;
@SuppressWarnings("serial")
public class BubbleSort<T> extends ArrayList<T> implements Comparable<T>{
@SuppressWarnings("unchecked")
public <T extends Comparable<T>> void sort() {
int n = this.size();
boolean swapped = false;
import java.util.Scanner;
public class InsertionSort {
public static void linearSearch(int[] array, int key) {
insertionSort(array);
boolean foundFlag = false;
for (int i = 0; i < array.length; i++) {
if (array[i] == key) {
package labone.insertionsort;
import java.util.Scanner;
public class InsertionSort {
public static void linearSearch(int[] array, int key) {
insertionSort(array);
boolean foundFlag = false;
for (int i = 0; i < array.length; i++) {
@rice2007
rice2007 / InsertionSort.java
Created January 8, 2014 21:40
Algorithm for insertion sort, bubble sort and linear search on integer arrays
package labone.insertionsort;
import java.util.Scanner;
public class InsertionSort {
public static void linearSearch(int[] array, int key) {
insertionSort(array);
boolean foundFlag = false;
for (int i = 0; i < array.length; i++) {