Skip to content

Instantly share code, notes, and snippets.

@ibdknox
ibdknox / clojure-mode.js
Created January 8, 2013 03:18
better clj mode
/**
* Author: Hans Engel
* Branched from CodeMirror's Scheme mode (by Koh Zi Han, based on implementation by Koh Zi Chun)
*/
CodeMirror.defineMode("clojure", function () {
var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", CHAR = "char",
ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD = "keyword";
var INDENT_WORD_SKIP = 2;
function makeKeywords(str) {
@ibdknox
ibdknox / core.clj
Created December 27, 2012 20:49
example of how to handle relation maps.
(defn rel-map
[ent sub-ent type opts]
(assoc-in ent [:rel (:name sub-ent)]
(delay
(create-relation ent sub-ent type opts))))
(defmacro has-one
"Add a has-one relationship for the given entity. It is assumed that the foreign key
is on the sub-entity with the format table_id: user.id = address.user_id
Opts can include a key for :fk to explicitly set the foreign key.
@ibdknox
ibdknox / activeline.html
Created December 4, 2012 19:17
CodeMirror V3 refresh doesn't calculate max line
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Active Line Demo</title>
<link rel="stylesheet" href="../lib/codemirror.css">
<script src="../lib/codemirror.js"></script>
<script src="../mode/xml/xml.js"></script>
<link rel="stylesheet" href="../doc/docs.css">
@ibdknox
ibdknox / project.clj
Created December 28, 2011 15:44
Noir 1.2.2 project supposed to work on Tomcat 6 (but doesn't)
(defproject lyrionch "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:dependencies [[org.clojure/clojure "1.3.0"]
[noir "1.2.2"]
[korma "0.2.1"]
[mysql/mysql-connector-java "5.1.18"]]
:ring {:handler lyrionch.server/handler}
:main lyrionch.server)
@ibdknox
ibdknox / dude.clj
Created December 26, 2011 22:33
dude example
(def my-dirs [:north :north :east :east :south :south :west :west])
(defn moves [& dirs]
(doseq [d dirs]
(println "Moving:" d)
(move d)))
(apply moves my-dirs)
@ibdknox
ibdknox / testing.clj
Created December 16, 2011 18:25
testing sessions
(defpage "/blah/:n" {:keys [n]}
(session/put! :b n))
(deftest session-vals
(with-noir
(session/put! :b 3)
(render "/blah/:n" {:n 1})
(is (= (session/get :b) 1))))
@ibdknox
ibdknox / common.clj
Created November 27, 2011 18:16
example of specialized defpage
(defmacro mainpage [route params & body]
`(defpage ~route ~params
(common/main-layout
~@body)))
;;Or if you wanted to get really crazy, so that you don't have to duplicate that macro
;;you could write a macro that writes the macros for you:
(defmacro layout-page [name layout]
`(defmacro ~name [route# params# & body#]
@ibdknox
ibdknox / gist:1372466
Created November 17, 2011 05:43
lein templates
Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to clojure.lang.Named (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:5440)
at clojure.lang.Compiler.eval(Compiler.java:5391)
at clojure.core$eval.invoke(core.clj:2382)
at clojure.main$eval_opt.invoke(main.clj:235)
at clojure.main$initialize.invoke(main.clj:254)
at clojure.main$script_opt.invoke(main.clj:270)
at clojure.main$main.doInvoke(main.clj:354)
at clojure.lang.RestFn.invoke(RestFn.java:457)
at clojure.lang.Var.invoke(Var.java:377)
@ibdknox
ibdknox / ns.clj
Created November 3, 2011 07:46
ns example
(ns irc
(:import (java.net Socket)
(java.io PrintWriter InputStreamReader BufferedReader))
(:require 'clojure.contrib.duck-streams)
(:use [clj-time.core :only [in-secs interval epoch now]]))
@ibdknox
ibdknox / clj.vim
Created October 10, 2011 21:58
vimclojure
let vimclojure#HighlightBuiltins=1
let vimclojure#HighlightContrib=1
let vimclojure#DynamicHighlighting=1
let vimclojure#ParenRainbow=1
let vimclojure#WantNailgun = 1
let vimclojure#NailgunClient = "/users/chris/.vim/bundle/vimclojure-2.3.0/lib/ng"