Skip to content

Instantly share code, notes, and snippets.

(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)))
@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: {} };
@egmontkob
egmontkob / Hyperlinks_in_Terminal_Emulators.md
Last active May 3, 2024 11:35
Hyperlinks in Terminal Emulators
{: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."
@metametadata
metametadata / react-bootstrap.cljs
Last active June 6, 2017 07:56
Fixing of caret/cursor jumps in text inputs of cljsjs.react-bootstrap
(ns app.components.react-bootstrap
(:require [cljsjs.react-bootstrap]
[reagent.core :as r]))
(def Alert (r/adapt-react-class (.-Alert js/ReactBootstrap)))
(def Button (r/adapt-react-class (.-Button js/ReactBootstrap)))
; ...
(def FormControl (r/adapt-react-class (.-FormControl js/ReactBootstrap))) ; WARNING: use FormControlFixed for text input controls instead
(defn FormControlFixed
@john-doherty
john-doherty / javascript-promise-timeout.js
Last active December 17, 2021 02:06
Adds a timeout to a JavaScript promise, rejects if not resolved within timeout period (uses requestAnimationFrame for better accuracy)
(function () {
'use strict';
/**
* wraps a promise in a timeout, allowing the promise to reject if not resolve with a specific period of time
* @param {integer} ms - milliseconds to wait before rejecting promise if not resolved
* @param {Promise} promise to monitor
* @example
* promiseTimeout(1000, fetch('https://courseof.life/johndoherty.json'))
@moodysalem
moodysalem / promise-cancellable.js
Last active April 9, 2024 18:06
ES6 Cancellable Promise Wrapper
/**
* Returns a promise that has a cancelled method that will cause the callbacks not to fire when it resolves or rejects
* @param promise to wrap
* @returns new promise that will only resolve or reject if cancel is not called
*/
export default function cancellable(promise) {
var cancelled = false;
const toReturn = new Promise((resolve, reject) => {
promise.then(() => {
@yang-wei
yang-wei / destructuring.md
Last active February 20, 2024 04:40
Elm Destructuring (or Pattern Matching) cheatsheet

Should be work with 0.18

Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !

Tuple

myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))
@jeroenvandijk
jeroenvandijk / datomic.schema_dump.clj
Last active January 23, 2020 10:58
(A) method to dump a datomic database schema
(ns datomic.schema-dump
(:require
[datomic.api :as d]
[clojure.pprint]))
(defmethod clojure.pprint/simple-dispatch datomic.db.DbId [v] (pr v))
(defmethod clojure.pprint/simple-dispatch datomic.function.Function [v] (pr v))
(defn database-url [name]
(str "datomic:mem://" name))
@TheBB
TheBB / loading.org
Last active June 22, 2023 11:53
Loading in Spacemacs

Emacs packages, features, files, layers, extensions, auto-loading, require, provide, use-package… All these terms getting you confused? Let’s clear up a few things.

Files

Emacs files contains code that can be evaluated. When evaluated, the functions, macros and modes defined in that file become available to the current Emacs session. Henceforth, this will be termed as loading a file.

One major problem is to ensure that all the correct files are loaded, and in the