Skip to content

Instantly share code, notes, and snippets.

ohpauleez / vimrc
Last active Jun 24, 2021
Using Clojure SocketREPL with a simple vimscript setup
View vimrc
"Clojure stuff
let g:paredit_electric_return = 0
let g:clojure_highlight_local_vars = 0
let g:clojure_highlight_references = 0 " Toggle with :ToggleClojureHighlightReferences
let g:clojure_srepl_port = 5555
let g:clojure_srepl_host = ""
let g:clojure_require_preamble = "(set! *warn-on-reflection* true)" " These forms will be sent over srepl before a `require` is sent
let g:clojure_reload = ":reload" " This option is sent as an arg to `require`
let g:clojure_use_jobs = 0
let g:clojure_repl_job = {}
ohpauleez / interceptor.clj
Last active Jun 19, 2018
An example of how to make conditional interceptors that enqueue new interceptors
View interceptor.clj
;; Let's start with a simple conditional interceptor that works with functions...
(defn conditional-context
"Given a keyword name and any variable predicate and terminator function pairs,
return an interceptor that will apply the terminator function paired to the first
truthy predicate. Predicates and terminators are both given the context as
the only argument.
If all predicates fail, the original context is returned."
[name-kw & pred-terms]
ohpauleez / example.jloj
Created Nov 19, 2015
ML-like Java/Clojure Transpiler
View example.jloj
/* All declarations/statements are one-per-line; No semi-colon needed;
Comments are only multi-line;
Follow Java naming conventions */
/* If no package is found you'll be in the "user" package */
ohpauleez /
Last active Sep 9, 2016
Capture blocks of Clojure code in the paste buffer for making Keynote presentations
#!/usr/bin/env bash
## Given a Clojure source file, 'example.clj'
## Where the contents are captured by START and END comments like:
## ;;START SomeTagName
## (println (inc 2))
## ;;END
## Run this script: example.clj SomeTagName
ohpauleez / debugrepl.clj
Last active Aug 29, 2015
Another debug repl
View debugrepl.clj
;; Simpler debug-repl based on
;; This `debug-repl` also tries to capture line metadata from forms/files, as well as exceptions
;; Some people may want to rename `debug-repl` to `break`, and `quit-dr` to `continue`
(defmacro local-bindings
"Produces a map of the names of local bindings to their values."
(let [symbols (map key @clojure.lang.Compiler/LOCAL_ENV)]
(zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)))
ohpauleez / service.clj
Last active Aug 29, 2015
Pedestal 0.3.0 example with SSE
View service.clj
;; In Pedestal 0.3.1, you won't have to use an atom.
;; You'll pass the channel into the SSE creation function (instead of it passing one back to you)
(def event-ch (atom nil))
(defn home-page
(ring-resp/response "Hello World!"))
(defroutes routes
[[["/" {:get home-page}
View clclj_example.clj
(ns com.ndensity.clclj.example
(:require [com.ndensity.clclj :as clclj :refer [clfn]]))
(defn cube [n] ; if you don't type hint, it assumes int32 for all args & return types
(* n n n))
(def cube_cl (clfn* cube))
(def square-cl
(clfn [n]
(let [a (inc n)
ohpauleez / sample.clj
Last active Jan 25, 2017
The Leap Motion example code using the clojure-leap library
View sample.clj
(ns sample
(:require [clojure-leap.core :as leap]
[clojure-leap.hand :as l-hand]
[clojure-leap.pointable :as l-pointable :refer [tip-position]]))
(defn process-frame [frame]
(let [_ (println "Frame id:" (.id frame) "timestamp:" (.timestamp frame)
"hands:" (leap/hands frame) "fingers:" (leap/fingers frame) "tools:" (leap/tools frame))]
(when-let [hand (and (leap/hands? frame) (leap/hand frame 0))]
(let [fingers (leap/fingers hand)
View logicrels-lucene.clj
(ns lucenalog.core
"Lucenalog = Datalog interface to Lucene in 10 lines.
Simple but powerful.
(db/add (index) {:a \"foo\" :b \"bar\"})
to index a map with Lucene. Then you can use the relation
ohpauleez / specs_example.clj
Last active Dec 11, 2015
An example of specifications-as-a-value.
View specs_example.clj
(ns sterling.specs-example
(:require [clojure.core.specs :as spec]))
;; A preview of some Specifications.
;; Out of the box, a single spec can be used with:
;; test.generative, core.contracts, Typed Clojure, and Sterling (an interface to Alloy)
;; You're also free to extend the system however you need.