Skip to content

Instantly share code, notes, and snippets.

pesterhazy /
Last active Dec 7, 2021
The pain and anguish of using IndexedDB: problems, bugs and oddities

This gist lists challenges you run into when building offline-first applications based on IndexedDB, including open-source libraries like Firebase, pouchdb and AWS amplify (more).

Note that some of the following issues affect only Safari. Out of the major browsers, Chrome's IndexedDB implementation is the best.

Backing file on disk (WAL file) keeps growing (Safari)

When this bug occurs, every time you use the indexeddb, the WAL file grows. Garbage collection doesn't seem to be working, so after a while, you end up with gigabytes of data.

Random exceptions when working with a large number of indexeddb databases (Safari)

pesterhazy /
Last active Nov 28, 2021
Promises in ClojureScript

Chaining promises

Chaining promises in ClojureScript is best done using the thread-first macro, ->. Here's an example of using the fetch API:

(-> (js/fetch "/data")
    (.then (fn [r]
             (when-not (.-ok r)
               (throw (js/Error. "Could not fetch /data")))
             (.json r)))
pesterhazy / react_cljs_es6_classes.cljs
Last active Nov 7, 2021
ClojureScript: bare React with ES6 classes (extending React.Component, no createClass or reagent)
View react_cljs_es6_classes.cljs
(ns demo.react-cljs-es6-classes
(:require [goog.object :as gobj]))
;; Demo of using bare React using ES6 classes (without createClass or reagent)
;; Equivalent of Javascript/JSX:
;; class MyComponent extends React.Component {
;; constructor(props) {
;; super(props);
pesterhazy / promises-passing-values.cljs
Last active Oct 24, 2021
Promise chains in ClojureScript and the problem of previous values
View promises-passing-values.cljs
(ns my.promises
"Demo to show different approaches to handling promise chains in ClojureScript
In particular, this file investigates how to pass data between Promise
callbacks in a chain.
See Axel Rauschmayer's post for a problem
pesterhazy / error_boundary.cljs
Last active Oct 12, 2021
Reagent error boundary for recovering from exceptions
View error_boundary.cljs
(ns error-boundary.error-boundary
(:require [reagent.core :as r]
[reagent.impl.component :as comp]
[reagent.impl.util :as util]
[goog.object :as gobj]))
;; (c) 2016 Paulus Esterhazy
;; License: MIT
pesterhazy /
Last active Oct 9, 2021
ClojureScript Do's and Don'ts: clj->js

ClojureScript Do's and Dont's: clj->js

You should prefer

#js["tag" #js{"k1" v1, "k2" v2}]


pesterhazy / reagent-ref-functions.clj
Last active Oct 8, 2021
Using ref functions with reagent
View reagent-ref-functions.clj
;; React supports "refs" as a way for a component to get a
;; handle to its children. Classically, refs were string-based.
;; Recent versions of React support callback attributes as a
;; more elegant variant of accessing DOM notes or components.
;; This example uses a Form-3 component as per
;; For callback refs, see React's documentation
pesterhazy /
Last active Aug 25, 2021
Using ripgrep in Emacs using helm-ag (Spacemacs)


Ripgrep is a fast search tool like grep. It's mostly a drop-in replacement for ag, also know as the Silver Searcher.

helm-ag is a fantastic package for Emacs that allows you to display search results in a buffer. You can also jump to locations of matches. Despite the name, helm-ag works with ripgrep (rg) as well as with ag.


pesterhazy /
Last active Aug 17, 2021
A UUID to remember

In their most used version v4, UUIDs are random, and that's a useful property. But sometimes all you want is a UUID that is easy to remember. To hell with randomness!

A minor complication is that for a string to parse as a valid UUID, the variant and version bits should be set correctly (to 2 and 4, respectively). Here are a few suggestions that pass the test:

pesterhazy /
Last active Aug 13, 2021
Print Github Markdown

I often want to read Markdown documentation on Github — or proof-read my own documents — without staring at a backlit screen. Here's an easy way to print the files in a readable format.

  1. Create a bookmarklet with the following code and give it the name "github print"

    javascript:void function(){b=document.body,c=document.querySelector("article"),b.innerHTML="",b.appendChild(c)}();
  2. Go to the markdown view on Github of the file you want to print, e.g. Ripgrep's user guide

  3. Click on the bookmarklet. Alternatively (in Chrome) type "github print" in the search bar, select the bookmarklet code with cursor keys if necessary and press enter.

  4. Use the browser print feature to print the document, to a physical printer or (to save paper) to PDF on a reMarkable eInk tablet.