Skip to content

Instantly share code, notes, and snippets.

View christianromney's full-sized avatar
🏠
Working from home

Christian Romney christianromney

🏠
Working from home
View GitHub Profile
@christianromney
christianromney / edn.cljx
Created August 24, 2017 19:19 — forked from Deraen/edn.cljx
Transit / edn date/datetime serialisers
(ns metosin.common.edn
#+clj
(:require [clj-time.format :as f])
#+cljs
(:require [cljs-time.format :as f]
cljs.reader)
#+clj (:import [org.joda.time DateTime LocalDate]))
;;
;; #DateTime tagging
;; This buffer is for Clojure experiments and evaluation.
;; Press C-j to evaluate the last expression.
(fn trapezoid [v]
(let [row (fn [v]
(-> (vector (first v))
(into (map #(reduce +' %) (partition 2 1 v)))
(conj (last v))))]
(lazy-seq (cons v (trapezoid (row v))))))
@christianromney
christianromney / core.clj
Last active November 30, 2016 16:19
A handy little Clojure utility function to print the members of an object.
(defn inspect
"Reflects the members of an object and prints them. Returns the
number of members on the object. Constructors are labeled
with [ctor], public members are prefixed with +, private members are
prefixed with -, and static members are listed as Class/member.
Fields are annotated as fieldName : type, functions have a parameter
list enclosed in parentheses (param1, param2) followed by an arrow
-> and the return type. Varargs have an elipsis following the last
param (params...)."
[x]
(defmacro <!?
"Exception-aware parking take. If a Throwable is returned
from the channel, it is re-thrown."
[c]
`(let [v# (<! ~c)]
(if (instance? Throwable v#)
(throw v#)
v#)))
(defmacro <!!?
(deftask overwrite
[f file VAL str "The path of the file to overwrite"
w with VAL str "The file containing the source content"]
(with-pre-wrap fs
(let [{:keys [file with]} *opts*
src-file (tmp-get fs with)
out-file (tmp-get fs file)]
(-> fs
(cp (tmp-file src-file) out-file)
commit!))))

Developing at the REPL

(defn show-routes
"Prints the application's route table"
[]
(print-routes routes))
(defn named-route
"Finds a route by name"
[route-name]
(->> routes
(filter #(= route-name (:route-name %)))
#!/bin/bash
set -e
CHECKOUT=/tmp/clojurescript.git
rm -rf $CHECKOUT
git clone --bare [email protected]:clojure/clojurescript.git $CHECKOUT >/dev/null 2>&1
pushd $(pwd) > /dev/null
cd $CHECKOUT
VERSION=$(git describe --abbrev=0 --tags | sed "s/^r//")
(ns datascript-to-datomic-util
(:require [datascript :as d]))
;;;; a utility to help with a datomic-datascript roundtrip process involving:
;;; 1. export some data from a datomic database and transact into a datascript instance.
;;; 2. perform one or more transactions against datascript.
;;; 3. transact the sum of all changes made against datascript back into datomic in a single tx
;;; this namespace contains two public functions:
;;; listen-for-changes: listen to datascript transactions and build up a record of changes
(def path-element (s/or :key keyword? :index integer?))
(s/def :column/title string?)
(s/def :column/spec (s/or :path (s/+ path-element)
:path+keys (s/cat :path (s/* path-element)
:keys (s/coll-of keyword? []))
:path+fn (s/cat :path (s/* path-element)
:fn fn?)
:fn fn?))
(s/def ::column (s/keys :req [:column/title :column/spec]))
(s/def :grid/title string?)