Skip to content

Instantly share code, notes, and snippets.

@bhb
bhb / struct_repro.zig
Last active March 24, 2023 23:06
Confusion related to zig pointers and structs
const std = @import("std");
// zig version: 0.11.0-dev.2249+dcdb87836
/////////////////////////////////////////////
// zig run -O Debug struct_repro.zig
// rand 1 0.47344332933425903
// rand 1 0.3766399025917053
// rand 2 0.6770572662353516
@bhb
bhb / clojure_m1.md
Last active September 15, 2022 00:50
How to set up Clojure on M1 using Homebrew: A thread

How to set up Clojure on M1 using Homebrew: A thread

I’m upgrading from a Mid 2014 MacBook Pro, so this isn’t a fair comparison to recent Intel machines, but if you’re like me and were waiting for a MacBook with a decent keyboard, you’ll see a big speed boost.

Non-scientific comparison - time to compile my ClojureScript project

  • Mid 2014 MacBook Pro - 14s
  • M1 Pro MacBook Pro (under Rosetta) - 17s
  • M1 Pro MacBook Pro (native) - 6s
data = [{"name":"Radiohead","albums":[{"title":"The King of Limbs","songs":[{"title":"Bloom","length":"5:15"},{"title":"Morning Mr Magpie","length":"4:41"},{"title":"Little by Little","length":"4:27"},{"title":"Feral","length":"3:13"},{"title":"Lotus Flower","length":"5:01"},{"title":"Codex","length":"4:47"},{"title":"Give Up the Ghost","length":"4:50"},{"title":"Separator","length":"5:20"}],"description":"\n\tThe King of Limbs is the eighth studio album by English rock band Radiohead, produced by Nigel Godrich. It was self-released on 18 February 2011 as a download in MP3 and WAV formats, followed by physical CD and 12\" vinyl releases on 28 March, a wider digital release via AWAL, and a special \"newspaper\" edition on 9 May 2011. The physical editions were released through the band's Ticker Tape imprint on XL in the United Kingdom, TBD in the United States, and Hostess Entertainment in Japan.\n "},{"title":"OK Computer","songs":[{"title":"Airbag","length":"4:44"},{"title":"Paranoid Android","length":"
[{"loan":{"id":1,"borrower_id":1,"amount":10984659,"term":120},"period":{"start_at":"2017-05-22T00:00:00-06:00","end_at":"2017-06-21T23:59:59-06:00"},"principal":57702,"interest":83752,"rate_annual":900,"service_fee":{"amount":0,"rate":0}},{"loan":{"id":1,"borrower_id":1,"amount":10984659,"term":120},"period":{"start_at":"2017-06-22T00:00:00-06:00","end_at":"2017-07-21T23:59:59-06:00"},"principal":56262,"interest":80629,"rate_annual":900,"service_fee":{"amount":0,"rate":0}},{"loan":{"id":1,"borrower_id":1,"amount":10984659,"term":120},"period":{"start_at":"2017-07-22T00:00:00-06:00","end_at":"2017-08-21T23:59:59-06:00"},"principal":58577,"interest":82877,"rate_annual":900,"service_fee":{"amount":0,"rate":0}},{"loan":{"id":1,"borrower_id":1,"amount":10984659,"term":120},"period":{"start_at":"2017-08-22T00:00:00-06:00","end_at":"2017-09-21T23:59:59-06:00"},"principal":59026,"interest":82428,"rate_annual":900,"service_fee":{"amount":0,"rate":0}},{"loan":{"id":1,"borrower_id":1,"amount":10984659,"term":120},"peri
@bhb
bhb / tempids.clj
Created May 13, 2019 02:17
Dependent effects with tempids
[{:op :create-company
:name "Foobar Company"
:id "tempid/company"}
{:op :create-employee
:name "Alice"
:company_id "tempid/company"
:id "tempid/user1"}
{:op :create-employee
:name "Bob"
:company_id "tempid/company"
Run this to launch REPL
rlwrap clj -Srepro -Sdeps '{:deps {speculative {:mvn/version "0.0.3"} expound {:mvn/version "0.7.2"} org.clojure/test.check {:mvn/version "0.9.0"} org.clojure/clojurescript {:mvn/version "1.10.520"}}}' -e "(require '[expound.alpha :as expound] '[cljs.core.specs.alpha]) (set! clojure.spec.alpha/*explain-out* (expound/custom-printer {:print-specs? false :show-valid-values? true :theme :figwheel-theme}))" -m cljs.main -re node
Then run this in REPL
(require '[expound.alpha :as expound] '[cljs.core.specs.alpha] '[speculative.instrument :as i]) (i/instrument) (set! cljs.spec.alpha/*explain-out* (expound/custom-printer {:print-specs? false :show-valid-values? true :theme :figwheel-theme}))
@bhb
bhb / cljs_1_10_339.cljs
Created February 9, 2019 02:18
Custom explain-out with different versions of CLJS
;; Note this uses clojure 1.9, not 1.10 like other examples
;; clj -Srepro -Sdeps '{:deps {org.clojure/test.check {:mvn/version "0.9.0"} org.clojure/clojure {:mvn/version "1.9.0"} org.clojure/clojurescript {:mvn/version "1.10.339"}}}' --main cljs.main --repl
in cljs.main --repl
(require '[cljs.spec.alpha :as s])
(require '[cljs.spec.test.alpha :as st])
(require '[clojure.core.specs.alpha])
;; instrumenting a function
(s/fdef foobar :args (s/cat :x int?))
@bhb
bhb / ex.clj
Last active November 25, 2018 23:37
Replacing default spec printer for experimentation
;; launch with
;; clj -Srepro -Sdeps '{:deps {org.clojure/test.check {:mvn/version "0.9.0"} org.clojure/clojure {:mvn/version "1.10.0-beta8"}}}'
(require '[clojure.spec.alpha :as s])
(require '[clojure.spec.test.alpha :as st])
;; instrumenting a function
(s/fdef foobar :args (s/cat :x int?))
(defn foobar [x] x)
@bhb
bhb / init.cljs
Last active November 7, 2018 03:26 — forked from borkdude/init.cljs
Speculative + Expound in Klipse
(require '[cljs.spec.alpha :as s])
(require '[cljs.spec.test.alpha :as stest])
(require '[expound.alpha :as expound])
(require '[speculative.core])
(set! s/*explain-out* (expound/custom-printer {:show-valid-values? true}))
(stest/instrument `map)
(try
(map 'lol 'lol)
(catch :default e
(println (.-message e))))
@bhb
bhb / ex.txt
Created September 29, 2018 13:00
Interpreting `:in` paths in `clojure.spec`
> clj -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.10.0-alpha8"}}}'
Clojure 1.10.0-alpha8
user=> (require '[clojure.spec.alpha :as s])
nil
user=> ;; `explain-data` returns a description of the problem, including the `:in` path
user=> ;; which is the location of the invalid data within the context of the larger
user=> ;; data structure
user=> (-> (s/explain-data (s/coll-of int?) [1 "2"]) ::s/problems first)
{:path [], :pred int?, :val "2", :via [], :in [1]}
user=> (-> (s/explain-data (s/coll-of int?) [1 "2"]) ::s/problems first :in)