Skip to content

Instantly share code, notes, and snippets.

@abp
abp / restrict-map.clj
Created May 29, 2012 15:14 — forked from fogus/restrict-map.clj
Restricting nested maps to keys of interest
;; I could have used a closed dispatch (aka cond) but you may find this version more enjoyable
;; the spec format is the one provided by BG
(defprotocol Selector
(-select [s m]))
(defn select [m selectors-coll]
(reduce conj {} (map #(-select % m) selectors-coll)))
(extend-protocol Selector
@abp
abp / part1.md
Created May 18, 2012 09:40 — forked from fogus/part1.md

Inheritance is a key concept in most object-oriented languages, but applying it skillfully can be challenging in practice. Back in 1989, M. Sakkinen wrote a paper called Disciplined inheritance that addresses these problems and offers some useful criteria for working around them. Despite being more than two decades old, this paper is extremely relevant to the modern Ruby programmer.

Sakkinen's central point seems to be that most traditional uses of inheritance lead to poor encapsulation, bloated object contracts, and accidental namespace collisions. He provides two patterns for disciplined inheritance and suggests that by normalizing the way that we model things, we can apply these two patterns to a very wide range of scenarios. He goes on to show that code that conforms to these design rules can easily be modeled as ordinary object composition, exposing a solid alternative to tradi

@abp
abp / gist:2721724
Created May 17, 2012 21:38 — forked from swannodette/gist:2719676
unify_datums.clj
(ns datomic-play.core
(:use [datomic.api :only [db q] :as d])
(:require [clojure.core.logic :as l]
[clojure.pprint :as pp]))
(def uri "datomic:dev://localhost:4334/hello")
(defprotocol IUnifyWithDatum
(unify-with-datum [u v s]))
@abp
abp / gist:2645634
Created May 9, 2012 15:37 — forked from stuarthalloway/gist:2645453
Datomic queries against collections
;; Datomic example code
(use '[datomic.api :only (db q) :as d])
;; ?answer binds a scalar
(q '[:find ?answer :in ?answer]
42)
;; of course you can bind more than one of anything
(q '[:find ?last ?first :in ?last ?first]
"Doe" "John")
@abp
abp / Actor.java
Created May 2, 2012 22:04 — forked from viktorklang/Actor.java
Minimalist Java Actors
// ©2012 Viktor Klang
// 6,016 bytes jarred.
package java.klang;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
public class Actor {
public static interface Fun<T, R> { public R apply(T t); }
public static interface Effect extends Fun<Behavior, Behavior> { };
public static interface Behavior extends Fun<Object, Effect> { };
public static interface Address { Address tell(Object msg); };
@abp
abp / reinvoke.cljs
Created April 9, 2012 22:01 — forked from alandipert/reinvoke.cljs
It's sweet that IFn is a protocol in ClojureScript
(extend-type js/RegExp
cljs.core.IFn
(-invoke ([this s] (re-matches this s))))
(#"foo.*" "foobar") ;=> "foobar"
(#"zoo.*" "foobar") ;=> nil
(filter #".*foo.*" ["foobar" "goobar" "foobaz"]) ;=> ("foobar" "foobaz")
@abp
abp / listbox-model-example.clj
Created March 21, 2012 13:25 — forked from daveray/listbox-model-example.clj
List box model binding example
; very basic example of driving a listbox with binding in Seesaw
(use 'seesaw.core)
(require '[seesaw.bind :as b])
; create a text box and a listbox next to each other
(defn make-ui []
(frame
:size [400 :by 400]
:content (left-right-split
(scrollable (text :id :text :multi-line? true))
@abp
abp / gist:2125898
Created March 19, 2012 19:53 — forked from fogus/gist:2124742
giftube – Generates an animated gif from a YouTube url.
#!/usr/bin/env ruby
# giftube – Generates an animated gif from a YouTube url.
#
# Usage:
#
# giftube [youtube url] [minute:second] [duration]
#
# ex.
#
@abp
abp / macrofn.clj
Created March 16, 2012 07:54 — forked from alandipert/macrofn.clj
invoke a macro like a function
; Invoke a macro like a function - if you dare.
; ______
; .-" "-.
; / \
; _ | | _
; ( \ |, .-. .-. ,| / )
; > "=._ | )(__/ \__)( | _.=" <
; (_/"=._"=._ |/ /\ \| _.="_.="\_)
; "=._ (_ ^^ _)"_.="
; "=\__|IIIIII|__/="
@abp
abp / gist:1992402
Created March 7, 2012 10:22 — forked from weavejester/gist:1982807
Initial thoughts on Datomic

Initial thoughts on Datomic

Rich Hickey (of [Clojure][1] fame) has released a cloud-based database called [Datomic][2] that has some interesting properties.

Datomic is an log of assertions and retractions of "facts", much as a DVCS like [Git][3] is a log of code diffs. The state of the database at any one time is the sum of all the assertions and retractions up to that date.