Skip to content

Instantly share code, notes, and snippets.

View christianromney's full-sized avatar
🏠
Working from home

Christian Romney christianromney

🏠
Working from home
View GitHub Profile
/* This is my interface, my API, my contract. */
interface IReservation {
IList<IGuest> getGuests();
Duration getLength();
Amount getBalance();
Amount getTotal();
bool cancel();
// By the way pay() could have been in IPaymentMethod as well but you know what?
// I called first and so I win!
// Or both of us would end up implementing pay() in which case we would smartly delegate
/*
Hi, I'm Reservation.
I dont need an interface because I am a carrier of data.
Like a good carrier, I can be instantiated in any layer and used
in any other layer.
[CR] Nomenclature! "Data carriers" are *not* domain models. They are
DataTransferObjects (DTOs). What I call domain model, you seem to call
Service Object, whereas what I mean by "Service Object" is something
altogether different...so maybe this is part of the reason we're not
@christianromney
christianromney / knn.clj
Created September 16, 2012 15:04 — forked from davidandrzej/knn.clj
k-Nearest Neighbors (kNN) supervised classifier
; Standard k nearest neighbors classifier
; Does not handle
; > 2 classes
; even values of k
; any bad input, really
;
; David Andrzejewski (andrzeje@cs.wisc.edu)
;
; Command-line arguments
; 0 training data filename
@christianromney
christianromney / gist:3889040
Created October 14, 2012 16:08 — forked from ddeaguiar/gist:3889008
One way to identify neighbors
(ns simple-csp.core)
(def arcs [
#{:sa :wa}
#{:sa :nt}
#{:sa :q}
#{:sa :nsw}
#{:sa :v}
#{:wa :nt}
#{:nt :q}
@christianromney
christianromney / gist:3889041
Created October 14, 2012 16:08 — forked from ddeaguiar/gist:3889008
One way to identify neighbors
(ns simple-csp.core
( :refer-clojure :exclude [==])
(:use clojure.core.logic))
(defne arco [x y]
([:sa :wa])
([:sa :nt])
([:sa :q])
([:sa :nsw])
([:sa :v])
@christianromney
christianromney / core.clj
Created October 17, 2012 20:35 — forked from ddeaguiar/core.clj
Simple functions to calculate weighted averages in Clojure
(ns rubric.core)
(defn average
"Averages a set of scores"
[& scores]
(/ (apply + scores) (count scores)))
(defn- sum-of
"Sum the collection after applying the given function"
[f coll]
/*
Hi, I'm Reservation.
I dont need an interface because I am a carrier of data.
Like a good carrier, I can be instantiated in any layer and used
in any other layer.
If you need to do stuff with me you should know to instantiate the correct
service and pass me to it.
Makes sense too since I you might need other classes to instantiate service
(defn filter-col [a]
(filter (juxt #(< 30 %) odd?) a))
(defn report-results [col]
(println col)
col)
(-> (range 100)
filter-col
report-results)

Clojure does Objects Better

A hopefully short and concise explanation as to how Clojure deals with Objects. If you already write Clojure, this isn't for you.

You know what an Interface is if you write/read Java or PHP 5+. In Clojure it might be called defprotocol.

user> (defprotocol IABC
        (also-oo [this])
        (another-fn [this x]))

IABC

Recent improvements to the ClojureScript compiler have greatly simplified setting up development versus production outputs.

This example uses Figwheel as something that you want to exclude for production, but the pattern is general.

With this simple setup you only need one html file/view and it will work for developement and production.