Skip to content

Instantly share code, notes, and snippets.

View maacl's full-sized avatar

Martin Clausen maacl

View GitHub Profile
;;framework.clj
;;...
(definterface ES
(putIfAbsent [k v])
(rep [k old-val new-val])
(get [k]))
(defn ^ES jes []
(let [m (atom {})]
(reify ES
@maacl
maacl / gist:2399054
Created April 16, 2012 14:09
Nathan University Lesson 2.2
var reverse = function(expr) {
var make_node = function(t, left, right) {
return {tag: t,
left: left,
right: right};
};
if (expr.tag == 'note') {
return expr;
}
return make_node(expr.tag,
@maacl
maacl / gist:1654089
Created January 21, 2012 21:27
AST Paths
[
Object
id: "invoice_no"
path: Array[4]
0: "statements"
1: "1"
2: "id"
3: "original"
length: 4
__proto__: Array[0]
@maacl
maacl / core.clj
Created August 25, 2011 20:57
ringerfinger
(ns rf-test.core
(:use (ringfinger core resource fields db auth auth-routes), ringfinger.db.inmem,
ringfinger.timesavers.hooks,
ring.util.serve))
(make-user inmem :ringfinger_auth {:username "test"} "demo" "salt")
(defresource contacts
{:db inmem
:pk :name_slug
@maacl
maacl / gist:1141943
Created August 12, 2011 12:32
Silly Chat errors
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)
Timestamp: Fri, 12 Aug 2011 12:45:11 UTC
Message: 'undefined' is null or not an object
Line: 643
Char: 2
Code: 0
(fn [f i] (map (fn [n] ((apply comp (take n (repeat f))) i)) (range)))
@maacl
maacl / project.clj
Created April 1, 2011 17:30
project.clj example using contexts and cake deploy.
(defproject +project+ "0.0.1-SNAPSHOT"
:description "TODO: Write project description"
:main +project+.core
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[enlive "1.0.0-SNAPSHOT"]
[net.cgrand/moustache "1.0.0-SNAPSHOT"]
[ring/ring-core "0.3.0"]
[ring/ring-jetty-adapter "0.3.0"]
[ring/ring-devel "0.3.0"]
@maacl
maacl / gist:894901
Created March 30, 2011 18:04
Example from page 186 in Practical Clojure
(defprotocol Payroll
(paycheck [emp hrs]))
(defrecord HourlyEmployee [name rate]
Payroll
(paycheck [hrs] (* rate hrs)))
Fails with:
java.lang.IllegalArgumentException: Can't define method not in interfaces: paycheck (NO_SOURCE_FILE:13)
@maacl
maacl / gist:877783
Created March 19, 2011 20:33
server.clj
(ns cmc.server
(:use net.cgrand.enlive-html
net.cgrand.moustache
somnium.congomongo
ring.util.response
[ring.middleware params multipart-params file reload session stacktrace]
[clojure.contrib logging]
[cmc templates handlers])
(:require [clojure.contrib.io :as io])
(:import [java.io File]))
@maacl
maacl / gist:877766
Created March 19, 2011 20:04
cmc-application
(def cmc-application
(app
(wrap-session)
(wrap-if development? wrap-reload '[cmc.templates])
(wrap-if development? wrap-stacktrace)
;; set application root
(wrap-if development? wrap-file "resources")
["app" &]
(app