Skip to content

Instantly share code, notes, and snippets.

View nha's full-sized avatar
🐢
https://turtlequeue.com

nha

🐢
https://turtlequeue.com
View GitHub Profile
;;; Author: Scott Jaderholm
;;; Created: 2009-12-18
;;;
;;; Short Description: Automates the creation of unit conversion
;;; functions and includes several common ones.
;;;
;;; Detailed Description: So for inches, feet, and meters, if you
;;; provide equations for inches-to-feet and feet-to-meters, then this
;;; package will automatically create feet-to-inches, meters-to-feet,
;;; inches-to-meters, meters-to-inches, and all the corresponding
;; an answer to http://kotka.de/blog/2010/03/The_Rule_of_Three.html#summary
;; memoize from core.clj:
(defn memoize
[f]
(let [mem (atom {})]
(fn [& args]
(if-let [e (find @mem args)]
(val e)
(let [ret (apply f args)]
;annotation syntax
(import [java.lang.annotation Retention RetentionPolicy Target ElementType]
[javax.xml.ws WebServiceRef WebServiceRefs])
(definterface Foo (foo []))
;annotation on type
(deftype ^{Deprecated true
Retention RetentionPolicy/RUNTIME
javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]
@david-mcneil
david-mcneil / inheritance.clj
Created November 4, 2010 01:05
Demonstration of implementation "inheritance" in clojure
;; Define a "base type" of Dog
(defrecord Dog [breed])
;; Define a "sub type" of TrainedDog
(defrecord TrainedDog [dog word])
;; The interface that both Dog and TrainedDog will implement
(defprotocol Talker
(bark [_])
(speak [_])
@lynaghk
lynaghk / main.clj
Created January 6, 2012 15:26
Cassowary constraint solver in ClojureScript
;;Using the Cassowary constraint solver from ClojureScript
;;This demo shows using multimethods for readable constraint syntax using +, -, and =.
;;Output is a row of circles with random radii spaced so that the space between their boundaries is uniform.
(ns c2.main
;;refer-clojure :exclude is currently broken in ClojureScript master
;;Ticket open: http://dev.clojure.org/jira/browse/CLJS-114
;;Fix applied here: https://github.com/lynaghk/clojurescript/tree/114-refer-clojure-exclude
(:refer-clojure :exclude [+ - =])
@fogus
fogus / main.clj
Created January 17, 2012 21:26 — forked from lynaghk/main.clj
Cassowary constraint solver in ClojureScript
;;Using the Cassowary constraint solver from ClojureScript
;;This demo shows using multimethods for readable constraint syntax using +, -, and =.
;;Output is a row of circles with random radii spaced so that the space between their boundaries is uniform.
(ns c2.main
;;refer-clojure :exclude is currently broken in ClojureScript master
;;Ticket open: http://dev.clojure.org/jira/browse/CLJS-114
;;Fix applied here: https://github.com/lynaghk/clojurescript/tree/114-refer-clojure-exclude
(:refer-clojure :exclude [+ - =])
@david-mcneil
david-mcneil / custom-clojure-map.clj
Created January 26, 2012 20:43
Creating a custom Clojure map type
(ns people
(:use [clojure.string :only (join)]
[clojure.pprint :only (pprint simple-dispatch)]))
;; we can make maps using the special literal form:
{:a 100
:b 200}
(class {:a 100 :b 200})
@blacktaxi
blacktaxi / custom-clojure-map.clj
Created January 27, 2012 07:04 — forked from david-mcneil/custom-clojure-map.clj
Creating a custom Clojure map type
(ns people
(:use [clojure.string :only (join)]
[clojure.pprint :only (pprint simple-dispatch)]))
;; we can make maps using the special literal form:
{:a 100
:b 200}
(class {:a 100 :b 200})
@grodtron
grodtron / quine.clj
Created May 7, 2012 01:53
A Clojure Quine
(fn [] (let [s "(fn [] (let [s %s] (format s (pr-str s))))"] (format s (pr-str s))))
@mardambey
mardambey / KafkaEmbedded.scala
Created May 10, 2012 02:58
Embedded Kafka broker / producer / simple consumer in a single process useful for testing or for persistent queues.
import java.util.Properties
import kafka.server.KafkaServer
import kafka.server.KafkaConfig
import kafka.producer.ProducerConfig
import kafka.producer.Producer
import kafka.message.Message
import kafka.producer.ProducerData
import kafka.consumer.ConsumerConfig
import kafka.consumer.Consumer
import kafka.utils.Utils