Skip to content

Instantly share code, notes, and snippets.

View danielytics's full-sized avatar
🚰

Dan Kersten danielytics

🚰
  • Dublin, Ireland
View GitHub Profile
@danielytics
danielytics / crdt_counter.py
Last active February 9, 2016 15:45
Playing with CRDTs
class Counter(object):
"""Increment-only counter"""
def __init__(self, peer_id):
self._peer_id = peer_id
self._counters = {peer_id: 0}
def increment(self):
self._counters[self._peer_id] += 1
def value(self):
@danielytics
danielytics / repl.clj
Last active January 13, 2016 17:33
Useful functions for retrieving items from a list
user=> (def items [{:id 1 :data "hi"}
{:id 2 :data "ho"}
{:id 3 :data "test"}])
#'user/items
user=> (first-where items :id = 1)
{:data "hi", :id 1}
user=> (first-where items :id > 1) ; will return only the first matching item
{:data "ho", :id 2}
user=> (get-where items :id > 1) ; will return all matching items
[{:data "ho", :id 2}
@danielytics
danielytics / gist:d4374cd51deec7201250
Last active March 7, 2018 16:24
Wrap React components for access in Reagent
;; Eclipse Public License 1.0 http://opensource.org/licenses/eclipse-1.0.php
(defn make-wrapped-component
"Wrap a React component in such a way that the raw JS component is accessible.
Useful for for calling methods on the native React component."
[component]
(fn [attrs & children]
(r/create-class
{:component-did-mount
(fn [this]
@danielytics
danielytics / gist:3c51258a351b7c46f7e0
Created May 28, 2014 00:52
Clojure Om component communication example
(defn child [props owner {:keys [ch]}]
(reify
om/IInitState
(init-state [_]
{:text ""})
om/IRenderState
(render-state [_ {:keys [text editable?]}]
(dom/div nil
(if editable?
(dom/input ...)