Skip to content

Instantly share code, notes, and snippets.

View ckirkendall's full-sized avatar

Creighton Kirkendall ckirkendall

  • Blue Manta Consulting
  • Cincinnati, Ohio
View GitHub Profile
@ckirkendall
ckirkendall / core.clj
Created January 22, 2014 11:44
This was just for fun to see how much effort it would take. It is a functional clojure version of the java bouncy ball tutorial.
(ns bouncy.core
(:require [goog.math :as math :refer [Vec2]]
[goog.math.Vec2 :as vec]))
(declare step draw-circle)
(def app {:elems [{:pos (Vec2. 100 100) :speed (Vec2. -3 5) :radius 20}
{:pos (Vec2. 200 200) :speed (Vec2. 5 3) :radius 30}
{:pos (Vec2. 300 200) :speed (Vec2. 7 6) :radius 5}
{:pos (Vec2. 400 200) :speed (Vec2. -5 -6) :radius 10}
@ckirkendall
ckirkendall / design.markdown
Last active January 3, 2016 22:59
Enliven Component Model

##Sketch for Enliven Component Model

This design page is a sketch of how I see enliven being used for dynamic templates in the browser.

Design Principles

  1. All state is in an application state object.
  2. State is scoped through lenses.
  3. Users should not have to manage lenses manually.
  4. There is no tree walking; paths/lenses, for dom manipulation, are determined at compile time.
(defn bind-view-watch-fn [id render-func]
(let [ky (str "EVB:" nid)]
(fn [ctx ref oval nval]
(let [node (.getElementById js/document id)]
(if node
(render-func node nval)
(remove-watch ref ky))))))
(ns chatter-box.event-bus-test
#+cljs
(:require-macros [cemerick.cljs.test :refer [deftest testing is]]
[cljs.core.async.macros :refer [go]])
(:require
[chatter-box.event-bus :as bus :refer [create-bus Component init accept-message? get-channel]]
#+clj [clojure.test :as test :refer [deftest testing is]]
#+cljs [cemerick.cljs.test :as t]
#+clj [clojure.core.async :as a :refer [alts! <! >! chan timeout go]]
#+cljs [cljs.core.async :as a :refer [alts! <! >! chan timeout]]))
package org.cinjug;
import java.util.Iterator;
interface Seq<T> {
public T next() throws EmptySequenceException;
public T peek() throws EmptySequenceException;
public boolean hasNext();
@ckirkendall
ckirkendall / speller.clj
Created July 8, 2013 20:38
Clojure version of Norvig's spell checker for LambdaJam.
(ns spell-checker.speller)
(defonce training-data (re-seq #"[a-z]+" (.toLowerCase (slurp "/home/ckirkendall/Development/clojure/spelling-jam/data/big.txt"))))
(defonce NWORDS (atom (frequencies training-data)))
(defn deletes [word]
@ckirkendall
ckirkendall / Show.java
Last active December 16, 2015 17:38 — forked from bkyrlach/Show.java
abstract class Show<A> {
public static register(Class c, Show s){
Map<Class,Object> shows=TypeClassFactory.tcs.get(Show.class)
if(shows!=null){
shows.put(c,s);
}else{
shows = new Map<Class,Object>();
shows.put(c,s);
TypeClassFactory.tcs.put(Show.class, shows);
@ckirkendall
ckirkendall / wrap.clj
Last active December 16, 2015 01:49
wrap function in clojure based on Uncle Bob's http://blog.8thlight.com/uncle-bob/2013/01/07/FPBE3-Do-the-rules-change.html. I wrote this to provide a more readable and idiomatic version than what Uncle Bob presented.
(use '[clojure.string :only (split)])
(defn break-long-word [n word]
(if (> (count word) n)
[(take n word) (break-long-word n (drop n word))]
[word]))
(defn break-long-words [n words]
(mapcat #(break-long-word n %) words))
@ckirkendall
ckirkendall / tow-way.clj
Last active December 15, 2015 22:29
Two way relationship with immutable data structure.
(defprotocol XmlNode
(get-parent [_])
(get-children [_]))
(def empty-node
(reify XmlNode
(get-parent [_] nil)
(get-children [_] '())))
;; The macros
;; most macros here alias names from select.cljs
;; they will get used in regular calls
(ns lib.select
(:require
[clojure.string :as str]))
;; selector syntax
(defn intersection [preds]