Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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")