Skip to content

Instantly share code, notes, and snippets.

View quoll's full-sized avatar
💭
Back to Asami

Paula Gearon quoll

💭
Back to Asami
View GitHub Profile
@quoll
quoll / complex.clj
Created May 22, 2012 14:36
Simple complex number code
(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")
@quoll
quoll / Complex.java
Created May 22, 2012 15:01
Java Mandelbrot test
package test;
public class Complex {
public final double real;
public final double imaginary;
public Complex(double r, double i) {
real = r;
imaginary = i;
}
@quoll
quoll / mandelbrot.clj
Created November 17, 2012 18:51
Mandelbrot in Clojure using Java 2D
(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]))
@quoll
quoll / CodePoint.java
Created May 21, 2013 17:07
Provides codepoint support as an extension to what java.lang.Character can do
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
*/
@quoll
quoll / gist:7593630
Created November 22, 2013 02:09
Diff to scan the heap
diff --git a/gherkin b/gherkin
index 073e926..06211ba 100755
--- a/gherkin
+++ b/gherkin
@@ -210,6 +210,20 @@ mark() {
done
}
+test_heap() {
+ local top
@quoll
quoll / turtles.clj
Created March 20, 2014 17:32
It's turtles all the way down!
(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();"
)))
@quoll
quoll / hello.clj
Created March 20, 2014 18:51
Calling JS functions
(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}))))
@quoll
quoll / matching.clj
Created May 9, 2014 03:28
Test if patterns from unrelated queries can match
(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]
@quoll
quoll / e31.clj
Created January 1, 2016 17:40
Euler31
(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))]))
@quoll
quoll / Hashtable.js
Last active August 31, 2016 14:46
Example Hashtable for WWCDC
// 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;