Clojure
-
- Preserving map order array-map for the reader: Looks like no way to do it, about to invent something useing rewrite-clj
- Tracing Not very good: M-x cider-toggle-trace-var Want a ctrace like system, didn't I start bulding one? Or found one? Fuck. Ah: https://github.com/Cyrik/omni-trace
- Built-in tracing libraries Emacs Cider uses (cider.nrepl.middleware.trace/toggle-trace-var {:ns 'clj-http.client :sym 'post}) which uses cider.nrepl.inlined.deps.toolstrace.v0v8v0.clojure.tools.trace (!!!) which I guess uses clojure.tools.trace ??? Actual function patching done by clojure.tools.trace/trace-var* Add [org.clojure/tools.trace "0.8.0"]
- Run a repl from an uberjar ? Is this even possible? Is repl code included?
- A non-cider repl for test profile Something like: lein with-profile +test,+repl,-user repl
- find unused namespace requires lein eastwood "{:add-linters [:unused-namespaces]}" Other eastwood info: https://github.com/jonase/eastwood#unused-namespaces
- spit made useful (defn schpit [f content & options] (with-open [w (apply clojure.java.io/writer f options)] (binding [print-length nil] (clojure.pprint/pprint content w))))
- deploying to clojars https://github.com/clojars/clojars-web/wiki/Pushing > lein deploy clojars username: mtravers, pwd: see vault Note that versions have to be -SNAPSHOT, or else it requires gpg signing.
- [argh I need to deploy real ones] Maybe start gpg-agent ?
- lein new ? How the fuck do you get a list of templates? https://www.reddit.com/r/Clojure/comments/2qmrdk/finding_all_available_lein_templates/ OK this works kinda: https://clojars.org/search?q=lein-template
- Unauthorized Reflection
- Get all namespaces (clojure.lang.Namespace/all)
- Get a particular namespace (clojure.lang.Namespace/find 'nrepl.core)
- Get bindings for current namespace (.getMappings ns)
- Circular ref (how to get around namespace strict tree rules) ((eval 'system.reacharound) ...)
- Java reflection Shows all methods and like that (clojure.reflect/reflect <thing> :ancestors true) (and see multitool/dev/beany)
- call a private method See multitool.cljcore/invoke-private,
- Web stuff (prob should have a file of its own) See Way for my accumualted wisdom
- get listing of compojure routes Actually I think there is no way to do that!
- Performance tuning Use yourkit. There'a 15-day free trial On Mac, you start your app with something like java -agentpath:/Applications/YourKit-Java-Profiler-2022.3.app/Contents/Resources/bin/mac/libyjpagent.dylib -jar target/goddinpotty-2.0.1-standalone.jar resources/hyperphor-config.edn
- Get process ID: (.pid (java.lang.ProcessHandle/current))
- see reflection problems Add this to project.clj :global-vars {warn-on-reflection true} This generates warnings at complie time.
- jvisualvm
Free profiling tool, not present in all Java versions. Use
export JAVA_HOME=
/usr/libexec/java_home -v 11.0.8or whatever to find a working version. Get current PID (.pid (java.lang.ProcessHandle/current)) - JDK Mission Control Add this to project.clj: :jvm-opts ["-XX:StartFlightRecording=disk=true,dumponexit=true,filename=recording.jfr,maxsize=1024m,maxage=1d,settings=profile,path-to-gc-roots=true"] The use JDK Mission Control https://www.oracle.com/java/technologies/javase/products-jmc8-downloads.html (but I couldn't make it work, probably some JDK screw)
- Cider see file:emacs.org
- Getting the current pid (.pid (java.lang.ProcessHandle/current))
- Clojurescript
- General https://cljs.info/cheatsheet/
- Clojurescript complilation nitty gritty http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html
- Javscript object to cljs map Short way, but not the best: (defn jsx->clj [x] (into {} (for [k (.keys js/Object x)] [k (aget x k)]))) https://stackoverflow.com/questions/32467299/clojurescript-convert-arbitrary-javascript-object-to-clojure-script-map
- How do you make a JS component? Ie https://plnkr.co/edit/bOIp5VLEaJfFBeTV?preview function DetailCellRenderer() { } DetailCellRenderer.prototype.init = function (params) { this.initialIds = params.initialIds; this.masterGridApi = params.api; this.masterRowAccountNo = params.data.account; this.masterNode = params.node.parent; this.detailRowSelectedHandler = params.detailRowSelectedHandler; protocols! https://github.com/clojure/clojurescript/wiki/Working-with-Javascript-classes
- interop
- getting obejct's class (type x)
- Fucking re-frame dev tools, how do you make them show up when they don't want to? day8.reframe10x.showpanelBANG_(true)
- Useful libraries
- Hashp p for debugging https://github.com/weavejester/hashp
- Hotloading https://github.com/clojure/tools.deps.alpha No actually that doesn't seem to do hotloading. The doc is so bad I can't figure out what it does. Ah maybe this: https://github.com/clj-commons/pomegranate
- Non-lein projects
- Install
- cljsjs, boot, etc
- Deploy locally boot package install target
- Deploy to github How to set up ~/.m2/settings.xml https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry Password needs to be a github personal access token with the right perms https://github.com/settings/tokens/387023693 https://samritchie.io/publishing-cljsjs-jars-to-clojars/ boot package push --ensure-release --repo github --repo-map "{:url \"https://github.com/parkerici/mvn-packages/\" :username \"mtravers\" :password \"...\"}"
- How to make errors show up in logs that is, undo that "Full report at: " bullshit :profiles {k :dev {:jvm-opts ["-Dclojure.main.report=stderr" ]}}
- Referring to a non-exported symbol
- Inspect compilation results Haven't actually tried this: https://github.com/gtrak/no.disassemble
- shadow-cljs Very mysterious. If it acts up, delete .shadow-cljs (lein clean should do this) Externs (I've used the "covering the last few percent" technique) https://code.thheller.com/blog/shadow-cljs/2017/10/15/externs-the-bane-of-every-release-build.html
- Normal lein shadow watch app
- REPL Much too much of a pain. Looks like you can't have both repl and auto-compile running which is of course what you want. 1) quit any shadow process running 1.5) lein shadow compile app (if it isn't current) 2) lein shadow cljs-repl app 3) Reload web page with app 4) You are in Note: for testing things, lumo is very convenient
- web stuff See ammdi:Way https://clojure-doc.org/articles/ecosystem/web_development/
- extend printer/reader I just want to make my stupid time objects printable/readable. https://clojuredocs.org/clojure.core/print-method Oh weird, I didn't know about this: https://clojure.org/reference/reader#tagged_literals data_readers.clj
- do a defn in a namespace other than the current one intern (intern 'com.hyperphor.way.handler 'wrap-no-read-eval (fn [h] (fn [req] (h req))))
- Defmulti has defonce semantics https://www.reddit.com/r/Clojure/comments/zypzr7/why_cant_defmulti_be_repl_friendly_by_default/ TODO write a macro that makes this saner for multitool
- WANT way to import and redefine a file/namespac https://claude.ai/share/55d0c1ab-caf3-4d7e-be5e-41cf8bf68a08 Apparently impossible in cljs, potemkin might work for clj. Bleah. https://github.com/clj-commons/rewrite-clj/blob/main/doc/design/01-merging-rewrite-clj-and-rewrite-cljs.adoc#potemkin-import-vars Gah this is the kind of thing I hate about clojure, in CL this shit would not be an issue at all.
- seqs → str (str seq) doesn't work on LasySeqs, which are common. Use pr-str or one of its brethren
- Clay (in clojure civitas) (use-package clay) M-x clay-start M-x clay-make-ns-html supposed to generate html and view in browser, doesn't? M-x jack-in (require '[scicloj.clay.v2.api :as clay]) (clay/make! {:single-form '(str "fuck" "my life")}) (clay/make! {:source-path "src/scicloj/cfd/dataviz/interactivevisualization.clj"}) Note: don't close the clay window once its created
- Switching Java sdk use java 25.0.1-oracle Or in Emacs/Cider (setenv "JAVA_HOME" "/Users/mt/.sdkman/candidates/java/25.0.1-oracle")