Skip to content

Instantly share code, notes, and snippets.

View vemv's full-sized avatar
🧑‍💻
Sprinting

vemv vemv

🧑‍💻
Sprinting
View GitHub Profile
@ghadishayban
ghadishayban / doseq.clj
Created April 24, 2016 05:19
doseq that doesn't blow up with too much bytecode, and w/o (fn []) thunks
(defmacro doseqs
[seq-exprs & body]
(let [stk (gensym "stack__")
level (gensym "level__")
seq-exprs (partition 2 seq-exprs)
bindings (vec (map first seq-exprs))
init-exprs (vec (map second seq-exprs))
nbinds (count init-exprs)
@mfikes
mfikes / iml.md
Last active January 5, 2020 22:31
Implicit Macro Loading

ClojureScript macros can be loaded using the :require-macros primitive in ns forms (or require-macros REPL special).

But, there is a shortcut you can take if a runtime namespace requires macros from its macro namepace file. This might be a bit tricky to understand so here is a concrete example.

Let's say you have a macro file:

$ cat src/foo/core.clj
(ns foo.core)
@timothypratley
timothypratley / forshame.md
Last active June 11, 2021 05:06
Error reporting in Clojure are the worst, no error reporting in ClojureScript is the worst.

For Shame!

Clojure error reporting is a problem. This gist contains examples of missed opportunities for a clear error message. Let's discuss how common scenarios can be improved, and get some "patch welcome" tickets out there with clearly defined expectations.

The problem

@gfredericks
gfredericks / with-local-redefs.clj
Last active November 30, 2022 15:30
thread-local version of with-redefs
(defn with-local-redefs-fn
[a-var its-new-value func]
(cast clojure.lang.IFn @a-var)
(alter-meta! a-var
(fn [m]
(if (::scope-count m)
(update-in m [::scope-count] inc)
(assoc m
::scope-count 1
::thread-local-var (doto (clojure.lang.Var/create @a-var)
@michalmarczyk
michalmarczyk / producer_consumer.clj
Created July 12, 2013 01:25
Single consumer, multiple producers in core.async
(use 'clojure.core.async)
(def output (atom []))
(defn producer [ctrl k]
(go (loop [i 0]
(when-let [c (<! ctrl)]
(>! c [k i])
(>! ctrl c)
(recur (inc i))))))
(ns async-test.core
(:require [cljs.core.async :refer [chan]]
[clojure.string :as string])
(:require-macros
[cljs.core.async.macros :as m :refer [go alt! alts!]]))
(def c (chan))
(def loc-div (.getElementById js/document "location"))
(.addEventListener js/window "mousemove"
@jneira
jneira / prior.clj
Last active December 18, 2015 07:18
tenemos una lista ordenada (por :priority) de objetos. debe poder accederse por índice (lo que al menos en clj, descarta la posibilidad de usar un set).
puede haber múltiples objetos con el mismo valor :priority.
[{:priority 1} {:priority 1} {:priority 3} {:priority 3} {:priority 3} {:priority 5} {:priority 5} {:priority 8} {:priority 8} {:priority 8}]
en mi dominio, cada objeto tiene más claves aparte de :priority, pero son irrelevantes en este problema.
lo que deseamos es un método que nos dé el índice de acceso de un elemento al azar, un azar influido por las prioridades.
digamos que dos objetos con la misma :priority tienen elegibilidad equiprobable,
@rodnaph
rodnaph / gist:5694439
Last active December 18, 2015 00:09
Datomic attribute schema fn with sane defaults.
(ns foo.schema
(:require [datomic.api :refer [tempid]]))
;; Datomic schema is wordy, so apply some sane defaults and allow overriding where needed.
(defn- attribute [ident & options]
(let [defaults {:db/id (tempid :db.part/db)
:db/ident ident
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
@jneira
jneira / Dyn.groovy
Last active December 16, 2015 11:29
def list=[1,"nan",new Whatever()] // neat!
def nan="nan"
def one=1
one+nan
"1nan"
one-nan
// No signature of method: java.lang.Integer.minus() is applicable for argument types: (java.lang.String)
Object nan2="nan2"
Object two=2
@ejackson
ejackson / gist:5203517
Last active March 14, 2020 08:09
Non-fiction, Non-textbook stories on How the West was Won, and where it got us
-----------= Tales of Yore =-----------
* Hackers: Heroes of the Computer Revolution
(http://www.amazon.co.uk/Hackers-Heroes-Computer-Revolution-Anniversary/dp/1449388396)
* The soul of a new machine
(http://www.amazon.co.uk/Soul-New-Machine-Tracy-Kidder/dp/0140062491/ref=sr_1_2?s=books&ie=UTF8&qid=1363772696&sr=1-2)
* The brainmakers
(http://www.amazon.co.uk/Brainmakers-Scientists-Moving-Beyond-Computers/dp/067151055X/ref=sr_1_1?s=books&ie=UTF8&qid=1363772724&sr=1-1)