Skip to content

Instantly share code, notes, and snippets.

Christophe Grand cgrand

Block or report user

Report or block cgrand

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cgrand
cgrand / gist:1236838
Created Sep 23, 2011 — forked from laurentpetit/gist:1233437
coding-dojo-20110921
View gist:1236838
; juste pour l'art
(defn primes []
(keep :prime
(iterate (fn [{:keys [known candidate]}]
(if (some #(zero? (rem candidate %)) known)
{:known known :candidate (inc candidate)}
{:known (conj known candidate) :candidate (inc candidate) :prime candidate}))
{:known [] :candidate 2})))
@cgrand
cgrand / gist:1877266
Created Feb 21, 2012 — forked from remleduff/gist:1876575
Simplified AST processing code from CinC
View gist:1877266
(use '[clojure.walk :only [walk]])
(def ^:dynamic ^:private *frame*)
(defn- new-frame [] (atom {}))
(defn- collect-frame [ast]
(case (:op ast)
:constant
{:constants [{:value (:form ast)}]}
@cgrand
cgrand / fib-seq-1.clj
Created Mar 6, 2012 — forked from scientific-coder/fib-seq-1.clj
Code snippets for Duchess-fr Battle Language 2012-02-29 test it on http://tryclj.com/ !
View fib-seq-1.clj
(def fib-seq
"lazy seq of Fibonacci numbers"
(lazy-cat [0 1] (map + (rest fib-seq) fib-seq)))
@cgrand
cgrand / fib-seq-1.clj
Created Mar 8, 2012 — forked from scientific-coder/fib-seq-1.clj
Code snippets for Duchess-fr Battle Language 2012-02-29 test it on http://tryclj.com/ !
View fib-seq-1.clj
(def fib-seq
"lazy seq of Fibonacci numbers"
(lazy-cat [0 1] (map + (rest fib-seq) fib-seq)))
View gist:2652814
(defn lein-env
"Create a new classlojure based leiningen environment by fetching all jars
and classes directories found inside the ccw.leiningen-core plugin."
[]
(let [leiningen-core (bundle-dir "ccw.leiningen-core")
jar (fn [f] (and (.isFile f) (.endsWith (.getName f) ".jar")))
classes-dir (fn [d] (let [manifest (io/file d "META-INF" "MANIFEST.MF")]
(and (.exists manifest)
(.isFile manifest))))
libs (->> leiningen-core file-seq (filter #(or (jar %) (classes-dir %))))]
@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})
@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 / 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: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
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]
You can’t perform that action at this time.