This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns test.complex | |
"A simple complex number library") | |
(defprotocol ComplexOp | |
(abs [this] "The absolute value of the number") | |
(abs2 [this] "The absolute value squared of the number") | |
(plus [this ^Complex that] "Adds another number") | |
(times [this ^Complex that] "Multiplies by another number") | |
(minus [this ^Complex that] "Subtracts another number") | |
(divide [this ^Complex that] "Divides by another number") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
public class Complex { | |
public final double real; | |
public final double imaginary; | |
public Complex(double r, double i) { | |
real = r; | |
imaginary = i; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns test.mandelbrot | |
"Simple Mandelbrot generator. | |
Trying to optimize. Pulling apart math operations." | |
(:gen-class) | |
(:use [test.complex :only (abs2 times plus)]) | |
(:import [test.complex Complex] | |
[java.awt Graphics Color Dimension] | |
[java.awt.event KeyListener KeyEvent] | |
[java.awt.image BufferedImage] | |
[javax.swing JPanel JFrame SwingUtilities])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util; | |
import java.util.*; | |
/** | |
* This method fills in where java.lang.Character can't manage 21 bit Unicode. | |
* Represents Unicode Scalar Values, U+0000 to U+10FFFF | |
* | |
* @author Paul Gearon | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/gherkin b/gherkin | |
index 073e926..06211ba 100755 | |
--- a/gherkin | |
+++ b/gherkin | |
@@ -210,6 +210,20 @@ mark() { | |
done | |
} | |
+test_heap() { | |
+ local top |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns turtles | |
(import [javax.script ScriptEngineManager])) | |
(defn -main [& args] | |
(let [e (.getEngineByName (ScriptEngineManager.) "nashorn")] | |
(.eval e | |
"var Clojure = Java.type('clojure.java.api.Clojure'); | |
var hello = Clojure.var('turtles', 'hello'); | |
hello.invoke();" | |
))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hello | |
(import [javax.script ScriptEngineManager])) | |
(def e (.getEngineByName (ScriptEngineManager.) "nashorn")) | |
(def js-print (.eval e "print")) | |
(defn call | |
[f & args] | |
(.eval e "f.apply(null, args)" (doto (.createBindings e) (.putAll {"f" f "args" args})))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn v? [x] (and (symbol? x) (= \? (first (name x))))) | |
(defn bnd-for [bindings other-bindings k] | |
(if-let [v (bindings k)] | |
(loop [b1 bindings, b2 other-bindings, cv v, subv (other-bindings v)] | |
(if-not subv | |
cv | |
(recur b2 b1 subv (b1 subv)))))) | |
(defn compatible? [x y] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def denoms [200 100 50 20 10 5 2 1]) | |
(def c (count denoms)) | |
(defn calc | |
"Return count for combinations, starting at the index for a given size denomination" | |
[ndx value] | |
(if (zero? value) | |
1 | |
(->> (range ndx c) | |
(map (fn [n] [n (- value (denoms n))])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Duplicates the String hashcode method in Java | |
function hashCode(str) { | |
var hash = 0, i, chr, len; | |
if (str.length === 0) return hash; | |
for (i = 0, len = str.length; i < len; i++) { | |
chr = str.charCodeAt(i); | |
hash = ((hash << 5) - hash) + chr; | |
hash |= 0; // Convert to 32bit integer | |
} | |
return hash; |
OlderNewer