Skip to content

Instantly share code, notes, and snippets.

{
"causes": [
{
"class": "StackTrace",
"message": "Harmless user-requested stacktrace",
"stacktrace": [
{
"class": "cider.nrepl.middleware.debug$debug_stacktrace",
"file": "debug.clj",
"file-url": "jar:file:/C:/Users/Brandon/.m2/repository/cider/cider-nrepl/0.23.0/cider-nrepl-0.23.0.jar!/cider/nrepl/middleware/debug.clj",
(-->
id "10"
op "load-file"
session "64e65c43-5f14-49be-92f3-69ee17fdf9e1"
time-stamp "2020-02-22 19:18:55.390040000"
file "(ns clock)
(defn clock-parts [t]
#break
{:h (mod (quot ..."
file-name "clock.clj"
{
"stackFrames": [
{
"id": 0,
"source": {
"name": "readme.md",
"path": "C:\\Users\\Brandon\\Development\\mock-test/readme.md",
"sourceReference": 0,
"adapterData": "mock-adapter-data"
},
(-->
id "22"
op "eval"
session "1a2caeb6-3972-4310-9122-6c772f3087c8"
time-stamp "2020-02-21 12:08:51.989614012"
code "(defn sum-inc
[a b]
(inc
#break (+ a b)))
"
@bpringe
bpringe / cider-nrepl-coor-description.txt
Created February 21, 2020 02:37
Describes the `coor` field of a need-debug-input nrepl response from cider-nrepl middleware
COORDINATES is a list of integers that specify how to navigate into the
sexp that is after point when this function is called.
As an example, a COORDINATES list of '(1 0 2) means:
- enter next sexp then `forward-sexp' once,
- enter next sexp,
- enter next sexp then `forward-sexp' twice.
In the following snippet, this takes us to the (* x 2) sexp (point is left
at the end of the given sexp).
(letfn [(twice [x]
(* x 2))]
@bpringe
bpringe / cider-debug-middleware-response.json
Last active February 21, 2020 02:21
Response from cider-nrepl debug middleware after sending eval that calls code that has #break in it
{
"code": "(defn print-nums\r\n [n]\r\n (dotimes [i 10]\r\n #break\r\n (prn i)))",
"column": 0,
"coor": [
3,
2
],
"debug-value": "nil",
"file": "c:\\Users\\Brandon\\Development\\clojure-test\\src\\clojure_test\\core.clj",
"id": "4",

Getting Started with Clojure on Windows

Clojure is an amazingly powerful language. Using it (and watching Rich Hickey videos) has changed the way I think about programming, and the way I code in general. Once I learned the basics of the language, which was a relatively quick process, I fell in love and couldn't look back. I hope this post can help others who are new to Clojure get up and running quickly and painlessly.

This post is opinionated in the sense that I'll suggest certain tools to help those who are new to this scene get on their feet. The things you'll need are:

  • Leiningen (pronounced LINE-ing-en) - This is like a package manager, build tool, task manager, and more in one tool. Think npm or nuget, but with more capabilities. There is at least one other build tool for Clojure (boot), but Leiningen is the most widely used.
  • JDK - Clojure runs on Java. Throw out any qualms you may have about Java, we aren't coding in Java (though we can through Clojure, and sometimes tha
@bpringe
bpringe / Time.cs
Created December 12, 2018 22:10
Function to print time of operation and return result
public static T Time<T>(string op, Func<T> f)
{
var sw = Stopwatch.StartNew();
T result = f();
sw.Stop();
Console.WriteLine($"{op} took {sw.ElapsedMilliseconds} ms");
return result;
}
@bpringe
bpringe / calculate-hmac-signature.clj
Last active October 19, 2018 18:50
Calcuate HMAC signature. Substitute `algorithm` for other types. This worked for me for validating Facebook webhook payloads.
;; Make sure you import javax.crypto.Mac and javax.crypto.spec.SecretKeySpec
(defn get-signature
[message secret]
(let [algorithm "HmacSHA1"
signing-key (SecretKeySpec. (.getBytes secret) algorithm)
mac (doto
(Mac/getInstance algorithm)
(.init signing-key))
bytes->hex-str #(apply str (for [b %] (format "%02x" b)))]