Skip to content

Instantly share code, notes, and snippets.

@abp
abp / debug-wrap.clj
Created November 23, 2011 08:41 — forked from fogus/debug-wrap.clj
(defn push-wrap [v wrap & args]
(alter-var-root v #(with-meta (apply wrap % args) {::orig %})))
(defn pop-wrap [v]
(alter-var-root v #(if-let [m (::orig (meta %))] m %)))
(defn post [orig post-printer]
(fn [& args]
(let [rtn (apply orig args)]
(post-printer orig rtn args)
(ns mars-rovers.core)
(def dirs [:N :E :S :W])
(def move-dir {:N [0, 1] :E [1, 0] :S [0, -1] :W [-1, 0]})
(defn turn [dir dirs]
(second
(drop-while
(complement #(= % dir))
(ns mars-rovers.core)
(def dirs [:N :E :S :W])
(def move-dir {:N [0, 1] :E [1, 0] :S [0, -1] :W [-1, 0]})
(defn turn [dir dirs]
(second
(drop-while
(complement #(= % dir))
@abp
abp / core.clj
Created January 4, 2012 09:52 — forked from hiredman/core.clj
defbean
(ns pharoh.core
(:import #_(org.drools.compiler DrlParser)
#_(org.drools.spi Consequence)
(java.beans PropertyChangeSupport)))
(definterface IBean
(init [])
(addPropertyChangeListener [pcl])
(removePropertyChangeListener [pcl]))
@abp
abp / delegating-proxy.clj
Created February 2, 2012 10:01 — forked from fogus/delegating-proxy.clj
A ridiculous proxy macro which delegates calls to methods which have not been explicitly implemented to a specified object.
;;; Written when pondering
;;; http://stackoverflow.com/questions/9086926/create-a-proxy-for-an-specific-instance-of-an-object-in-clojure
(defmacro delegating-proxy [o class-and-ifaces ctor-args & impls]
(let [oname (gensym)]
(letfn [(delegating-impls [^java.lang.reflect.Method ms]
(let [mname (symbol (.getName ^java.lang.reflect.Method (first ms)))
arity-groups (partition-by #(count (.getParameterTypes ^java.lang.reflect.Method %)) ms)
max-arity (max-key #(count (.getParameterTypes ^java.lang.reflect.Method %)) ms)]
`(~mname
@abp
abp / gist:1992397
Created March 7, 2012 10:20 — forked from stuarthalloway/gist:1980351
frinj unit conversion running inside a Datomic datalog query
;; lein settings
(defproject foo "1.0.0-SNAPSHOT"
:description "Test App"
:dependencies [[com.datomic/datomic "0.1.2678"]
[frinj "0.1.2" :exclusions [org.clojure/clojure]]])
;; load libs
(use 'frinj.core 'frinj.calc)
(frinj-init!)
(use '[datomic.api :only (q db) :as d])
@abp
abp / pom2proj.clj
Created March 7, 2012 10:20 — forked from fogus/pom2proj.clj
Convert Maven pom.xml file to Lein project.clj
(ns pom2proj
(:require [clojure.xml :as xml]
[clojure.zip :as zip]
[clojure.java.io :as io]
[clojure.data.zip.xml :as zx])
(:use [clojure.pprint :only [pprint]]))
(defn- text-attrs
[loc ks]
(map (fn [k]
@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.

@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: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.
#