Skip to content

Instantly share code, notes, and snippets.

Christophe Grand cgrand

View GitHub Profile
View maze-generation
(require '[clojure.string :as s])
(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
{"actions": {},
{"givenName": "mike",
"faimlyName": "amundsen",
"email": ""}}}
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")

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
(fn this
([[components seen :as state] node]
(if (contains? seen node)
(let [[components seen] (this components seen node)]
[(conj components (get seen node)) seen])))
([components seen node]
(reduce (fn [[components seen] subnode]
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)
cgrand / answer.clj
Last active Dec 11, 2015 — forked from laurentpetit/gist:4538379
Optimisons sans trahir
View answer.clj
; original
(defn best-plan [bids]
(first (vals (reduce (fn [plans {:keys [DEPART VOL DUREE PRIX]}]
(assoc plans DEPART
(max-key #(:gain % 0) (first (vals plans))
(let [[[_ {:keys [gain path] :or {gain 0}}]]
(subseq plans >= (+ DEPART DUREE))]
{:gain (+ gain PRIX) :path (cons VOL path)}))))
(sorted-map) (sort-by :DEPART > bids)))))
You can’t perform that action at this time.