Skip to content

Instantly share code, notes, and snippets.

View raek's full-sized avatar

Rasmus Bondesson raek

View GitHub Profile
(defproject my-proj "0.1.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]]
:dev-dependencies [[swank-clojure "1.2.1"]])
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>How to get started with Clojure in Emacs</title>
<style>
body {
font-family: sans-serif;
width: 800px;
(deftest single-are-style
(testing "prefix, command and single parameter"
(let [result (msg/parse ":source COMMAND param")]
(are [key val] (= (get result key) val)
:source "source"
:command "COMMAND"
:params ["param"]))))
(deftest multiple-is-style
(testing "prefix, command and single parameter"
(ns se.raek.quirclj.message
(:refer-clojure :exclude [format])
(:use [clojure.contrib.def :only [defvar-]]))
(declare parse-params)
(defvar- message-regex
#"^(?::([^ ]+) +)?([^ ]+)(?: +(.+))?$")
(defn parse [s]
datatype Term = Var of string
| Abs of string * Term
| App of Term * Term
fun replace (Var v) x y = if v = x then y else Var v
| replace (Abs (v, t)) x y = Abs (v, replace t x y)
| replace (App (l, t)) x y = App (replace l x y, replace t x y)
fun eval (App (Abs (p, b), x)) = eval (replace b p x)
| eval (App (App a, x)) =
(ns se.raek.validator
"A library for validating the values of maps.
This library is build around the concept of validators. A validator is a
function that takes a value and returns non-nil if it was valid and nil if
it was invalid. The non-nil value can be the same as the given value or a
processed version of it. For example, an integer validator might work as
follows (demonstrating validators' normalizing functionality):
(defn integer-validator [x]
@raek
raek / web.clj
Created September 29, 2010 18:38
(ns se.raek.lcug.web-example
(:use [net.cgrand.moustache :only [app]]
[ring.adapter.jetty :only [run-jetty]]))
(def messages (atom ()))
(def routes
(app
[""] "hi!"
["hello"] {:get [{:status 200
(defn file-stored
"Creates an instance of ref-type with its value loaded from, and on changes
automatically stored in the file with the filename."
[ref-type filename]
(let [r (ref-type (read-string (slurp filename)))]
(add-watch r ::file-stored #(spit filename (pr-str %4)))
r))
(require 'paredit)
(eval-after-load 'paredit
'(progn (define-key paredit-mode-map (kbd "{")
'paredit-open-curly)
(define-key paredit-mode-map (kbd "}")
'paredit-close-curly)
(define-key paredit-mode-map (kbd "M-}")
'paredit-close-curly-and-newline)))
(use 'clojure.walk)
(defn prefix-thingy [form]
(let [counter (atom -1)]
(postwalk (fn [x]
[(swap! counter inc) x])
form)))
;; (prefix-thingy [[:a :b] [:c :d]])
;; --> [6 [[2 [[0 :a] [1 :b]]] [5 [[3 :c] [4 :d]]]]]