Skip to content

Instantly share code, notes, and snippets.

.collapsible button.collapsible-collapse-handle:after {
content: "►";
}
.collapsible.collapsed button.collapsible-collapse-handle:after {
content: "▼";
}
.collapsible .collapsible-collapse-handle {
(define (atom? x) (not (pair? x)))
(define wrong 'wait)
(define the-false-value (cons "false" "boolean"))
(define (evaluate e env)
(if (atom? e)
(cond ((symbol? e) (lookup e env))
((or (number? e) (string? e) (char? e) (boolean? e) (vector? e))
e)
(else (wrong "Cannot evaluate" e)))
@dpsutton
dpsutton / source.el
Created November 11, 2019 05:24
find source and display
(defun cider-tooltip-source ()
(interactive)
(let* ((sym (thing-at-point 'symbol))
(response (cider-nrepl-send-sync-request
(list "op" "eval"
"code"
(format
"(do (require 'clojure.repl) (with-out-str (clojure.repl/source %s)))"
sym)))))
(when-let ((source (nrepl-dict-get response "value")))
while inotifywait -e modify -r .
make test
end
(ns app.main
(:require ["react-dom" :as rdom]
[helix.core :as hx :refer [defnc $ <>]]
[helix.dom :as d]
[helix.hooks :as hooks]
[clojure.core.async :as a :refer [go-loop]]))
(defnc greeting
"A component which greets a user."
[{:keys [name]}]
@dpsutton
dpsutton / future-utils.clj
Last active May 17, 2020 16:58
ghadi's completeable future helpers from slack
(defn ->Function
[f]
(reify java.util.function.Function
(apply [_ obj] (f obj))))
(defn future-map
[cf f]
(.thenApply cf (->Function f)))
(defn future->ch
([cf]
(future->ch cf (async/chan 1) true))
(reify FileVisitor
(visitFile [_ p attrs]
(let [f (.relativize src p)
last-mod (Files/getLastModifiedTime p (make-array LinkOption 0))]
(when *verbose* (println (str (.toString src) "/" (.toString f))))
(with-open [is (Files/newInputStream p (make-array OpenOption 0))]
(copy! (.toString f) is (.resolve dest (.toString f)) last-mod)))
FileVisitResult/CONTINUE)
(preVisitDirectory [_ p attrs]
(Files/createDirectories (.resolve dest (.toString (.relativize src p)))
;; thanks ghadi from #clojure.beginners
(defn into-str
"reduce coll into a String, given a transducer"
[xf coll]
(transduce (comp xf (map str))
(fn
([] (StringBuilder.))
([^StringBuilder sb] (.toString sb))
([^StringBuilder sb s] (.append sb ^String s)))
(let (defcustoms)
(dolist (file (directory-files "/Users/dan/projects/dev/cider" t "\.el"))
(unless (string-match-p "dir-locals" file)
(with-current-buffer (find-file file)
(goto-char (point-min))
(while (re-search-forward "defcustom" nil t)
(let ((custom (substring-no-properties (progn (paredit-forward 1)
(thing-at-point 'sexp))))
(docstring (substring-no-properties (progn (paredit-forward 2)
(or (thing-at-point 'sexp)
;; ‘C-x r s <register-key>’ save to register
;; 'C-c C-j x <register-key' to send to repl
(defun cider-insert-register-contents (register)
(interactive (list (register-read-with-preview "From register")))
(let ((form (get-register register)))
;; could put form into a buffer and check if its parens are
;; balanced
(if form
(cider-insert-in-repl form (not cider-invert-insert-eval-p))
(user-error "No saved form in register"))))