Skip to content

Instantly share code, notes, and snippets.

Paul deGrandis ohpauleez

Block or report user

Report or block ohpauleez

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ohpauleez
ohpauleez / vimrc
Created Dec 21, 2018
Using Clojure SocketREPL with a simple vimscript setup
View vimrc
"Clojure stuff
let g:clojure_srepl_port = 5555
let g:clojure_srepl_host = "127.0.0.1"
function! VisualNC() range
let n = @n
silent! normal gv"ny
"echo "". @n
echo "" . system("script=$(cat <<'EOF'\n" . @n . "\nEOF\n); echo -n $script | nc " . g:clojure_srepl_host . " " . g:clojure_srepl_port)
let @n = n
" bonus: restores the visual selection
@ohpauleez
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
ohpauleez / example.jloj
Created Nov 19, 2015
ML-like Java/Clojure Transpiler
View example.jloj
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 Sep 9, 2016
Capture blocks of Clojure code in the paste buffer for making Keynote presentations
View colorblock.sh
#!/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 Aug 29, 2015
Another debug repl
View debugrepl.clj
;; 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 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
[request]
(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
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.
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 Dec 11, 2015
An example of specifications-as-a-value.
View specs_example.clj
(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.
You can’t perform that action at this time.