Skip to content

Instantly share code, notes, and snippets.

Christophe Grand cgrand

View GitHub Profile
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 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
@cgrand
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)))))
@cgrand
cgrand / gist:4038631
Created Nov 8, 2012 — forked from laurentpetit/gist:4038525
Memento du déroulé Agile Grenoble 2012
View gist:4038631
(ns agile.life
(:use [clojure.pprint :only [pprint]]))
;; cell representation
(pprint [2 2])
;; game state representation
#{[2 2] [3 2]}
;; game initial state ("blinker")
@cgrand
cgrand / clojure-match.clj
Created Sep 5, 2012 — forked from ckirkendall/clojure-match.clj
Language Compare F#, Ocaml, Scala, Clojure, Ruby and Haskell - Simple AST example
View clojure-match.clj
(use '[clojure.core.match :only [match]])
(defn evaluate [env [sym x y]]
(match [sym]
['Number] x
['Add] (+ (evaluate env x) (evaluate env y))
['Multiply] (* (evaluate env x) (evaluate env y))
['Variable] (env x)))
(def environment {"a" 3, "b" 4, "c" 5})
You can’t perform that action at this time.