Skip to content

Instantly share code, notes, and snippets.

Dealing with platform specific code

Sometimes you need to modifiy code depending on which target it is running in. Say you are writing a :browser app but parts of the code should also work in :react-native. The way I deal with this by abstracting out the relevant bits and either providing separate implementations of a protocol or just plain functions.

Interface code

;; shared ns that defines the "interface"
;; with actual implementation added later
(ns my.app.env)

How Clojure's documentation can leapfrog other languages

Summary

I made a documentation generator that cashes in on Clojure's dynamism. See the play-cljs docs (a ClojureScript game library) for an example of its output.

The Problem

Like many of you, I've often wondered what my final regret will be on my deathbed. My best guess came to me in a dream recently. I was walking across the charred earth of an apocalyptic future world, maneuvering around the remains of the less fortunate. I was startled to find a young girl, barely holding onto her life. She murmured something to me. I asked her to repeat it, and she said more loudly: "I...wish your Clojure projects didn't have such crappy documentation."

@spencerduncan
spencerduncan / sc2ainotes.txt
Created November 5, 2016 18:03
Note from SC2 AI panel - Blizzcon 2016
Basics of deep learning
______________
/ observations\
| |
V |
agent environment
| ^
| actions |
\______________/
@taylorSando
taylorSando / transact.clj
Created May 19, 2016 14:21
A way of enforcing transactions
(ns datomscript.model
(:require #?@(:clj [[datomic.api :as d]
[clojure.tools.logging :as log]])
#?@(:cljs [[datascript.core :as d]])
[clojure.string :as string]
[clojure.walk :as walk]))
(def vconcat (comp vec concat))
(defn get-model [models model-type]
@ah45
ah45 / nested_map_zipper.clj
Created March 6, 2015 13:04
Editing Nested Maps from the bottom up with Clojure Zippers
(ns nested-map-zipper
(:require [clojure.zip :as zip]
[clojure.data :refer [diff]]))
(defmacro recur-if
([expr]
`(recur-if ~expr nil))
([expr else]
`(let [temp# ~expr]
(if temp# (recur temp#) ~else))))
@kornysietsma
kornysietsma / wikiparse.clj
Last active January 2, 2021 18:41
parsing wikipedia dumps in clojure
(ns wikiparse.core
(:require [clojure.java.io :as io]
[clojure.data.xml :as xml]
[clojure.zip :refer [xml-zip]]
[clojure.data.zip.xml :refer [xml-> xml1-> text]])
(:import [ org.apache.commons.compress.compressors.bzip2 BZip2CompressorInputStream])
(:gen-class :main true))
(defn bz2-reader
"Returns a streaming Reader for the given compressed BZip2