Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
pesterhazy / reagent.cljs
Last active February 28, 2017 17:51
Template for Reagent on Klipse
; Try this online here:
;
; http://app.klipse.tech/?cljs_in.gist=pesterhazy%2F2540ab6458f6681656bfd8bf5a4af4cb&container=1
(ns test.reagent
(:require [reagent.core :as r]))
(defonce !state (r/atom nil))
(defn input-ui []
@pesterhazy
pesterhazy / reagent-render.cljs
Created February 28, 2017 17:56
r/create-class :render vs :reagent-render
(ns test.reagent
(:require [reagent.core :as r]))
(defonce !state (r/atom nil))
(defn comp1 []
(r/create-class {:render (fn [x]
[:div "comp1: " (pr-str x)])}))
(defn comp2 []
@pesterhazy
pesterhazy / react-native-navigators.md
Last active March 2, 2017 22:37
React Native Navigator choices

To implement RN navigation (showing scenes, animating transitions, ability to navigate back in a stack), there are a number of components to choose from.

Here's a list with some (non-authoritative) features:

  • Navigator (and its close cousin NavigatorIOS): included with RN, janky imperative interface
  • NavigationExperimental: also included in RN, more functional but still has "experimental" in it name
  • exponent/ex-navigator: provided by exponent, a wrapper around Navigator with a better interface (deprecated in favor of react-navigation?)
  • exponent/ex-navigation: also by exponent, a successor (?) of ex-navigator (deprecated in favor of react-navigation?)
  • [wix/react-native-naviga
@pesterhazy
pesterhazy / react_select_klipse.cljs
Last active March 4, 2017 23:08
react-select using reagent and klipse
(ns zap.core
"Demonstrate react-select in KLIPSE"
(:require [reagent.core :as r]
[cljsjs.classnames]
[cljsjs.react-input-autosize]
[cljsjs.react-select]))
(defonce value (r/atom nil))
(defn select-ui []
@pesterhazy
pesterhazy / background.clj
Last active March 28, 2017 22:24
As replacement for clojure.core/future, java.util.concurrent.Executors
(ns my.utils
(:require [clojure.tools.logging :as log])
(:import java.util.concurrent.Executors))
(defonce !executor (delay (java.util.concurrent.Executors/newCachedThreadPool)))
(defn background
"Calls the fn passed in a thread from a thread pool, returning immediately.
Unlike future, background does not swallow exceptions."
[f]
@pesterhazy
pesterhazy / reagent-anonymous-fns.cljs
Last active September 4, 2017 14:47
Reagent, anonymous functions and props
(ns test.reagent
(:require [reagent.core :as r]))
;; Reagent, anonymous functions and props
;; Demonstrate that a reagent component will rererender
;; each time when its enclosing component updates *if*
;; one if its props is an anonymous fn.
;;
;; Note that the DOM is not update in each case, as the
@pesterhazy
pesterhazy / shepherd.md
Last active April 13, 2017 14:23
shepherd: run an interactive command repeatedly, listening for file-system events

Shepherd

Run an interactive command repeatedly, listening for file-system events

Motivation

I find myself frequently wishing for a tool that runs an interactive command (i.e. one that accepts input from stdin) and restarts it whenever a file in a directory tree changes. That tool is shepherd.

Installation

@pesterhazy
pesterhazy / pidkill
Last active May 11, 2017 09:35
Kill a process by port number
#!/usr/bin/env bash
#
# Kill a process by the port number it's listening to
#
# Installation: paste the following command into the terminal
#
# curl -sL https://gist.githubusercontent.com/pesterhazy/8a876d3c713fa106cbcfb7d2c04301bd/raw/6609ec71485f98dc8e25f350e72a3aa1d5c53271/pidkill | sudo tee /usr/local/bin/pidkill > /dev/null && sudo chmod +x /usr/local/bin/pidkill
#
# Tested on macOS 10.12
@pesterhazy
pesterhazy / threading-macro-spy.md
Created June 9, 2017 10:25
Threading macro spy

If you're looking for a low-tech way to print intermediate results inside arrow macros for debugging purposes, this works for thread-first:

(-> v transform)

;; with spy:

(-> v (doto prn) transform)
@pesterhazy
pesterhazy / reagent-remount-component.cljs
Created June 13, 2017 13:05
Reagent forcing a remount
;; This snippet forces React to unmount and remount the
;; entire component tree. Note that this is not the same
;; as using r/force-update-all. r/force-update-all causes
;; all components to update while staying mounted; the technique
;; used here causes a complete did-unmount/did-mount cycle.
(defonce !refresh-count (r/atom 0))
(defn refresh []
(swap! !refresh-count inc))