Skip to content
View obfuscated.clj
(let [f #(->> \o byte (iterate dec) (drop %) first char), a 5, b 3, c 13, x 2, y 0] (symbol (apply str (flatten [(f (inc y)) (repeat (* a b) (f y)) (f (* a c)) (f (* x x b)) (f (* c y)) (f x)]))))
(let [f #(->> \o byte (iterate dec) (drop %) first char)
a 5
b 3
c 13
x 2
y 0]
View some-let.clj
(defmacro some-let [bindings body]
(let [[x y & rest] bindings]
`(if-let [~x ~y]
~(if (empty? rest)
`(some-let ~(vec rest)
(some-let [a 1
b (inc a)
View wrap-flash.clj
(defn wrap-flash [handler]
(fn [request]
(let [old-flash (-> request :session :_flash)
request (cond-> request
(some? old-flash)
(assoc :flash old-flash))
response (handler request)
new-flash (:flash response)]
(some? new-flash) (assoc-in response [:session :_flash] new-flash)

Best practices in Clojure, part 1

How to require and name stuff


View css.clj
(is (= (str ".content{color:black}"
"@media (max-width: 960px){.content{background:#fff}.content div{width:640px;margin:1em}}"
".content a{color:red}"
".content a span,.content a font{color:blue}"
".content h3{font-size:200%;margin:2em 0;margin-bottom:0}")
{:color "black"}
["@media (max-width: 960px)"
{:background "#fff"}
let () =
let person = match Array.to_list Sys.argv with
| [_; x] -> x
| [_] | _ -> "stranger"
Printf.printf "hi, %s\n" person
View Enum Example.swift
enum Router: URLRequestConvertible {
static let baseURLString = ""
static var OAuthToken: String?
case MapView(Int)
case PhotoInfo(Int, ImageSize)
case Comments(Int, Int)
var URLRequest: NSURLRequest {
let (path: String, parameters: [String: AnyObject]) = {
View gist:55e75827a6b795e4507d
class ObserverSetEntry<Parameters> {
weak var object: AnyObject?
let f: AnyObject -> Parameters -> Void
init(object: AnyObject, f: AnyObject -> Parameters -> Void) {
self.object = object
self.f = f
View fancy-call.clj
(defn testfn [bar foo]
[:retval foo bar])
(defn fancy-call [f m]
(let [args (->> f meta :arglists first (map keyword))
params (map m args)]
(apply f params)))
(is (= [:retval :a :b]
(fancy-call #'testfn {:foo :a :bar :b})))
View choose.vim
" find file in git repo
function! ChooseFile()
let dir = expand("%:h")
if empty(dir) | let dir = getcwd() | endif
let root = system("cd " . dir . " && git rev-parse --show-toplevel")
if v:shell_error != 0 | echo "Not in a git repo" | return | endif
let root = root[0:-2]
let selection = system("cd " . root . " && git ls-files -co --exclude-standard | choose")
Something went wrong with that request. Please try again.