Skip to content

Instantly share code, notes, and snippets.

View cjmcgraw's full-sized avatar

Carl McGraw cjmcgraw

View GitHub Profile
import java.awt.Point;
public class LoopFill {
public static void main(String[] args) {
LoopFill loopFiller = new LoopFill();
int[] result;
try {
result = parseArgs(args);
#! /usr/bin/python
from random import randint
from time import time
VALUE_RANGE = (0, 1000)
def timer(f):
def wrapper(first_list, second_list, required_difference):
t1 = time()
@cjmcgraw
cjmcgraw / test_pairs.py
Last active August 29, 2015 14:03
File for testing an algorithm for finding all potential pairs of numbers
#! /usr/bin/python
from time import time
from collections import Counter
from random import randint
#########################################
# Test functions. Used for testing
########################################
VALUES = (1, 100000)
@cjmcgraw
cjmcgraw / FilePathFinder.java
Created July 16, 2014 02:48
Class for obtaining and validating a file path
import java.io.*;
public class FilePathFinder {
public static void main(String[] args) {
String path = getInput();
boolean validatePath = validatePath(path);
System.out.println("Path exists? ");
System.out.println(validatePath);
@cjmcgraw
cjmcgraw / QuestionNodeTreeBuilder.java
Created August 12, 2014 03:19
The initial implementation of a "builder" to build a tree from a formatted text file
import java.io.*;
import java.util.*;
import com.mycompany.guesstheanimal.exceptions.InvalidTreeParsingException;
public class QuestionNodeTreeBuilder implements TreeBuilder<QuestionNode>{
public static final String NODE_DATA_SPLITTER = QuestionNodeTreeWriter.NODE_DATA_SPLITTER;
public static final String QUESTION_PREFIX = QuestionNodeTreeWriter.QUESTION_PREFIX;
public static final String ANSWER_PREFIX = QuestionNodeTreeWriter.ANSWER_PREFIX;
from itertools import ifilter
from time import time
def time_it(func, *args, **kwargs):
def func_wrapper(*args, **kwargs):
t1 = time()
func(*args, **kwargs)
t2 = time()
print("Function Executed in: {} seconds".format(t2 - t1))
return func_wrapper
class FantasyTeam(object):
def __init__(self):
self._roster = {'RB' : None,
'QB' : None,
... ,
'WR': None}
self._points = 0.0
@cjmcgraw
cjmcgraw / every-nth.clj
Created May 16, 2015 21:28
Clojure function to map a given function over a given dataset every nth interval.
(defn every-nth [f data n & {:keys [n-times] :or {n-times -1}}]
"Applies the function to every nth element, leaving other elements unaltered"
(map-indexed #(if (and
(zero? (mod (Math/abs (+ %1 1)) n))
(> n (quot %1 (* (Integer/signum n) n-times))))
(f %2) %2)
data))
@cjmcgraw
cjmcgraw / kmeans.py
Last active August 29, 2015 14:25
K-Means implementation
from random import randint
class KMeans:
def __init__(self, minimum, maximum, dim, k):
self._centroids = [[randint(minimum, maximum) for d in range(dim)] for x in range(k]
self._points = {i: [] for i in range(k)}
def update(self, vector):
distance = lambda v: sqrt(sum([(x2-x1) ** 2 for x1, x2 in zip(v[1], vector)]))
#! /usr/bin/env python
import subprocess
import argparse
import httplib
import json
parser = argparse.ArgumentParser(description="print out all documents in an index to stdout")
parser.add_argument("--index", type=str)
parser.add_argument("--host", type=str)
parser.add_argument("--port", default=9200, type=int)