This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun insert-parentheses-backward () | |
"Insert parentheses around the sexp near point. | |
Move parentheses backward by sexp if used repeatedly." | |
(interactive) | |
(cond ((string-match-p "\\\w" (char-to-string (char-after))) | |
(forward-char) (insert-parentheses-backward)) | |
((equal (char-before) 41) | |
(backward-sexp) (insert-parentheses-backward)) | |
((equal (char-after) 40) | |
(if (equal (char-before) 40) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[proc_macro_attribute] | |
pub fn instrument_err(args: TokenStream, item: TokenStream) -> TokenStream { | |
let input: ItemFn = syn::parse_macro_input!(item as ItemFn); | |
let args = syn::parse_macro_input!(args as AttributeArgs); | |
// these are needed ahead of time, as ItemFn contains the function body _and_ | |
// isn't representable inside a quote!/quote_spanned! macro | |
// (Syn's ToTokens isn't implemented for ItemFn) | |
let ItemFn { | |
attrs, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(put {:crux.db/id {[:user/id 1] :login-details} :user/id 1 :user/name "foo" :user/password "bar"}) | |
(put {:crux.db/id {[:user/id 1] :favorites} :user/id 1 :user/favorite-food "pie" :user/favorite-animal "cow"}) | |
(defn attr [ident attr] | |
(dissoc (crux/entity (db) {ident attr}) :crux.db/id)) | |
(defn entity [ident] | |
(let [[table id] ident] | |
(dissoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns app.crux.scylla | |
(:require [crux.codec :as codec] | |
[crux.db] | |
[crux.document-store :as ds] | |
[crux.io :refer [with-nippy-thaw-all]] | |
[crux.system :as sys] | |
[crux.memory] | |
[taoensso.nippy :as nippy] | |
[taoensso.timbre :as log] | |
[qbits.alia :as alia] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
["/user" {:name ::user-main | |
:target 'app.ui.root/UserMain} | |
["/" {:target-ident [:user-main :screen]}] ;; put it here, because reitit will append collections | |
["/:uuid" | |
{:name ::user | |
:target 'app.ui.user/User | |
:target-ident [:user/id :param/uuid] | |
:target-router :router/user | |
:parameters {:path [:map [:uuid uuid?]]}}]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn merge-two-vecs | |
"Takes a keyfn and two sorted vecs, peek-smallest, and returns one sorted vec. | |
e.g. (merge-two-vecs identity [5 3 1] [6 4 2])" | |
[keyfn xs ys] | |
(let [keyfn (comp keyfn peek)] | |
(loop [acc (transient []) | |
xs xs | |
ys ys] | |
(let [x (keyfn xs) y (keyfn ys)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns app.client.pathom-remote | |
(:require [com.wsscode.pathom3.plugin :as p.plugin] | |
[com.fulcrologic.fulcro.algorithms.transit :as fulcro-transit] | |
[com.wsscode.pathom3.connect.runner :as pcr] | |
[com.wsscode.pathom3.interface.async.eql :as p.a.eql] | |
[com.wsscode.pathom3.connect.foreign :as pcf] | |
[com.wsscode.transito :as transito] | |
[promesa.core :as p] | |
[com.fulcrologic.fulcro.algorithms.tx-processing :as txn] | |
[taoensso.timbre :as log] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; port of https://blog.bruce-hill.com/a-faster-weighted-random-choice | |
(defn weighted-randomizer [weights] | |
(let [N (count weights) | |
avg (/ (reduce + weights) N) | |
aliases (volatile! (vec (repeat N [1 nil]))) | |
{:keys [smalls bigs]} (->> (map-indexed | |
(fn [idx weight] | |
(if (< weight avg) | |
[[idx (/ weight avg)] :smalls] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns app.todo-list | |
(:require contrib.str | |
[hyperfiddle.electric :as e] | |
[hyperfiddle.electric-dom2 :as dom] | |
[hyperfiddle.electric-ui4 :as ui] | |
[odoyle.rules :as o] | |
[missionary.core :as y]) | |
#?(:clj (:import [clojure.lang IFn IDeref]))) | |
(defn rule->subject [*s whats then] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def timer* | |
(->> e/<clock ;; produce time | |
(y/sample e/-get-system-time-ms) ;; label time | |
(y/reductions (fn([] {:t (e/-get-system-time-ms) :dt 0}) | |
([acc next] ;; produce difference | |
{:t (e/-get-system-time-ms) | |
:dt (- next (:t acc))}))))) | |
(defn pid [<setpoint {:keys [<force error-threshold k <clock] | |
:or {<force (y/watch (atom 10)) |
OlderNewer