Skip to content

Instantly share code, notes, and snippets.

@ibdknox
ibdknox / todos.clj
Created August 3, 2011 16:31
noir todos ex
(ns todos.views.welcome
(:require [todos.views.common :as common]
[noir.content.pages :as pages]
[noir.response :as resp])
(:use noir.core
hiccup.core
hiccup.form-helpers
hiccup.page-helpers))
(defonce todos (atom {1 "Get milk"
@ibdknox
ibdknox / server.sh
Created August 4, 2011 06:13
example daemon for lein processes
#!/bin/bash
name=webnoir
pidfile=/var/run/$name.pid
if [ -f "$pidfile" ]; then
pid=`cat $pidfile`
running=`ps p $pid |wc -l`
if [ $running -eq 1 ]; then
pid=
@ibdknox
ibdknox / force-realized.clj
Created September 23, 2011 01:36
Slow cljs loops
(ns cljs-test.client)
(defn now []
(. (js/Date.) (getTime)))
(let [nums (doall (range 0 1000000))
start (now)]
(doseq [n nums]
)
(. js/console (log (- (now) start))))
@ibdknox
ibdknox / tests.clj
Created September 23, 2011 23:13
simple speed tests
(ns cljs-test.client)
(defn now []
(. (js/Date.) (getTime)))
(let [nums (doall (range 0 1000000))
start (now)]
(doseq [n nums]
)
(. js/console (log (str "pre-seq: " (- (now) start)))))
@ibdknox
ibdknox / alephNoir.clj
Created October 2, 2011 19:53
aleph and noir
(require '[noir.server :as server])
(use 'noir.core 'aleph.http 'lamina.core)
(defn async-response [response-channel request]
(enqueue response-channel
{:status 200
:headers {"content-type" "text/plain"}
:body "async response"}))
(defpage "/" [] "hey from Noir!")
@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"
@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 / 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 / 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 / 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))))