Skip to content

Instantly share code, notes, and snippets.

View ivarref's full-sized avatar

Ivar Refsdal ivarref

View GitHub Profile
(defn iterate-gql-connection [{:keys [api-url token]} query variables]
(->> (iteration
(fn [after]
(some->> (client/post api-url {:content-type :json
:accept :json
:as :json
:headers {"authorization" (str "Bearer " token)}
:form-params {:query query
:variables (merge variables {:after after})}})
:body
(ns datomic-oom
(:require [datomic.api :as d]
[clojure.set :as set])
(:import (java.util UUID)))
; This gist reproduces an odd (?) OutOfMemoryError with datomic-pro v1.0.6344
(def conn (let [uri "datomic:mem://demo"]
(d/delete-database uri)
(d/create-database uri)

This is on-prem. Both transactor and peer is running datomic pro v1.0.6344.

I am encountering a strange (?) OutOfMemoryError with the following simple query:

(d/query {:query {:find  '[(count ?tx) .]
                  :in    '[$ ?start ?end]
                  :where '[[?tx :tx/user-id _]
                           [?tx :db/txInstant ?inst]
                           [(.after ^java.util.Date ?inst ?start)]
.#!/bin/bash
rm client.crt client.pkcs8 2> /dev/null || true
rm server.crt server.pkcs8 2> /dev/null || true
rm -rf demoCA || true
mkdir -p demoCA/newcerts
touch demoCA/index.txt
set -ex
(defn ttl-fn
"Returns a function that will cache the `f` function.
The f function must return a map with two keys:
- :ttl number of seconds for the return value to live.
- :val the value that this function will return and cache."
[f]
(let [cache (atom nil)]
(fn [& args]
(locking cache
@ivarref
ivarref / hello.clj
Last active June 30, 2020 12:57
pedestal async solution
(ns hello
(:require [io.pedestal.http :as http]
[io.pedestal.http.route :as route]
[clojure.core.async :as async]
[cheshire.core :as json]))
; deps.edn:
; {:paths ["src"]
; :deps {io.pedestal/pedestal.service {:mvn/version "0.5.8"}
; io.pedestal/pedestal.route {:mvn/version "0.5.8"}
(ns dato.tuples2
(:require [datomic.api :as d])) ; Datomic pro 0.9.6024
(def url "datomic:mem://test-db")
(def conn (do (d/delete-database url)
(d/create-database url)
(d/connect url)))
(def schema
(ns dato.demo
(:require [datomic.api :as d])) ; datomic version 0.9.6024
(def url "datomic:mem://test-db")
(def conn (do (d/delete-database url)
(d/create-database url)
(d/connect url)))
(def schema
(ns ivarref.recurring-cup
(:require [tea-time.core :as tt]
[tea-time.virtual :as tv])
(:import (java.time ZonedDateTime ZoneId Instant DayOfWeek)
(java.time.format DateTimeFormatter)
(tea_time.core Task)))
;; Example of how to add scheduling of functions returning ZonedDateTime
;; and lazy sequences returning ZonedDateTime to aphyr/tea-time
{:db/id #db/id [:db.part/user]
:db/ident :nil->retract
:db/fn #db/fn {:lang :clojure
:params [db m & opts]
:code (letfn [(remove-nil
[m]
(let [f (fn [[k v]] (when (not (nil? v)) [k v]))]
(clojure.walk/postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)))
(empty-coll->nil