Skip to content

Instantly share code, notes, and snippets.

View danielneal's full-sized avatar

Daniel Neal danielneal

View GitHub Profile
(require 'faces)
(require 'color)
(require 'dash)
(unless (require 'xterm-color nil t)
(require 'ansi-color))
(defvar rainbow-keys-font-lock-keywords
'((":\\([-a-zA-Z0-9\\$\\?\\_\\*\\!\\.]+\\)/\\([-a-zA-Z0-9\\$\\?\\_\\*\\!]+\\)"
(2 (colorize-ns-keyword 2)))
(ns compound.core
(:refer-clojure :exclude [get-in update-in assoc-in]))
(def ^:private index-permutations
(memoize
(fn permutations [coll]
(if (= 1 (count coll))
(list coll)
(for [head coll
tail (permutations (disj (set coll) head))]
@danielneal
danielneal / Compound.clj
Last active July 28, 2017 16:02
A micro denormalised index for reframe
(ns compound.core
(:require [clojure.spec :as s]
[clojure.set :as set]
[clojure.test :as test :refer [deftest is]]))
(defn find-index-def [index-defs index]
(some #(when (= (:index %) index) %) index-defs))
(defn index-unique
"Like set/index, but for unique indexes, so the vals are just maps, not
@danielneal
danielneal / compound2.clj
Created July 30, 2017 16:27
A micro structure for your data
(ns compound.core)
(def ^:private meta-index-defs
[{:id :id
:index-fn :id
:unique? true}
{:id :unique?
:index-fn :unique?
:unique? false}])
(ns compound.core
(:require [clojure.spec.alpha :as s]))
(s/def ::address
int?)
(s/def ::compound
(s/cat :m map? :v vector?))
@danielneal
danielneal / events.cljs
Last active September 7, 2017 11:47 — forked from qleguennec/events.cljs
(rf/reg-event-fx
:auth
(fn [{:keys [db]} _]
{:POST
{:url "https://api.intra.42.fr/oauth/token"
:on-success [:auth/response-received]
:on-fail :auth-nok
:params
{:grant_type "client_credentials"
:client_id "secret"
(rf/reg-fx
:POST
;; on-success is a reframe event vector [:foo/bar ...]
(fn [{:keys [url params on-success on-fail]}]
(take! (http/post url {:form-params params})
;; conj the results into it so the response gets put into the event
;; like this:
;; [:foo/bar <result>]
#(re-frame.core/dispatch (conj on-success %)))
@danielneal
danielneal / compound4.clj
Last active September 21, 2017 14:43
Compound 4
(ns compound9.core
(:refer-clojure :exclude [get]))
(defmulti add
(fn [index-primary indexes index-def items]
(clojure.core/get index-def :compound.index/type)))
(defmulti remove
(fn [index-primary indexes index-def items]
(clojure.core/get index-def :compound.index/type)))
(ns compound.indexes
(:require [clojure.set :as set]))
(defprotocol IIndexPrimary
(-get-primary [this ks])
(-add [this items])
(-remove [this ks]))
(defprotocol IIndexSecondary
(-get-secondary [this ks])
@danielneal
danielneal / portpid
Created October 26, 2017 08:13
portpid
# Show the process that is listening on the port
portpid () {
lsof -i 4tcp:$1 -sTCP:LISTEN -Fp | cut -c 2-
}
# thanks @bronsa