Skip to content

Instantly share code, notes, and snippets.

@ohpauleez
ohpauleez / fs.clj
Created December 17, 2012 05:59
This is a preview of my experiments using the Alloy Language and Verifier in Clojure. The goal is to use one common, open spec backend to generate: test.generative tests, core.contract constraints, Alloy specs, extra documentation, etc
(ns sterling.example.filesystem.fs
(:require [clojure.walk :as cwalk]))
;; Overview
;; ==========
;;
;; A common example is to illustrate Alloy's abilities is a simpel filesystem.
;;
;; Below is a pure Clojure implementation of the same system, with the same
;; checks.
@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 / 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)
@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
(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)
(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.
(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 / 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 */