Skip to content

Instantly share code, notes, and snippets.

View metametadata's full-sized avatar

Yuri Govorushchenko metametadata

View GitHub Profile
@mourjo
mourjo / with-local-redefs.clj
Last active October 10, 2023 13:25 — forked from gfredericks/with-local-redefs.clj
thread-local version of with-redefs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Commentary ;;
;; ;;
;; The goal for writing this started with the idea to have tests run in ;;
;; parallel using the leiningen plugin eftest ;;
;; https://github.com/weavejester/eftest. ;;
;; ;;
;; With tests using with-redefs, it was not possible to run them in ;;
;; parallel if they were changing the root binding of the same ;;
;; vars. Here, we are binding the root of the var to one function that ;;
@leonoel
leonoel / asyncawait.clj
Created December 6, 2018 20:17
cloroutine-based async/await
(ns asyncawait
(:refer-clojure :exclude [await])
(:require [cloroutine.core :refer [cr]]))
(defmacro async [& body]
`(js/Promise. (fn [s# f#]
(spawn (cr {await thunk}
(try (s# (do ~@body))
(catch :default e# (f# e#))))))))
@lilactown
lilactown / rebel.sh
Last active June 18, 2019 09:52
Start a Clojure(Script) REPL with rebel-readline and any other dependencies you want to include
# Add these to your .bash_profile / .zshrc / etc.
# Starts a Clojure repl
function rebel-clj() {
clojure -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version \"0.1.4\"} $@}}" -m rebel-readline.main
}
# Starts a browser REPL
function rebel-cljs() {
clojure -Sdeps "{:deps {com.bhauman/figwheel-main {:mvn/version \"0.1.7\"} com.bhauman/rebel-readline-cljs {:mvn/version \"0.1.4\"} $@}}" -m figwheel.main
@mfikes
mfikes / elide.md
Last active February 14, 2018 14:21
(Ab)using constant Boolean's for conditional compilation

The goal is to have the spec-related code conditionally elided from the below for prod builds:

(ns my-app.core
  (:require [clojure.spec.alpha :as s]
            [my-app.config :as config]))

(defn new-machine
  [opts]
@stuarthalloway
stuarthalloway / missing_keys_specs.clj
Created October 14, 2017 11:44
I think it would be a mistake to introduce temporal coupling to prevent typos.
;; I think it would be a mistake to introduce temporal coupling to prevent typos.
;; The example program below lets you identify "missing" keys specs at
;; the time and place of your choosing, and then handle them as you
;; deem appropriate, without imposing those decisions on other
;; users of spec.
(require '[clojure.spec.alpha :as s]
'[clojure.set :as set])
@pesterhazy
pesterhazy / 00-reagent-state-bidi-input.md
Last active July 16, 2017 01:45
Reagent input field experiments in bidirectional binding

Reagent state bidi input

This Gist demonstrates problems with synchronizing input fields in reagent.

Shows how to bind an atom to a remote state asychronously and bidirectionally

@reborg
reborg / rich-already-answered-that.md
Last active February 23, 2024 13:09
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
@briansunter
briansunter / clojure-protocol-redux.md
Created January 24, 2017 08:16
clojure spec multimethods as a better protocol

How can we extend functionality in Clojure without modifying the orignal source?

Let's say we want to computer the area of some Shape types like Square and Circle

We have multiple shapes all of which have an area function

We may have some function called sum-areas that takes a list of Shape , calls area on each of them, and sums them up. We don't have access to the original source, but want the ability to add new shapes.

@pesterhazy
pesterhazy / lumo-deps
Last active February 10, 2017 10:05
Run lumo with ClojureScript (maven) or JavaScript (npm) dependencies
#!/usr/bin/env python
#
# lumo-deps: lumo with JavaScript or ClojureScript dependencies
#
# Synopsis:
#
# lumo-deps [-c clojure-dep] [-j javascript-dep] [-- lumo-opt1 lumo-opt2 ...]
#
# Starts a lumo session with ClojureScript or JavaScript dependencies loaded.
#