Skip to content

Instantly share code, notes, and snippets.

View arichiardi's full-sized avatar

Andrea Richiardi arichiardi

View GitHub Profile
@bhauman
bhauman / figwheel-simple.cljc
Last active July 4, 2019 14:14
simple figwheel
(ns figwheel.simple
(:require
[clojure.string :as string]
#?@(:cljs [[goog.object :as gobj]])
#?@(:clj [[clojure.walk :as walk]
[cljs.repl.browser :as brow]
[cljs.repl :as repl]
[cljs.env :as env]
[cljs.analyzer :as ana]
[cljs.build.api :as bapi]
@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

@yannvanhalewyn
yannvanhalewyn / build.boot
Last active December 13, 2017 17:37
Boot node cljs repl
(set-env!
:target-path "target"
:source-paths #{"src"}
:dependencies '[[org.clojure/clojure "1.9.0-RC1"]
[org.clojure/clojurescript "1.9.946"]
[figwheel-sidecar "0.5.14"]])
(require '[figwheel-sidecar.repl-api :as ra])
(deftask cljs-repl []
@reborg
reborg / parallel-lazy-merge-sort.clj
Last active November 28, 2017 03:03
Clojure parallel-lazy merge-sort
;; PARALLEL LAZY MERGE-SORT
;; Allows large datasets (that would otherwise not fit into memory)
;; to be sorted in parallel on a single machine.
;; Data to fetch is identified by a range of IDs. IDs are split into
;; chunks that are sent in parallel to a fork-join thread pool
;; (using reducers). A protocol allows to define a policy to fetch
;; the data for the current ID range. The chunk is sorted and saved
;; to disk. A file handle is returned from each thread pointing at
;; a temp file containing the sorted chunk. The list of file handles

Code Splitting

NOTE: This gist uses the master branch of ClojureScript. Clone ClojureScript and from the checkout run ./script/bootstrap and ./script/uberjar. This will produce target/cljs.jar which you can use to follow this guide.

As client applications become larger it becomes desirable to load only the code actually required to run a particular logical screen. Previously ClojureScript :modules compiler option permitted such code splitting, but this feature only worked under :advanced compilation and users would still have to manage loading these splits. :modules also required manual

;; differences from scheme unfold
;; even initial value is lazy
;; predicate sense reversed
;; internal state == produced value, no special mapper-fn
;; no tail-gen
(defn series
"Produces a sequence of values.
`f` is a function that given a value, returns the next value.
`continue?` is a predicate that determines whether to produce
@cgrand
cgrand / demo.clj
Last active April 26, 2019 06:47
For toolsmithes really caring about isolation
;; Clojure 1.6.0
=> *clojure-version*
{:major 1, :minor 6, :incremental 0, :qualifier nil}
=> (def env1 (create-clojure-env))
#'net.cgrand.quarantine/env1
=> (env1 *in* *out*)
clojure.core=> *clojure-version*
{:major 1, :minor 8, :incremental 0, :qualifier nil}
clojure.core=>
@reborg
reborg / rich-already-answered-that.md
Last active January 23, 2025 22:49
A curated collection of answers that Rich gave throughout the history of Clojure

Rich Already Answered That!

A list of commonly asked questions, design decisions, reasons why Clojure is the way it is as they were answered directly by Rich (even when from many years ago, those answers are pretty much valid today!). Feel free to point friends and colleagues here next time they ask (again). Answers are pasted verbatim (I've made small adjustments for readibility, but never changed a sentence) from mailing lists, articles, chats.

How to use:

  • The link in the table of content jumps at the copy of the answer on this page.
  • The link on the answer itself points back at the original post.

Table of Content

@pesterhazy
pesterhazy / select.cljs
Last active December 10, 2022 03:17
Using react-select with reagent
;; in your project definition
;; [cljsjs/react-select "1.0.0-rc.1" :exclusions [cljsjs/react]]
;; See react-select documentation: https://github.com/JedWatson/react-select
(ns example.select
(:require [reagent.core :as r]
[cljsjs.react-select]))
(defn select
(ns cljs.stripe
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs.core.async :refer [<! chan put!]]
[oops.core :refer [gcall!]]))
; Stripe.piiData.createToken({
; personal_id_number: $('.personal_id_number').val()
; }, stripeResponseHandler);
; a simple wrapper