Skip to content

Instantly share code, notes, and snippets.

View raek's full-sized avatar

Rasmus Bondesson raek

View GitHub Profile
@SrPeixinho
SrPeixinho / gist:3c34f66fd86f12af165f
Last active August 29, 2015 14:23
Syntax considered harmful
-- When your code grows too big for a line:
separateParens = foldr (\ head tail -> if head == '(' then head : ' ' : tail else if head == ')' then ' ' : head : tail else head : tail) []
-- Your natural instinct is to add new lines and comments:
separateParens =
foldr (\ head tail ->
if head == '('
then head : ' ' : tail -- inserts space after left parens
(defn unfold
"Next and done? are functions that operate on a seed. next should
return a pair, [value new-seed]; the value half of the pair is
inserted into the resulting list, while the new-seed is used to
continue unfolding. Notably, the value is never passed as an
argument to either next or done?."
[next done? seed]
((fn unfold*
[seed]
(lazy-seq
(defn enlive->hiccup [node]
(if-not (map? node)
node
(let [{:keys [tag attrs content]} node
children (map enlive->hiccup content)]
(if (empty? attrs)
(vec (cons tag children))
(vec (cons tag (cons attrs children)))))))
(defn hiccup->enlive [node]
(defn with-timeout [thunk]
(let [task (FutureTask. thunk)
thr (Thread. task)]
(try
(.start thr)
(.get task 10 TimeUnit/SECONDS)
(catch TimeoutException e
(.cancel task true)
(.stop thr (Exception. e))
nil))))
(ns libpsm.string
(:require [clojure.string :as str]))
(let [triml-with-pipe (comp #(str/replace-first % "|" "")
str/triml)]
(defn mstr*
"Multiline string with explicit left margin."
[s]
(str/join "\n" (map triml-with-pipe
(str/split-lines s)))))
@LauJensen
LauJensen / cells.clj
Created February 23, 2010 20:08 — forked from richhickey/cells.clj
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(set! *warn-on-reflection* true)