Skip to content

Instantly share code, notes, and snippets.

@ohpauleez
ohpauleez / vimrc
Last active June 24, 2021 14:30
Using Clojure SocketREPL with a simple vimscript setup
"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 = "127.0.0.1"
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
ohpauleez / interceptor.clj
Last active June 19, 2018 01:35
An example of how to make conditional interceptors that enqueue new interceptors
;; 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
ohpauleez / example.jloj
Created November 19, 2015 16:13
ML-like Java/Clojure Transpiler
package one.one.one.one
/* 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
ohpauleez / colorblock.sh
Last active September 9, 2016 15:24
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: colorblock.sh example.clj SomeTagName
@ohpauleez
ohpauleez / debugrepl.clj
Last active August 29, 2015 14:17
Another debug repl
;; Simpler debug-repl based on https://github.com/stuarthalloway/circumspec/blob/master/src/clojure/contrib/debug.clj
;; 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
ohpauleez / service.clj
Last active August 29, 2015 14:03
Pedestal 0.3.0 example with SSE
;; 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
[request]
(ring-resp/response "Hello World!"))
(defroutes routes
[[["/" {:get home-page}
(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
ohpauleez / sample.clj
Last active January 25, 2017 19:33
The Leap Motion example code using the clojure-leap library
(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)
(ns lucenalog.core
"Lucenalog = Datalog interface to Lucene in 10 lines.
Simple but powerful.
Use
(db/add (index) {:a \"foo\" :b \"bar\"})
to index a map with Lucene. Then you can use the relation
@ohpauleez
ohpauleez / specs_example.clj
Last active December 11, 2015 01:58
An example of specifications-as-a-value.
(ns sterling.specs-example
(:require [clojure.core.specs :as spec]))
(comment
;; 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.