Skip to content

Instantly share code, notes, and snippets.

View laurentpetit's full-sized avatar

Laurent Petit laurentpetit

View GitHub Profile
@laurentpetit
laurentpetit / gist:1507832
Created December 21, 2011 21:39
FooBarQiz in Clojure
;; Note 1: in a real project, would have had 3 files: one for the code, one for the tests, one for the test data
;; Note 2: you can test online at http://tryclj.com/ : copy/paste the (do ...) encapsulating the 3 defs (lines 7 to 21).
;; Then hit Enter to evaluate. Then type (main), then hit Enter to evaluate.
(ns foobarqiz)
(do ;; trick to ease the use of copying/pasting into http://tryclj.com
(def data (sorted-map 7 "Qix", 5 "Bar", 3 "Foo"))
(defn serialize
@laurentpetit
laurentpetit / gist:1510229
Created December 22, 2011 12:58
FooBarQiz in Clojure with more decomposed steps
;; Note 1: in a real project, would have had 3 files: one for the code, one for the tests, one for the test data
;; Note 2: you can test online at http://tryclj.com/ : copy/paste the (do ...) encapsulating the 3 defs (lines 8 to 55).
;; Then hit Enter to evaluate. Then type (main), then hit Enter to evaluate.
(ns foobarqix
(:require [clojure.string :as str]))
(do ;; trick to ease the use of copying/pasting into http://tryclj.com
(def FBQ
(ns ^{:doc "Eclipse interop utilities"}
ccw.util.eclipse
(:require [clojure.java.io :as io])
(:import [org.eclipse.core.resources IResource
ResourcesPlugin]
[org.eclipse.core.runtime IPath
Path]
[org.eclipse.jdt.core IJavaProject]))
(extend-protocol io/Coercions
(ns ^{:doc "Eclipse interop utilities"}
ccw.util.eclipse
(:require [clojure.java.io :as io])
(:import [org.eclipse.core.resources IResource
ResourcesPlugin
IWorkspaceRunnable
IWorkspace]
[org.eclipse.core.runtime IPath
Path]
[org.eclipse.jdt.core IJavaProject]
Caused by: java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:421)
at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
at org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog.run(ProgressMonitorJobsDialog.java:275)
at org.eclipse.ui.internal.progress.ProgressManager$5.run(ProgressManager.java:960)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.progress.ProgressManager.busyCursorWhile(ProgressManager.java:995)
at org.eclipse.ui.internal.progress.ProgressManager.busyCursorWhile(ProgressManager.java:970)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
<h1>1. Installer et télécharger Eclipse For Java Developers:</h1>
http://eclipse.org/downloads/packages/eclipse-ide-java-developers/indigosr2
@laurentpetit
laurentpetit / gist:2490821
Created April 25, 2012 15:52
Ajout d'un visualiseur swing
;; Pour ajouter un visualiseur Swing
;;
;; 1. coller ce texte à la fin de votre namespace mixit.life
;; 2. evaluer
;; 3. demarrer un visualiseur swing :
;; (swing-board board 7 5)
;; 4. attention, la fenetre swing est peut etre cachee derriere votre fenetre Eclipse
;; 5. lancer l'animation en calculant 10 générations à partir de l'état init :
;; (play init 20)
@laurentpetit
laurentpetit / gist:2491305
Created April 25, 2012 17:00
Memento du déroulé mixit
(ns mixit.life
(:use [clojure.pprint :only [pprint]]))
;; cell representation
(pprint [2 2])
;; game state representation
#{[2 2] [3 2]}
;; game initial state ("blinker")
(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 %))))]
@laurentpetit
laurentpetit / gist:2912899
Created June 11, 2012 21:37 — forked from charles-dyfis-net/gist:2909106
clojure.osgi aware nREPL middleware
(defn classloader-handler
"Call cl-provider with the session each time a msg is sent.
The resulting classloader will then be used as context for executing msg."
[h cl-provider]
(fn [msg]
(let [classloader (cl-provider (:session msg))
dynamic-loader (and classloader (clojure.lang.DynamicClassLoader. classloader))]
(when dynamic-loader
(swap! (:session msg) assoc clojure.lang.Compiler/LOADER dynamic-loader))
(h msg))))