Skip to content

Instantly share code, notes, and snippets.

pub fn access_token() -> BoxedFilter<(String,)> {
let (set_token_value, token_value) =
tokio_sync::watch::channel::<Option<gcloud::GrantedToken>>(None);
let channel_lock = tokio_sync::lock::Lock::new(set_token_value);
warp::any()
.and_then(move || {
let current_value = token_value.get_ref().clone().filter(|t| t.is_valid());
let result = match current_value {

Keybase proof

I hereby claim:

  • I am c-spencer on github.
  • I am cagspencer (https://keybase.io/cagspencer) on keybase.
  • I have a public key whose fingerprint is 6941 F445 2599 B7BC FF92 F7B1 E091 D260 3D41 E23C

To claim this, I am signing this object:

@c-spencer
c-spencer / datomic-annotations.clj
Last active December 24, 2016 21:45
A first pas at Datomic Types
(ns typed-datomic.types
(:use [clojure.core.typed])
(:import [clojure.lang Keyword Symbol]
[java.util Date]))
;; Type aliases
; Marker protocol to distinguish historical databases
(ann-protocol HistoryDB)
(defprotocol> HistoryDB)
@c-spencer
c-spencer / sysdea.clj
Last active December 24, 2015 01:59
Simple experiment in ClojureScript approach to Sysdea documents with undo/redo
; adapted from clojure.core.incubator
(defn dissoc-in
"Dissociates a number of entries from the object at the given path,
removing empty maps on the path.
e.g. (dissoc-in {:a {:b {:e 6} :c 6}} [:a :b] [:e]) -> {:a {:c 6}}"
[m [k & ks :as keys] rems]
(if k
(if-let [nextmap (get m k)]
(let [newmap (dissoc-in nextmap ks rems)]
(if (seq newmap)
(cf (fn [m] (conj [0] (if m 1 2))))
; [(Fn [Any -> [(Value 0) (U (Value 1) (Value 2))]]) {:then tt, :else ff}]
(cf (fn [{:keys [a] :as m} c]
(merge m {:b (+ a c) :c c}))
['{:a Number} Number -> '{:a Number :b Number :c Number}])
; (Fn [(HMap :mandatory {:a Number}) Number -> (HMap :mandatory {:a Number, :b Number, :c Number})])
(cf (fn [m] (dissoc {:a 1 :b 2} (if m :a :b))))
; [(Fn [Any -> (U (HMap :mandatory {:a (Value 1)} :complete? true)
@c-spencer
c-spencer / core.clj
Last active December 23, 2015 02:49
Simple demo of type construction from Datomic with core.typed and a little glue
(defn create-type
"Extract a type from provided field idents stored in Datomic database at uri."
[uri type-name overrides]
(let [c (d/connect uri)
d (d/db c)
datomic-type-map {:db.type/string 'String
:db.type/ref 'Any}
mt (dt/q> :- [EntityID]
'[:find ?e
:in $ ?t-name
@c-spencer
c-spencer / gist:6528482
Last active December 22, 2015 20:48
core.typed messings about
; trying to work around no update-in type
(defmacro typed-update-in [m [v] f]
`((ann-form update-in
(~'All [~'x ~'y]
[ (~'HMap :mandatory {~v ~'x}) (~'Vector* Keyword) [~'x ~'-> ~'y]
~'->
(~'HMap :mandatory {~v ~'y}) ]))
~m [~v] ~f))
; still causes an error because of the inner un-typed update-in
(defn Buffer [string]
(set! this.string string)
(set! this.pos 0)
undefined)
(defn Buffer.prototype.read1 []
(cond
(= this.pos this.string.length)
(do
(set! this.pos (+ this.pos 1))
(ns typingfun.core
(:require [clojure.core.typed :as t]))
(t/ann-protocol AddProtoc
adder [AddProtoc Number -> AddProtoc])
(t/defprotocol> AddProtoc
(adder [this amount]))
(t/ann-datatype Accumulator [t :- Number])
@c-spencer
c-spencer / preprocess-schema.clj
Last active December 10, 2015 05:28 — forked from anonymous/preprocess-schema.clj
Simple template expansion meta-definitions for Datomic
(defn extract-key [m k]
(when-let [value (k m)] [(dissoc m k) value]))
(defn expand-entry-id [entry]
(if (keyword? (:db/id entry))
(update-in entry [:db/id] d/tempid)
entry))
(defn expand-schema-entry [entry templates]
(if (and (map? entry) (:meta/templates entry))