Skip to content

Instantly share code, notes, and snippets.

Avatar

Christophe Grand cgrand

View GitHub Profile
@cgrand
cgrand / gist:564d6e8ad57299f64beb438e4a8b709f
Created Jul 11, 2020 — 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)
View gist:564d6e8ad57299f64beb438e4a8b709f
;; (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)
View maze-generation
(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]
View 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]
View mutabots.clj
(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 :
View payload.json
{"user":
{"actions": {},
"properties":
{"givenName": "mike",
"faimlyName": "amundsen",
"email": "m...@example.org"}}}
View macros.clj
(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"
View gist:7638887
(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")
View 1a.md

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.

View gist:5116531
(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 Dec 11, 2015 — forked from anonymous/gist:4655172
cheap merge-with when you only need lookup
View gist:4655215
(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
You can’t perform that action at this time.