Skip to content

Instantly share code, notes, and snippets.

View mhuebert's full-sized avatar

Matt Huebert mhuebert

View GitHub Profile
(ns layout.core
(:require
[sablono.core :include-macros true :refer-macros [html]]
[goog.dom :as gdom]
[om.next :as om :refer-macros [defui]]))
(def leaves
(atom {1 {:leaf/label "Root"
:leaf/id 1
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
; in clojure an if-then statement looks like: (if test do-this-if-true do-this-if-false)
; eg (if has-water (prn "content") (water-plant))
(defn find-replace [zipper pred replacement]
(loop [loc zipper] ;begin a loop - when we call `recur` at the bottom,this is where we come back to.
(if (z/end? loc) ;if we are at the end, it means we've visited every node, so...
(root loc) ;we return the zipper
(if
(pred loc) ;`pred` is a function that we supply as a "test" for each location. eg. is this an 'x'?
(recur (z/next (z/replace loc (replacement loc)))) ;this is what we do if `pred` returned true
@mhuebert
mhuebert / cljs-js-analysis-cache-usage.md
Last active September 9, 2020 11:59
Using existing namespaces from cljs.js

Let's say you want to use cljs.js to eval code using functions declared in your project.

Expressions that only use core functions are simple to evaluate:

(ns foo.try-eval
  (:require [cljs.js :as cljs]))

(def compiler-state (cljs/empty-state))
@mhuebert
mhuebert / get.clj
Created August 4, 2015 16:02
a simple http-get fn
(ns cells.io
(:require
[cljs.core.async :refer [put! chan]]
[goog.net.XhrIo :as xhr]))
(defn GET [path]
(let [c (chan)]
(xhr/send path #(do
(put! c (-> % .-target .getResponseText)) "GET"))
c))
@mhuebert
mhuebert / cljs-example.md
Last active August 29, 2015 14:26
ClojureScript with zero dependencies (browser)

ClojureScript from master w/ zero dependencies

  1. git clone https://github.com/clojure/clojurescript.git
  2. cd clojurescript; ./scripts/uberjar
  3. (^this creates cljs.jar in clojurescript/target; you will use it below)
  4. Create the following directory & file structure
 foo
 ├── build.clj
@mhuebert
mhuebert / eval-with-ns.cljs
Last active August 29, 2015 14:26
`def` in a namespace, cljs.js/eval
(cljs/eval (cljs/empty-state)
'(def x 1)
{:eval cljs/js-eval
:context :expr
:def-emits-var true
:ns cells.core
}
#(pprint %))
@mhuebert
mhuebert / oculus-mac-2015-july-30.md
Last active August 29, 2015 14:26
Oculus - Unity - Mac, July 30 / 2015

assuming you've already installed the Oculus runtime & it's working on your machine

  1. start unity (version 5.1.2f1 - download)
  2. edit > project settings > player, scroll to the bottom of panel on right side of page, "Other Settings", check "Virtual Reality Supported"
  3. command-p exits full-screen (remember this - ESC does not work)
  4. assets > import package > custom package... - select OculusUtilities.unitypackage (download)
  5. on the pop-up panel- keep selections as-is, just click import
  6. see "assets" panel at bottom of window. double-click OVR > Scenes > Cubes (or whatever scene you want)
  7. press play
@mhuebert
mhuebert / core.cljs
Last active August 29, 2015 14:25
CLJS javascript dependency load order?
; I want to use the files referenced in deps.cljs
; - CodeMirror must run before -overlay, -subpar, and -match-brackets.
(ns my-project.core
(:require
[CodeMirror]
[CodeMirror-overlay]
[CodeMirror-subpar]
[CodeMirror-match-brackets]
[reagent.core :as r :refer [cursor]]
@mhuebert
mhuebert / reagent-cursors-test.cljs
Created July 4, 2015 23:20
Reagent Cursors Test
(ns app.layout
(:require
[reagent.core :as r]
[reagent.cursor :refer [cursor]]))
(defonce my-state (r/atom {1 "aaa"
2 "bbb"}))
(defn display-item [item-cursor id]
(fn []