Skip to content

Instantly share code, notes, and snippets.

Dustin Getz dustingetz

Block or report user

Report or block dustingetz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
dustingetz / ordering.clj
Created May 30, 2019 — forked from joinr/ordering.clj
examples of composeable ordering functions
View ordering.clj
(ns ordering)
;;We want to pack some information along with
;;our functions so that when our interpreter picks them
;;up, we can determine if the function should be applied
;;directly as a comparator, or if we need to "lift"
;;it into the comparator domain.
(defn ordering? [x] (get (meta x) :ordering))
;;convenience macro to help us create functions with
;;ordering specified in meta
dustingetz / .cljs
Created May 12, 2019
react virtualized data grid clojurescript
View .cljs
(defn row [ctx k]
^{:key (pr-str k)}
[:> js/ReactVirtualized.Column
{:label (reagent.core/as-element [hyperfiddle.ui/field [k] ctx])
:dataKey (hypercrud.transit/encode k)
(fn [m]
(let [k (hypercrud.transit/decode (aget m "dataKey"))
ctx (aget m "rowData")
#_#_ctx (hypercrud.browser.context/attribute ctx k)]
View seattle-data.edn
[[:db/add "-1000001" :district/region :region/e]
[:db/add "-1000001" :district/name "East"]
[:db/add "-1000002" :neighborhood/name "Capitol Hill"]
[:db/add "-1000002" :neighborhood/district "-1000001"]
[:db/add "-1000003" :community/category "15th avenue residents"]
[:db/add "-1000003" :community/orgtype :community.orgtype/community]
[:db/add "-1000003" :community/type :community.type/email-list]
[:db/add "-1000003" :community/name "15th Ave Community"]
[:db/add "-1000003" :community/url ""]
[:db/add "-1000003" :community/neighborhood "-1000002"]
View seattle-schema.edn
[[:db/add "-700968933" :db/ident :community/name]
[:db/add "-700968933" :db/valueType :db.type/string]
[:db/add "-700968933" :db/cardinality :db.cardinality/one]
[:db/add "-700968933" :db/fulltext true]
[:db/add "-700968933" :db/doc "A community's name"]
[:db/add "43126449" :db/ident :community/url]
[:db/add "43126449" :db/valueType :db.type/string]
[:db/add "43126449" :db/cardinality :db.cardinality/one]
[:db/add "43126449" :db/doc "A community's url"]
[:db/add "-1305932792" :db/ident :community/neighborhood]
View forall.clj
;; Because in formal logic, ∀x.P(x) = ¬∃x.¬P(x)
(d/q '[:find ?id
:in $ [?interest ...]
[?a :account/id ?id]
(not-join [?a ?interest]
[?a :account/interest ?i]
(not [(= ?i ?interest)]))])
;; It is harder to understand when you bind interest as above if you
View datomic-players-roster-rules.clj
(def players-roster-rules
"Rules to test if a collection of players are a subset of the players
in a roster.
Usage Constraints:
- ?players must always be bound
- ?roster may be bound or unbound
Valid Uses:
- test if a specific ?roster contains all ?players
View Datomic pulling through relations as if

This is a thought experiment, obviously this is not real datomic!

Why do this? I think it would cancel out data transformation boilerplate currently needed to do something like this.

(defn user-uuid-to-user [user-uuid]
  (d/q [:in $ ?user-uuid
        :find ?user .                          ; no pull here, bind it later
        :where [?user :user/uuid ?user-uuid]]
       *$* user-uuid))
View match-datascript-parser.clj
(require '[clojure.core.match :refer [match]])
(require '[datascript.parser :refer [parse-query]])
(import (datascript.parser FindRel FindColl FindTuple FindScalar Variable Aggregate Pull))
(def q '[:find [?e ...] :where [?e :db/ident]])
(let [FindColl FindColl ; Create locals for symbols
FindScalar FindScalar
FindRel FindRel
FindTuple FindTuple]
(match [(type (:qfind (parse-query q)))]
[FindRel] :rel ; match searches locals first before binding wildcards
View enclosing-pull-shape.cljc
(defn- attr-spec->shape "Take the pull and get rid of everything, even splat, just attrs requested."
; todo :as
(keyword? a) a
(#{'* "*"} a) nil
(map? a) (reduce-kv (fn [m k v]
(assoc m (attr-spec->shape k)
(pull-shape v)))
{} a)
View datomic.client.protocol.clj
;; Copyright (c) Cognitect, Inc.
;; All rights reserved.
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;; Unless required by applicable law or agreed to in writing, software
You can’t perform that action at this time.