Skip to content

Instantly share code, notes, and snippets.

View jimfleming's full-sized avatar

Jim Fleming jimfleming

View GitHub Profile
(function() {
this.tmpl3 = function tmpl(str, data) {
var value = "var out = ''; out+=" + "'" +
str.replace(/[\r\t\n]/g, " ")
.replace(/'(?=[^%]*%>)/g,"\t")
.split("'").join("\\'")
.split("\t").join("'")
.replace(/<%=(.+?)%>/g, "'; out += $1; out += '")
.split("<%").join("';")
@eschulte
eschulte / neural-net.clj
Created November 10, 2010 22:13
Neural Network DSL
(ns neural-net.core) ; Copyright Eric Schulte, GPL V3
(defprotocol Neural
"Protocol implemented by any element of a neural network."
(run [this x] "Evaluates the net")
(train [this x y d] "Trains the net returning the updated net and deltas")
(collect [this key] "Collect key from the network")
(inputs [this] "Number of inputs")
(outputs [this] "Number of outputs")
(check [this] "Ensure that the number of inputs matches the outputs"))
@jimfleming
jimfleming / Array.js
Created November 10, 2010 16:19
Some useful array extensions (dependent on javascript 1.6)
Array.prototype.intersect = function(b) {
return this.filter(function(n) {
return (b.indexOf(n) != -1);
});
}
Array.prototype.diff = function(a) {
return this.filter(function(n) {
return !(a.indexOf(n) > -1);
});
function doHash(str, seed) {
var m = 0x5bd1e995;
var r = 24;
var h = seed ^ str.length;
var length = str.length;
var currentIndex = 0;
while (length >= 4) {
var k = UInt32(str, currentIndex);