Skip to content

Instantly share code, notes, and snippets.

@thheller
thheller / shadow-cljs.edn
Created June 1, 2017 05:52
webpack config written in CLJS
[{:id :webpack
:target :node-library
:output-to "webpack.config.js"
:exports config.webpack/exports
:devtools
{:enabled false}}]
;; then shadow-cljs --build webpack --dev|--once
;; webpack -d
@thheller
thheller / summary.md
Last active May 21, 2017 07:13
:advanced in a JS tool world

WIP - still working out the details

The Problem

The :npm-module build target currently means that you have to sacrifice the Closure Compiler :advanced compilation.

The :browser target already supports code-splitting but needs a lot of extra work to make use of NPM packages. The default solution CLJSJS provides a good integration story but doesn't scale well with the the number of NPM packages you want to use. The odds of importing code multiple times increase substantially with each package and that leads to excessive JS sizes.

The odds are pretty high that most CLJS builds that use a decent amount of JS code actually get bigger by using :advanced+:foreign-libs than they would otherwise be by using :npm-module + webpack -p.

CompilerException clojure.lang.ExceptionInfo: Call to clojure.core/let did not conform to spec:
In: [0] val: [{:keys [externs modules compiler compiler-options]} closure (.compileModules compiler externs (into [] (map :js-module) modules) compiler-options)] fails spec: :shadow.cljs.devtools.cljs-specs/bindings at: [:args :bindings] predicate: (even? (count %))
:clojure.spec/args ([{:keys [externs modules compiler compiler-options]} closure (.compileModules compiler externs (into [] (map :js-module) modules) compiler-options)] (update state :closure assoc :result result))
#:clojure.spec{:problems [{:path [:args :bindings], :pred (even? (count %)), :val [{:keys [externs modules compiler compiler-options]} closure (.compileModules compiler externs (into [] (map :js-module) modules) compiler-options)], :via [:shadow.cljs.devtools.cljs-specs/bindings :shadow.cljs.devtools.cljs-specs/bindings], :in [0]}], :args ([{:keys [externs modules compiler compiler-options]} closure (.compileModules compiler externs (into [
@thheller
thheller / map-spec.clj
Last active March 23, 2017 13:34
map-spec
(ns shadow.spec
(:require [clojure.spec :as s]
[clojure.pprint :refer (pprint)]
[clojure.walk :as walk]))
(s/def ::foo string?)
(s/def ::bar string?)
;; using deftype will break spec, must support IObj
(defrecord MapSpec [entries closed? defined-keys]

Keybase proof

I hereby claim:

  • I am thheller on github.
  • I am thheller (https://keybase.io/thheller) on keybase.
  • I have a public key whose fingerprint is 922C 14A8 C52C 5447 547B 9FB0 D7E5 0DB4 2B8F B7DE

To claim this, I am signing this object:

@thheller
thheller / repl.clj
Created November 26, 2016 14:33
find dependent names for namespace using shadow-build
;; [thheller/shadow-build "1.0.239"]
(require '[shadow.cljs.build :as cljs])
(-> (cljs/init-state)
(cljs/find-resources-in-classpath)
(cljs/find-dependent-names 'goog.testing.PseudoRandom))
@thheller
thheller / web-component-v1.cljs
Created November 20, 2016 09:19
create web-component v1 in cljs without class
(defn component []
(js/Reflect.construct js/HTMLElement #js [] component))
(set! (.-prototype component)
(js/Object.create (.-prototype js/HTMLElement)
#js {:connectedCallback
#js {:configurable true
:value
(fn []
(this-as this
@thheller
thheller / thread-dump.txt
Created March 23, 2016 09:32
Aleph leak
2016-03-23 10:30:43
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.72-b15 mixed mode):
"Attach Listener" #553 daemon prio=9 os_prio=0 tid=0x0000000001b2e800 nid=0x565b waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"manifold-pool-3-443" #552 daemon prio=10 os_prio=0 tid=0x00000000037a1800 nid=0x55cc waiting on condition [0x00007f57f01b5000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000006cdf03908> (a java.util.concurrent.SynchronousQueue$TransferStack)
@thheller
thheller / thread-dump-linux.txt
Last active March 10, 2016 11:11
aleph shutdown
2016-03-10 12:10:21
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.74-b02 mixed mode):
"Attach Listener" #42 daemon prio=9 os_prio=0 tid=0x0000000000dcc800 nid=0x68bb waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"DestroyJavaVM" #39 prio=5 os_prio=0 tid=0x00007f924c40b800 nid=0x664e waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"nioEventLoopGroup-3-1" #20 prio=10 os_prio=0 tid=0x00007f924c3e0800 nid=0x666b runnable [0x00007f92521c5000]
{:mode-name :ruby
:atom-scope ["source.ruby"
"source.ruby.rails.rjs"
"source.ruby.rails"
"source.erb"
"source.ruby.rspec"
"source.ruby.chef"]
:initial-config
[["ruby-linter.rubyExecutablePath" "/usr/bin/ruby"]
["ruby-rubocop.executablePath" nil]]