Skip to content

Instantly share code, notes, and snippets.

View refset's full-sized avatar
🌍

Jeremy Taylor refset

🌍
View GitHub Profile
@refset
refset / crux-pull.clj
Created May 5, 2020 18:40 — forked from dvingo/crux-pull.clj
pull api support for crux
(ns datascript-crux.pull-api
(:require
[crux.api :as crux]
[datascript.pull-parser :as dpp]
[my-app.crux-node :refer [crux-node]])
(:import [datascript.pull_parser PullSpec]))
;; lightly adapted from:
;; https://github.com/tonsky/datascript/blob/master/src/datascript/pull_api.cljc
;; https://github.com/tonsky/datascript/blob/master/src/datascript/pull_parser.cljc
@refset
refset / convert.clj
Created June 6, 2020 14:15 — forked from KGOH/convert.clj
convert.clj -- babashka edn/json/yaml to edn/json/yaml converter
#!/usr/bin/env bb
;; convert.clj -- babashka edn/json/yaml to edn/json/yaml converter
;; Author: github.com/KGOH/
;; Source: gist.github.com/KGOH/50c0f66022fea2ac173518a143238058
;; Version: 2020.3
; Usage example:
; In Emacs: i.imgur.com/TIEDmga.mp4
; $ convert.clj edn <<< '{"foo": "bar"}'
; {:foo "bar"}
@refset
refset / datomic_util.cljc
Created July 27, 2020 23:00 — forked from tomconnors/datomic_util.cljc
kc datomic util
(ns kc.datomic
"Datomic utility functions
Usage Notes:
Some functions in this namespace take sequences of facts and return them modified in some way. Some up-front modifications are useful for those functions, like replacing all map-form facts with vector-form facts. In order to avoid doing these modifications repeatedly to same the same set of facts (which would be harmless but wasteful), two versions of these functions exist: a \"safe\" version that does those up-front modifications, and an \"unsafe\" version that expects those modifications to already have been performed. The unsafe versions are named like the safe ones, but with a single quote appended.
TODO:
- consider implementing all fns that branch based on operation as multimethods
These fns mostly support :db/add, :db/retract :db.fn/retractEntity, :db.fn/cas,
@refset
refset / user.clj
Created November 9, 2020 18:20 — forked from spacegangster/user.clj
Getting call graph (vars structure) in Clojure
(ns user)
; Hey, I've been playing a bit with graphing out the structure of a module for Lightpad.
; It worked well, I've found the target function that I'll need change to add a new feature.
; Tweet with a screenshot https://twitter.com/spacegangster/status/1324760381735272450
; lein coordinate
; [com.gfredericks/clj-usage-graph "0.3.0"]
; https://github.com/gfredericks/clj-usage-graph
@refset
refset / datomic-rules.clj
Created February 24, 2021 11:10 — forked from taylorSando/datomic-rules.clj
Datomic recursion using rules
(defn recursive-rule
"A recursive rule for establishing prototype inheritance/isa relationship.
Can specify a maximum depth to travel, or none if there are no restrictinos.
rule The name of the rule
e The entity
a The attribute
v The value
Should be creating the rule like: (recursive-rule 'isa '?e '?a '?v)
Then within a query, can refer to it like this:
(isa ?e :thing/isa ?v) "
;; RGA
;; https://speakerdeck.com/ept/data-structures-as-queries-expressing-crdts-using-datalog?slide=22
(def schema
{:id/node {:db/valueType :Number}
:id/ctr {:db/valueType :Number}
:insert/id {:db/valueType :Eid}
:insert/parent {:db/valueType :Eid}
:assign/id {:db/valueType :Eid}
:assign/elem {:db/valueType :Eid}
;; LWW Register
;; https://speakerdeck.com/ept/data-structures-as-queries-expressing-crdts-using-datalog?slide=15
(def schema
{:assign/time {:db/valueType :Number}
:assign/key {:db/valueType :Number}
:assign/value {:db/valueType :Number}})
(def rules
'[[(older ?t1 ?key)
@refset
refset / visit.clj
Last active January 9, 2022 15:10
visit.clj
(defn visit [m visitors]
;; [node node-s next-s down-s right-s get-right get-down init-right-s cut-down cut-right :as m]
;; {:keys [break]} next-s
;; ;use next-state by default, unless down or right is necessary
(let
[dovisit (fn [m dir]
(loop [s m [v & vs] visitors]
(if v (recur (apply v (concat [dir] s)) vs) s)))
m2 (dovisit m :pre)
;break/cut checks should be between each visitor (:pre :post and :in) according to zip-visit
@refset
refset / get-current-pid.clj
Last active August 1, 2021 17:55
get-current-pid.clj
(-> (java.lang.management.ManagementFactory/getRuntimeMXBean)
(.getName)
(clojure.string/split #"@")
(first))
@refset
refset / flames_repl.clj
Created May 18, 2022 13:17 — forked from sw1nn/flames_repl.clj
Repl fns to generate a flame graph. (Not super sophisticated!)
;; Assumes https://github.com/jstepien/flames available
;; requires http://riemann.io to be installed.
(def flames (atom nil))
(defn flames-start! []
;; We resolve explicitly here, to avoid warnings when not working
;; with flamegraphs
(if-not @flames
(let [config {:port 54321, :host "localhost"}]
(reset! flames ((requiring-resolve 'flames.core/start!) config))