Skip to content

Instantly share code, notes, and snippets.

View laurentpetit's full-sized avatar

Laurent Petit laurentpetit

View GitHub Profile
@laurentpetit
laurentpetit / gist:7625561
Last active December 29, 2015 05:59
Current status of experiments with Eclipse 4 for Clojure development of Counterclockwise.
(require '[ccw.util.e4 :as e4])
;; plumbing/kernel functions: no reflection, follows closely eclipse Application Model/Semantics,
;; no magic (no nice-to-have coercition, only the ones that make total sense)
;; , simple
;; porcelain/user functions: relax reflection constraint as appropriate, pay as you go (thus can depart from eclipse
;; semantics/Application Model), more fancy coercitions, etc.
;; , easy
(def cmd-id "hello-6")
(require '[ccw.util.e4 :as e4])
(def app (-> @e (e4/context-key :application)))
(def categories
{:window "org.eclipse.ui.category.window"})
(def model-service (-> @e (e4/context-key :model-service)))
(def command-service (-> @e (e4/context-key :command-service)))
(def category-window (first (filter #(= "org.eclipse.ui.category.window" (e4/element-id %)) (.getCategories app))))
(import '[org.eclipse.e4.ui.model.application.commands MCommand])
(def command (-> model-service
(.createModelElement MCommand)
@laurentpetit
laurentpetit / gist:7583340
Created November 21, 2013 15:17
`deffield` macro for automatically creating interop getter/setter function
(require '[clojure.string :as s])
(defn camelize [s]
(let [parts (s/split s #"-")
capitalize #(str (.toUpperCase (subs % 0 1)) (subs % 1))]
(apply str (map capitalize parts))))
(defn clj->setter [s] (str "set" (camelize s)))
(defn clj->getter [s & options]
@laurentpetit
laurentpetit / 0-new-down.clj
Last active December 23, 2015 10:19
Can you spot the bug in new-down?
(defn split "cs is a vector" [cs idx]
(when cs
[(subvec cs 0 idx) (cs idx) (subvec cs (inc idx))]))
(defn new-down
"Returns the loc of the child at index idx of the node at this loc, or
nil if no children. It is assumed that z/children returns systematically a vector"
{:added "1.0"}
[loc idx]
(when (z/branch? loc)
(defn make-parse-tree-node
[t children-vec]
(let [[combined count] (children-info children-vec)]
{:tag t
:content children-vec
:build-id *build-id*
:count count
:content-cumulative-count combined
:broken? (or (#{::unexpected :chimera} t)
(some #{::unexpected :chimera} (cons t (map :tag children-vec)))
(def dirs #{[0 1] [0 -1] [-1 0] [1 0]})
(defn subv [a b] (mapv - a b))
(defn addv [a b] (mapv + a b))
(defn are-neighbours? [a b]
(contains? dirs (subv a b)))
(defn valid-path
"returns a seq of all the next positions that are free
@laurentpetit
laurentpetit / gist:5460218
Last active December 16, 2015 15:59
#mixit13 - Tester ses idées

= symptomes

  • je le finirai plus tard
  • j'ai ca dans les cartons depuis un moment
  • je ne comprends pas pourquoi ca ne marche pas
  • le marché n'est pas prêt

Techniques : Lean Startup

  • Une startup cherche
  • Une société exécute
@laurentpetit
laurentpetit / gist:5359539
Last active December 16, 2015 02:00
Spécifications d'une API pour un serveur "proxy" du serveur mix-it pouvant renvoyer uniquement les entités nouvelles et modifiées plutôt que systématiquement la liste totale des entités.
;; API
;; Principe général:
;; - utiliser les appels de listes ( /api/members par ex., mais pas /api/members/78 )
;; - la granularité du diff est l'entité. On renvoie une entité en entier, ou pas du tout.
;; - Déjà suffisamment intéressant pour les perfs (et simple à exploiter), ou faut-il descendre plus bas ?
;; la premiere fois, faire la requete comme à l'habitude (?details=true mis pour l'exemple, il peut aussi être omis):
;; GET / http://www.mix-it.fr/api/members?details=true
;; le retour contient tous les éléments nouveaux, et un sha1 qu'il faudra fournir
@laurentpetit
laurentpetit / gist:5231432
Created March 24, 2013 11:07
What could cause this exception to be thrown by clojure.lang.Compiler.StaticMethodExpr ?
Caused by: java.lang.IllegalArgumentException: No matching method: createAsIfByAssoc, compiling:(clojure/core.clj:3970)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6462)
at clojure.lang.Compiler.analyze(Compiler.java:6262)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6443)
at clojure.lang.Compiler.analyze(Compiler.java:6262)
at clojure.lang.Compiler.analyze(Compiler.java:6223)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5618)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5054)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3674)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6453)
@laurentpetit
laurentpetit / gist:5165928
Last active December 14, 2015 23:29
ccw.util.launch wraps JDT launcher. lein is an example of a generic leiningen launcher based on ccw.util.launch.
(ns ccw.leiningen.launch
(:require [ccw.util.launch :as launch]
[ccw.util.eclipse :as e]))
(defn lein [project command]
(let [launch {
:private true
:java/project-name (e/project-name project)
:java/classpath [{:entry-type :archive
:path "/Users/laurentpetit/.lein/self-installs/leiningen-2.0.0-preview10-standalone.jar"}