Skip to content

Instantly share code, notes, and snippets.

boot-react-native/example$ boot -v dev
registering react-support [:create :modify :delete]
registering react-support/cljsjs [:create :modify :delete]
registering src [:create :modify :delete]
registering src/mattsum [:create :modify :delete]
registering src/mattsum/simple_example [:create :modify :delete]
sending change event
Syncing project dirs to temp dirs...
Acquired java.util.concurrent.Semaphore@68567e20[Permits = 0]...
@pesterhazy
pesterhazy / reagent-ref-functions.clj
Last active January 19, 2023 11:31
Using ref functions with reagent
;; 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
;; https://github.com/Day8/re-frame/wiki/Creating-Reagent-Components
;;
;; For callback refs, see React's documentation
;; https://facebook.github.io/react/docs/more-about-refs.html
@pesterhazy
pesterhazy / react-native-only.py
Created August 5, 2016 13:55
Filter "react-native log-ios" output for relevant app logs
#!/usr/bin/env python
# Cleans up the output of "react-native log-ios" by
# removing all output not related to your app, similarly
# to how it works in the XCode debug window
#
# Usage: react-native log-ios | ./react-native-only.py "<string>"
#
# where "<string>" is the name of your app as known
# to the iOS logging system. E.g. "SimpleExampleApp"
@pesterhazy
pesterhazy / boot-react-native-no-dev.py
Created August 17, 2016 18:13
Set __DEV__ of RN packager output to false
#!/usr/bin/env python
#
# boot-react-native-no-dev.py
#
# Patch jsbundle to set __DEV__ to false
#
# The React Native packager often cannot handle Google Closure-generated JS files
# if `--dev false` is set, eventually running out of memory. As a workaround,
# use `--dev true` and patch the __DEV__ setting in the output bundle to
# false.
@pesterhazy
pesterhazy / reagent-inner-outer.clj
Last active August 19, 2016 12:53
Reagent props, component-did-mount and container components
;; This demonstrates the container component pattern
;; used with reagent (or re-frame)
;;
;; - listen for props changes
;; - inner component (foo-view) gets data passed as prop
;; - outer component (foo) reacts to prop changes by fetching data
;;
;; see https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0
;;
;; For reagent's handling of props, see https://www.martinklepsch.org/posts/props-children-and-component-lifecycle-in-reagent.html
@pesterhazy
pesterhazy / no-dev.py
Created October 16, 2016 11:41
patch jsbundle to set __DEV__ to false for a bundle built with `--dev true`
#!/usr/bin/env python
# Patch jsbundle to set __DEV__ to false
import sys, re
print(re.sub(r'__DEV__\s*=\s*true;', "__DEV__=false;",
sys.stdin.read()))
@pesterhazy
pesterhazy / error_boundary.cljs
Last active October 12, 2021 00:19
Reagent error boundary for recovering from exceptions
(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
pesterhazy / datomic-set-intersection.clj
Created January 3, 2017 11:35
Datomic set intersection query
(defn make-intersection-q
"Generate an intersection q for arbitrary sets of features"
[n]
(assert (pos? n))
{:find '[[?product-slug ...]]
:in ['$ (->> (range 1 (inc n)) (mapv #(symbol (str "?v" %))))]
:where
(into ['[?product :cat.product/slug ?product-slug]]
(map (fn [n]
['?product :cat.product/features (symbol (str "?v" n))])
@pesterhazy
pesterhazy / datomic-repl.clj
Created January 9, 2017 14:54
Datomic REPL helpers
;; Makes it easier to work from the REPL
;;
;; Don't use these from production functions
(defonce !c (atom nil))
(defn rdc []
(let [c @!c]
(assert c "Database not connected")
c))
@pesterhazy
pesterhazy / datomic_maintenance.clj
Created January 11, 2017 09:50
Datomic entity maintenance helpers
;; Helpers for looking up and updating datomic db entities from the REPL
(defn every-eid
"Returns set of ids of entites that have a given attribute"
[db attr]
(into #{} (d/q '[:find [?e ...]
:in $ ?attr
:where [?e ?attr]]
db attr)))