Skip to content

Instantly share code, notes, and snippets.

View MageMasher's full-sized avatar

Joe Lane MageMasher

View GitHub Profile
@MageMasher
MageMasher / dynacode.repl
Created July 2, 2019 16:57
An executable transcriptor file for dynamically requiring functions from datomic cloud, with time travel.
(require '[datomic.client.api :as d]
'[cognitect.transcriptor :as xr :refer (check!)])
(def get-client
"This function will return a local implementation of the client
interface when run on a Datomic compute node. If you want to call
locally, fill in the correct values in the map."
(memoize #(d/client {:server-type :ion
:region "us-east-1"
:system "dynacode"
@MageMasher
MageMasher / web-component-v1.cljs
Created April 9, 2019 13:45 — forked from thheller/web-component-v1.cljs
create web-component v1 in cljs without class
(defn component []
(js/Reflect.construct js/HTMLElement #js [] component))
(set! (.-prototype component)
(js/Object.create (.-prototype js/HTMLElement)
#js {:connectedCallback
#js {:configurable true
:value
(fn []
(this-as this
@MageMasher
MageMasher / deps.edn
Created December 26, 2018 20:54 — forked from bmaddy/deps.edn
Playing around with caching
{:deps
{org.clojure/clojure {:mvn/version "1.10.0-RC5"}
#_#_org.clojure/spec.alpha {:mvn/version "0.2.176"}
#_#_org.clojure/test.check {:mvn/version "0.10.0-alpha3"}
org.clojure/core.cache {:mvn/version "0.7.1"}
org.clojure/core.memoize {:mvn/version "0.7.1"}
}}
@MageMasher
MageMasher / Transcriptor-Output.clj
Created December 24, 2018 19:28
In Clojure 1.10 Objects can dynamically extend protocol methods at runtime. First file is cognitect.transcriptor output, second is the transcriptor file itself.
(comment {:transcript "./extend.repl", :namespace cognitect.transcriptor.t_56})
(require '[cognitect.transcriptor :refer (check!)])
;;=> nil
(defprotocol
CustomerDatabase
:extend-via-metadata
true
(get-customer-by-id [db id])
(update-customer-by-id [db id data])
(require
'[datomic.client.api :as d]
'[clojure.core.logic :refer :all]
'[clojure.core.logic.datomic :as ld])
(defn entid [db k]
(-> db
(d/pull [:db/id] [:db/ident k])
:db/id))
@MageMasher
MageMasher / interceptor.clj
Created June 19, 2018 01:35 — forked from ohpauleez/interceptor.clj
An example of how to make conditional interceptors that enqueue new interceptors
;; Let's start with a simple conditional interceptor that works with functions...
(defn conditional-context
"Given a keyword name and any variable predicate and terminator function pairs,
return an interceptor that will apply the terminator function paired to the first
truthy predicate. Predicates and terminators are both given the context as
the only argument.
If all predicates fail, the original context is returned."
[name-kw & pred-terms]
@MageMasher
MageMasher / selfrealizing.clj
Last active July 21, 2019 02:48
Self Realizing code! Code that, when given a `what-i-want` and a vector of operators and operands, will create the lisp code to compute that result.
(ns self-realizing.core
(:gen-class)
(:require [clojure.math.combinatorics :as combo]))
(defmacro ignore-errors
"Returns the result of evaluating e, or nil if it throws an exception."
[e]
`(try ~e (catch java.lang.Exception _# nil)))
(defn findr