Skip to content

Instantly share code, notes, and snippets.

View cgrand's full-sized avatar

Christophe Grand cgrand

View GitHub Profile
@cgrand
cgrand / gist:564d6e8ad57299f64beb438e4a8b709f
Created July 11, 2020 20:26 — forked from KingCode/gist:773560f4ab5bf91e660a2a26e581b036
cond-let and cond-let| macros, to leverage bindings between test and result expressions, as well as earlier ones (for cond-let)
;; (cond-let
;; (odd? x) [x n] (inc x)
;; (< n 10) [y (inc n)] 10
;; :else n))
;; we want the above to yield
;; (let [x n]
;; (if (odd? x)
;; (inc x)
(require '[clojure.string :as s])
;; Maze GENERATION
(defn north-of [[row col]] [(dec row) col])
(defn south-of [[row col]] [(inc row) col])
(defn west-of [[row col]] [row (dec col)])
(defn east-of [[row col]] [row (inc col)])
(defn neighbours [rows cols cell]
@cgrand
cgrand / foami.clj
Created September 22, 2017 16:02 — forked from ztellman/foami.clj
(ns foami.core
"FOreign Asynchronous Mechanism Interop"
(:require [clojure.core.async :as async]))
(defn put!
"Takes a `ch`, a `msg`, a single arg function that when passed `true` enables backpressure
and when passed `false` disables it, and a no-arg function which, when invoked, closes the
upstream source."
[ch msg backpressure! close!]
(let [status (atom :sending]
(ns mutabots
"Reimplementation of transducers, in terms of processing functions instead
of reducing functions.
tl;dr: reducing-fn based transducers are a special case, influenced by reducers,
of processing-fn based transducers.
In Clojure 1.7.0-alpha2, transducers are expressed in terms of the existing
concept of reducing functions.
To sum it up, a transducer has currently the signature :
@cgrand
cgrand / payload.json
Last active August 29, 2015 13:57 — forked from mamund/uber-doc.xml
{"user":
{"actions": {},
"properties":
{"givenName": "mike",
"faimlyName": "amundsen",
"email": "m...@example.org"}}}
(ns lein-script-test
(:require [ccw.util.eclipse :as e]))
(defn greet [context]
(e/info-dialog "Hello world"
"This popup provided to you from a user script"))
;; these two def* build the fragment using the provided symbol and the current ns
(defcommand greeter
:command-name "Greetings from CCW"
@cgrand
cgrand / gist:7638887
Last active December 29, 2015 07:49 — forked from laurentpetit/gist:7625561
(require '[ccw.util.e4 :as e4])
;; e is anything that can reach an IEclipseContext. Extend protocol e4/HasContext
;; to your type:
;(defprotocol HasContext
; "Protocol for retrieving the associated IEclipseContext for objects
; for which this makes sense."
; (-context [o] "Return the context for o, or nil"))
(def cmd-id "hello-6")
@cgrand
cgrand / 1a.md
Last active December 22, 2015 15:49

You can use id attributes suffixed by # within your HTML template code in order to generate :#id# selectors that you can later use within Enlive template.

For example, if you say:

<div id="content-main#"></div>

You can later reference it with :#content-main# selector, which will be automatically generated for you.

(defn tarjan-stepper
[graph]
(fn this
([[components seen :as state] node]
(if (contains? seen node)
state
(let [[components seen] (this components seen node)]
[(conj components (get seen node)) seen])))
([components seen node]
(reduce (fn [[components seen] subnode]
@cgrand
cgrand / gist:4655215
Last active December 11, 2015 20:28 — forked from anonymous/gist:4655172
cheap merge-with when you only need lookup
(defn cheap-merge-with
"Merges two maps-as-functions" [f a b]
(memoize (fn this
([k] (this k nil))
([k default]
(let [av (a k this)
bv (b k this)]
(if (identical? this av)
(if (identical? this bv)
default