Skip to content

Instantly share code, notes, and snippets.

View campeterson's full-sized avatar

Cam Peterson campeterson

View GitHub Profile
@alandipert
alandipert / with_conditions.clj
Last active March 18, 2016 18:26
inline pre/post conditions macro
(defmacro with-conditions
[conditions & body]
{:pre [(map? conditions)]}
(if-not *assert*
`(do ~@body)
(let [ret (gensym "ret")]
`(do ~@(for [pre (:pre conditions)]
`(when-not ~pre
(throw (ex-info "Precondition failed" {:pre '~pre}))))
(let [~ret (do ~@body)]
@jasongilman
jasongilman / atom_clojure_setup.md
Last active October 28, 2025 22:34
This describes how I setup Atom for Clojure Development.

Atom Clojure Setup

This describes how I setup Atom for an ideal Clojure development workflow. This fixes indentation on newlines, handles parentheses, etc. The keybinding settings for enter (in keymap.cson) are important to get proper newlines with indentation at the right level. There are other helpers in init.coffee and keymap.cson that are useful for cutting, copying, pasting, deleting, and indenting Lisp expressions.

Install Atom

Download Atom

The Atom documentation is excellent. It's highly worth reading the flight manual.

(ns seagent-ui.catan
(:require [reagent.core :as r]))
(defn dice-roll []
(+ (rand-nth [1 2 3 4 5 6])
(rand-nth [1 2 3 4 5 6])))
(defonce roll (r/atom (dice-roll)))
(defonce history (r/atom [@roll]))
(defonce players (r/atom ["P 1" "P 2" "P 3" "P 4"]))
@alandipert
alandipert / ec2query.boot
Last active July 31, 2018 16:33
Example of querying AWS infrastructure with Amazonica and Datomic, in Clojure with Boot-clj
#!/usr/bin/env boot
;; or `BOOT_FILE=ec2query.boot boot repl' for interactive use
(set-env! :dependencies '[[amazonica "0.3.23"]
[com.datomic/datomic-free "0.9.5344"]])
(require '[amazonica.aws.ec2 :as ec2]
'[amazonica.core :refer [defcredential]]
'[boot.cli :refer [defclifn]]
'[boot.util :refer [info]]
@marlabrizel
marlabrizel / get_in.rb
Last active December 22, 2015 03:33
Ruby version of clojure's get in method
def get_in(data, array)
if array.size > 1
key = array.shift
get_in(data[key], array)
else
return data.values.first
end
end
(defn define-node-repl-launcher []
(fn [handler]
(fn [fileset]
(defn node-repl []
(require 'cemerick.piggieback 'cljs.repl.node)
((resolve 'cemerick.piggieback/cljs-repl)
:repl-env ((resolve 'cljs.repl.node/repl-env))
:output-dir ".noderepl"
:optimizations :none
:cache-analysis true
@john2x
john2x / 00_destructuring.md
Last active September 24, 2025 00:52
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@vbatts
vbatts / Dockerfile
Last active August 29, 2015 14:00
Convenience function, for entering a fedora development environment, while in my current working directory
FROM fedora:20
RUN yum erase -y vim-minimal &&\
yum groupinstall -y "development tools" && \
yum install -y --setopt=override_install_langs=en --setopt=tsflags=nodocs \
yum-utils \
git \
golang \
mercurial \
bzr \
@danlentz
danlentz / flow-diagram.clj
Created February 26, 2014 06:53
Clojure ASCII flow diagrams from google code
;;;;;;;;;;;;;;;;;;
;; $Rev$
;; textflow is a trivial generator of RFC like call flow (a.k.a sequence diagrams)
;;
;; Example usage:
;; (flow [Alice Bob Tzach]
;; [[mmm Tzach Bob]
;; [xxx Bob Alice]
;; []
;; [zzz Alice Tzach]])
@tbatchelli
tbatchelli / scratchpad-cw2014.txt
Created January 25, 2014 03:13
Scratchpad proposal sent to Clojure/West 2014
Scratchpad: Code + everything needed to run it
———————————————————————
Scratchpad is a platform that lets you build scratchpads and run them
at the REPL. A scratchpad is a self-contained clojure file that includes
both code and everything needed to run it: library dependencies and
infrastructure.
Dependencies are expressed in lein-style and are downloaded and added
into the classpath when you load the scratchpad into the REPL. You can