Skip to content

Instantly share code, notes, and snippets.

@bsless
bsless / README.md
Created August 31, 2023 12:44
Clojure app startup performance

Why

Simple experiment to test the effects of different techniques and options on application start up time

Class Data Sharing (CDS)

The goal of CDS is to reduce the startup time of the JVM by loading from a pre-processed archive of Java classes and JVM metadata that is used during the initialization process. https://dev.java/learn/jvm/cds-appcds/

Clojure compiler options

see

Meta elision

(defn stateful-map
"Returns a stateful transducer similar to `clojure.core/map-indexed` that
transforms each item with `(f state <the item>)` where `state` is built by
applying `state-building-fn` to the previous state (starting with `init`) and
the transformed item.
Ex., re-implementing map-indexed:
```clojure
(sequence (stateful-map vector (fn build-state [idx _] (if idx (inc idx) 5))) \"abc\")
; => ([nil \\a] [5 \\b] [6 \\c])
@roman01la
roman01la / clojurescript-repl-workflow.md
Last active October 22, 2022 12:07
ClojureScript REPL Workflow

ClojureScript REPL Workflow

Short write up on using REPL when developing UIs in ClojureScript.

Hot-reload on save or Eval in REPL?

Everyone's standard approach to hot-reloading is to use a tool (Figwheel or shadow-cljs) that reloads changed namespaces automatically. This works really well: you change the code, the tool picks up changed files, compiles namespaces and dependants, notifies REPL client which then pulls in compiled changes, and re-runs a function that re-renders UI.

The other approach is to use ClojureScript's REPL directly and rely only on eval from the editor. This more or less matches Clojure style workflow. This approach might be useful when you don't want tools overhead or hot-reloading becomes slow for you or you just used to this style of interactions. Also changing code doesn't always mean that you want to reload all the changes. On the other hand it is very easy to change a couple of top-level forms and forget to eval one of them.

@ericnormand
ericnormand / 00_script.clj
Last active May 18, 2024 08:30
Boilerplate for running Clojure as a shebang script
#!/bin/sh
#_(
#_DEPS is same format as deps.edn. Multiline is okay.
DEPS='
{:deps {clj-time {:mvn/version "0.14.2"}}}
'
#_You can put other options here
OPTS='

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@reborg
reborg / rich-already-answered-that.md
Last active May 8, 2024 14:20
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

@danielpcox
danielpcox / deep-merge-spec.clj
Created March 11, 2015 21:21
Simple, recursive deep-merge in Clojure.
(ns deep-merge-spec
(:require [midje.sweet :refer :all]
[util :as u]))
(fact (u/deep-merge {:one 1 :two 2}
{:one 1 :two {}})
=> {:one 1 :two {}})
(fact (u/deep-merge {:one 1 :two {:three 3 :four {:five 5}}}
{:two {:three {:test true}}})
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@john2x
john2x / 00_destructuring.md
Last active April 23, 2024 13:18
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences