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 / 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 ...)
@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 / 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 / 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):
postwalk comes from clojure.walk/postwalk (namespace might be cljs.walk in cljs, you'll have to check)
may need to look at prewalk, i didn't test so dunno. also didn't pay attention to which (pre or post) is more efficient in this case (if they both work)
(postwalk
(fn [item]
(let [t (:type item)]
(if (or (not (map? item))
(nil? t)
(= t filter-type))
item
; ok
(println foo
bar
baz
quux)
; ok
(println
foo
bar
(defn infect [{inputs :pathogen/infected
immune :pathogen/immune
traits :pathogen/diseases
:as c}]
;'([protocol [output-key output-fn]] [protocol [output-key output-fn]])
(->>
(for [infected (->> (or (seq inputs) (keys c))
(filter (complement (or immune #{})))
(map (partial get c)))
[protocol [output-key output-fn]] traits]
template <typename T> constexpr T bitfield (T bit) { return 1 << bit; }
namespace Telemetry {
enum TelemetryType {
Guage = bitfield(0),
Counter = bitfield(1),
Debug = bitfield(2),
Info = bitfield(3),
Warn = bitfield(4),
Error = bitfield(5)
(def rui-components
{'list rui/list
'list-item rui/list-item})
(def component-registry
(merge
rui-components
{}))
(def my-template
@danielytics
danielytics / helpers.hpp
Created March 5, 2018 20:02
Helper template functions for registering and emitting Godot signals with arguments from GDNative
#ifndef HELPERS_H
#define HELPERS_H
#include <core/Godot.hpp>
#include <core/Dictionary.hpp>
#include <core/String.hpp>
#include <Node.hpp>
namespace helpers {