Skip to content

Instantly share code, notes, and snippets.

@jjcomer
jjcomer / keybase.md
Last active August 29, 2015 13:58
keybase.md

Keybase proof

I hereby claim:

  • I am jjcomer on github.
  • I am jjcomer (https://keybase.io/jjcomer) on keybase.
  • I have a public key whose fingerprint is 951D BB52 4253 4B41 E48F 00BD 8FB0 6166 F8A9 582F

To claim this, I am signing this object:

@jjcomer
jjcomer / keybase.md
Created May 20, 2015 16:58
keybase.md

Keybase proof

I hereby claim:

  • I am jjcomer on github.
  • I am jjcomer (https://keybase.io/jjcomer) on keybase.
  • I have a public key whose fingerprint is 8E60 EB2A 9A8F 5A4E 2146 3F4B 124D C290 7C94 9EF2

To claim this, I am signing this object:

@jjcomer
jjcomer / stateMachine.clj
Created July 30, 2011 11:32
Clojure State Machine
(ns stateMachine)
(defn parse-integer [str]
(try (Integer/parseInt str)
(catch NumberFormatException nfe 0)))
(defn displayMenu
"This function displays the menu and gets the user's input"
[]
(println "Displaying the menu")
@jjcomer
jjcomer / stateMachine.clj
Created July 31, 2011 00:43
Clojure State Machine with Application State
(ns StateMachine)
(defn initTodo []
"This function will return a hash representing the inital application state"
{:file "todo.txt"
:some-other-option true})
(defn parse-integer [str]
(try (Integer/parseInt str)
(catch NumberFormatException nfe 0)))
@jjcomer
jjcomer / HelperMethods.java
Created July 31, 2011 11:46
Java Unit Test Helpers
import java.lang.reflect.*;
public class HelperMethods {
@SuppressWarnings("unchecked")
public static <R, T> R invokePrivateMethod(T object, String methodName, Object... args) {
final Method methods[] = object.getClass().getDeclaredMethods();
for (Method method : methods) {
if (methodName.equals(method.getName())) {
try {
method.setAccessible(true);
@jjcomer
jjcomer / colour.clj
Created August 6, 2011 01:31
Colour for terminal output
(ns ^{:doc "Add some colour to your output"
:author "Josh Comer <joshjcomer@gmail.com>"}
cljcolour)
(def black {:fore "02;30" :back "02;40"})
(def red {:fore "02;31" :back "02;41"})
(def green {:fore "02;32" :back "02;42"})
(def yellow {:fore "02;33" :back "02;43"})
(def blue {:fore "02;34" :back "02;44"})
(def purple {:fore "02;35" :back "02;45"})
@jjcomer
jjcomer / trollscript.clj
Created September 11, 2011 20:25
Trollscript interpreter in Clojure
(ns trollscript.core
(:use [clojure.string :only [lower-case]])
(:gen-class))
(def MAX_CELLS 30000)
(defn split-code
"Splits the string into its trollscript commands"
[raw-code]
(->> raw-code
@jjcomer
jjcomer / median.clj
Created January 29, 2012 11:53
Median Finding Algorithms
(ns median.core
(:use [clojure.math.numeric-tower :only [floor ceil]]))
(defn rand-list
"Generates a random vector of length n with unique
values inclusive 1 to exclusive n"
[n]
(shuffle (map inc (range n))))
(defn- median-skeleton
@jjcomer
jjcomer / analysis.clj
Created January 29, 2012 12:02
Analysis of my Median Finding Algorithms
(ns median.analyze
(:use [median core]
[incanter core charts datasets stats]))
(defn test-lists
"Generate test lists applying f to p and n"
[n p f]
(map #(rand-list (f p %)) (range n)))
(defmacro time-it
@jjcomer
jjcomer / columns.clj
Created August 8, 2012 00:38
Ordering columns
(def c-order
(let [order [:id :title :author :date :price]]
(zipmap order (range (count order)))))
(defn column-sort
[k1 k2]
(compare (get c-order k1 -1)
(get c-order k2 -1)))
(def test-data