Skip to content

Instantly share code, notes, and snippets.

{:db/ident :bsu.fns/reset-to-many-by,
:db/doc "Resets the set of entities which are related to `eid` via `ref-attr` to the set given by `val-maps`.
Assumptions:
* `ref-attr` is a cardinality-many, ref attribute.
* `e` is an entity identifier for an _existing_ entity
(you have to know whether an entity exists before using this function,
and it's pointless to use it on a non-existing entity as opposed to just asserting all the new values.)
* `val-maps` is a seq of transaction maps, all of which have the `v-id-attr` key provided.
* `retract-target-entity?`: whether to call :db.fn/retractEntity on the old entities which get removed from the relationship.
* the old values of the relationship all have the `id-attr` attribute."
@egmontkob
egmontkob / Hyperlinks_in_Terminal_Emulators.md
Last active May 3, 2024 11:35
Hyperlinks in Terminal Emulators
@rgdelato
rgdelato / uncontrolled-react-forms.md
Last active May 8, 2017 23:29
Forms in React.js

Forms in React.js

Controlled Change

Lets say you want to make form input that shows the user an error message if they leave it blank. If you typically write controlled inputs, you might do something like this simplified example:

class ControlledInput extends Component {
  state = { fields: { username: "" }, errors: {} };
(defvar-local unrepl-repl-input-start-mark nil)
(defvar-local unrepl-hello-payload nil)
(edn-add-reader :unrepl/param (lambda (x) `(:unrepl/param . ,x)))
(edn-add-reader :unrepl/ns (lambda (x) `(:unrepl/ns . ,x)))
(edn-add-reader :unrepl/ratio (lambda (x) `(:unrepl/ratio . ,x)))
(edn-add-reader :unrepl/meta (lambda (x) `(:unrepl/meta . ,x)))
(edn-add-reader :unrepl/pattern (lambda (x) `(:unrepl/pattern . ,x)))
(edn-add-reader :unrepl/object (lambda (x) `(:unrepl/object . ,x)))
(edn-add-reader :unrepl.java/class (lambda (x) `(:unrepl.java/class . ,x)))
@YurySolovyov
YurySolovyov / class-names.cljs
Created July 2, 2017 12:17
class-names for ClojureScript
(defn class-names [& args]
(clojure.string/join " "
(mapv name
(reduce (fn [arr arg]
(cond
(or (string? arg)
(symbol? arg)
(keyword? arg)) (conj arr arg)
(vector? arg) (vec (concat arr arg))
(map? arg) (vec (concat arr
@thheller
thheller / es6-class.cljs
Created August 24, 2017 13:51
class extends React.Component in CLJS
(defn my-component [props context updater]
(cljs.core/this-as this
(js/React.Component.call this props context updater)
;; anything else you want to set-up. use goog.object/set on this
this))
(gobj/extend
(.. my-component -prototype)
js/React.Component.prototype)
@lmakarov
lmakarov / lambda-basic-auth.js
Created August 30, 2017 19:15
Basic HTTP Authentication for CloudFront with Lambda@Edge
'use strict';
exports.handler = (event, context, callback) => {
// Get request and request headers
const request = event.Records[0].cf.request;
const headers = request.headers;
// Configure authentication
const authUser = 'user';
const authPass = 'pass';
(def kw-cache #js{})
(defn cached-kw [fqn]
(if-some [kw (unchecked-get kw-cache fqn)]
kw
(let [kw (keyword fqn)]
(unchecked-set kw-cache fqn kw)
kw)))
(defn js->clj-fast
@OliverJAsh
OliverJAsh / foo.ts
Last active July 29, 2023 18:16
Records and dictionaries in TypeScript
/*
In JavaScript, objects can be used to serve various purposes.
To maximise our usage of the type system, we should assign different types to our objects depending
on the desired purpose.
In this blog post I will clarify two common purposes for objects known as records and dictionaries
(aka maps), and how they can both be used with regards to the type system.
@bhb
bhb / README.md
Last active May 15, 2023 01:28
Clojure friendly mode, inspired by https://github.com/slipset/friendly