Skip to content

Instantly share code, notes, and snippets.

@jackrusher
jackrusher / drei.cljs
Created January 30, 2019 13:35
Trying out the three.js + shadow-cljs workflow in clojurescript.
(ns drei
(:require [goog.object :as gobj]
["three" :as three]
["three-orbitcontrols" :refer (OrbitControls)]
["bezier-easing" :as BezierEasing]))
(defonce renderer
(let [rndr (three/WebGLRenderer. (js-obj "antialias" true))]
(.setPixelRatio rndr (.-devicePixelRatio js/window))
(.setSize rndr
@mfikes
mfikes / err-msgs.md
Last active December 1, 2018 10:08
WIP on ClojureScript Error Messages

Illustration of WIP on CLJS-2913 is in this branch: https://github.com/mfikes/clojurescript/tree/CLJS-2913-WIP

Here are examples exploring :clojure.error/phase :read-source, :macro-syntax-check, :macroexpansion, and :compile-syntax-check

ClojureScript:

$ clj -Srepro -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.10.0-RC2"} org.clojure/clojurescript {:git/url "https://github.com/mfikes/clojurescript" :sha "b43d38a9c7d8dea1438cb8762709d95a3b447d90"}}}' -m cljs.main
cljs.user=> (require 'cljs.core.specs.alpha)
nil
@bmaddy
bmaddy / README.md
Created September 12, 2018 14:45
piggie back issue
clj -R:nrepl -m nrepl.cmdline --middleware "[cider.piggieback/wrap-cljs-repl]"

in Emacs, cider-connect

user> (require '[oops.core :refer [oset!]])
nil
user> (oset! (js-obj) :mood "a happy camper")
IllegalStateException Can't change/establish root binding of: *cljs-warnings* with set  clojure.lang.Var.set (Var.java:223)
@mfikes
mfikes / README.md
Last active December 12, 2019 12:08
ClojureScript parameter type inference

This is a demo of experimental work into ClojureScript parameter type inference.

The work is in a branch, and if you'd like to try out any of this yourself, you can start up a REPL based on the experimental branch using the following command, and play along at home:

clj -Srepro -Sdeps '{:deps {github-mfikes/gist-1e2341b48b882587500547f6ba19279d {:git/url "https://gist.github.com/mfikes/1e2341b48b882587500547f6ba19279d" :sha "55d6c6e9a1c4fc9b58fec74aef1af4aba57bad2a"}}}' -m cljs.main -co @compile-opts.edn -re node -r

To date, all ClojureScript inference "flows" in a certain direction, essentially from primitive values or type-hinted locals to their use sites. For example, consider this expression:

@mfikes
mfikes / README.md
Last active March 8, 2019 12:11
cljs.main rebel-readline

Start cljs.main with rebel-readline:

clojure -Sdeps '{:deps {github-mfikes/cljs-main-rebel-readline {:git/url "https://gist.github.com/mfikes/9f13a8e3766d51dcacd352ad9e7b3d1f" :sha "27b82ef4b86a70afdc1a2eea3f53ed1562575519"}}}' -i @setup.clj -m cljs.main
@jmlsf
jmlsf / js-in-cljs.md
Last active January 25, 2024 23:15
Using JavaScript modules in ClojureScript

Using JavaScript Libraries from ClojureScript

Using JavaScript libraries from ClojureScript involves two distinct concerns:

  1. Packaging the code and delivering it to the browser
  2. Making ClojureScript code that accesses JavaScript libraries safe for advanced optimization

Right now, the only single tool that solves these probems reliably, optimally, and with minimal configuration is shadow-cljs, and so that is what I favor. In paricular, shadow-cljs lets you install npm modules using npm or yarn and uses the resulting package.json to bundle external dependencies. Below I describe why, what alternatives there are, and what solutions I disfavor at this time.

Packaging and Delivering Code

@darwin
darwin / totalfinder-diagnostics.md
Last active November 14, 2020 20:47
TotalFinder diagnostics
  1. Please open /Applications/Utilities/Terminal.app
  2. In the Terminal prompt copy&paste this line and hit return:
curl -sL https://updates.binaryage.com/diagnose-totalfinder.sh > /tmp/dtf.sh && bash /tmp/dtf.sh
  1. Please send the resulting file totalfinder-diagnostics.tar.gz (on Desktop) to support@binaryage.com
@bhauman
bhauman / ClojureScriptLoader.js
Created September 26, 2017 20:12
Loading a ClojureScript/Figwheel project with fetch instead of writing script tags.
/*
* This script provides an example of loading a ClojureScript project
* that has been compiled using optimizations level :none.
*
* There are many environments that might not support the default
* method of writing script tags to load files.
*
* I wrote this to solve the problem of loading compiled ClojureScript
* into Chrome extentions.
*

In the context of cljs-oss had success setting up Planck and triggering it to build with a specific version of ClojureScript. Here is a sketch:

  1. I changed Planck's project.clj to have a dep that can be driven by an environment variable: [org.clojure/clojurescript ~(or (System/getenv "CLOJURESCRIPT_VERSION") "1.9.660")]
  2. I added a minimal ".travis.yml-only" repo at https://github.com/cljs-oss/planck which clones and builds Planck and runs its tests
  3. For the sake of running it in Travis, I forked this repo to my own GitHub account, but this step is just an optional pragmatic bit for now
  4. I installed the travis client, logged in using a GitHub personal access token created for this purpose, and then had it give me a Travis API token
  5. I chose which ClojureScript version I wanted to trigger the Planck build with: body='{"request": {"branch":"master", "config": {"env": {"CLOJURESCRIPT_VERSION": "1.9.671"}}}}'
  6. I triggered the build: `curl -s -X POST -H "Content-Type: application/json" -H "
(ns v8.core
"
Start Chrome with:
google-chrome-beta --js-flags=\"--allow-natives-syntax\"
")
(defn v8
"Runs a v8 natives syntax command with eval."
([c]