Skip to content

Instantly share code, notes, and snippets.

@domkm
domkm / view.cljs
Created May 21, 2014 01:44
TypeError: Cannot read property 'firstChild' of undefined
(defn render-str [el]
(dom/render-to-str
(om/build
(fn [data owner]
(reify
om/IRender
(render [_] el)))
{})))
(render-str (dom/div nil))
@domkm
domkm / silk.clj
Last active August 29, 2015 14:05
(defrecord User [id])
; --------------------
; unmatch on Routes
(def routes
(silk/routes [[User ["users" (silk/integer :id)]]]))
(silk/unmatch routes User (User. 42)) ; you can use a record as a params map
@domkm
domkm / fsm.clj
Last active August 29, 2015 14:05
(require '[automat.core :as a])
(-> [1 2 (a/$ :conj) 3 4 (a/$ :conj)]
(a/compile {:reducers {:conj conj}})
(a/find nil [1 2 3 4])
:value)
;=> (4 2)
(-> [1 a/any (a/$ :conj) 3 4 (a/$ :conj)]
(a/compile {:reducers {:conj conj}})
### Keybase proof
I hereby claim:
* I am DomKM on github.
* I am domkm (https://keybase.io/domkm) on keybase.
* I have a public key whose fingerprint is E8A7 7F7C FC53 EE8E 59FA 5468 0A66 DE7B 9E89 228D
To claim this, I am signing this object:
@domkm
domkm / namespace.clj
Last active August 29, 2015 14:13
ClojureScript reads records as maps. Bug?
(ns namespace)
(defrecord Language [name])
(defmacro lang [name]
(->Language name))
(def clj
(lang "Clojure"))
@domkm
domkm / gist:3536189
Created August 30, 2012 18:13
Dev Bootcamp Birthday Torture
def happy_birthday(name, torture_level = 100)
hb = "Happy Birthday to You."
song = "#{hb} #{hb} Happy Birthday Dear #{name}. #{hb}"
song.chars.reduce do |memo, char|
%w[a e i o u y].include?(char) ? memo + char * torture_level : memo + char
end
end
@domkm
domkm / broadbrim.datomic.api.cljc
Created December 16, 2015 07:57
Datomic EntityMap wrapper for DataScript consistency
;;;; Entity wrapper
#?(:clj (declare ->EntityMap))
#?(:clj (deftype EntityMap [^datomic.query.EntityMap entity ^boolean ident?]
Object
(hashCode [this]
(.hashCode entity))
(equals [this o]
(and (instance? (class this) o)
(.equals entity (.entity o))))
@domkm
domkm / gist:5769839
Created June 12, 2013 22:54
delegate methods to a serialized hash
class Asset < ActiveRecord::Base
def self.data_delegate(*methods)
methods.each do |method|
define_method(method) { data.send "[]", method }
define_method("#{method}=") { |val| data.send "[]=", method, val }
end
end
end
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix.
;;
;; * :use makes functions available without a namespace prefix
;; (i.e., refers functions to the current namespace).
;;
;; * :import refers Java classes to the current namespace.
;;
@domkm
domkm / react_relay.clj
Created April 4, 2017 23:07
This is an incredibly hacky ClojureScript wrapper for Relay 0. While we used this in production at one point, I would recommend against doing so. I'm only uploading it for posterity. Relay 1, which decouples the React wrapper from the GraphQL client, will enable us to write a good CLJS wrapper, as opposed to this abomination.
(ns broadbrim.react-relay
(:require
[cljs.core :refer [specify! this-as js-arguments js-obj]]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.macro :as macro]
[me.raynes.conch :as conch]
[potemkin]
[sablono.core :as sablono]
[taoensso.timbre :as log]))