This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns rabbit-mq-test.core | |
(:require [clojure.core.async :refer [chan dropping-buffer]]) | |
(:import [com.rabbitmq.client ConnectionFactory Connection Channel QueueingConsumer Consumer DefaultConsumer] | |
)) | |
(set! *warn-on-reflection* true) | |
(defprotocol Lifecycle | |
(start [service]) | |
(stop [service])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro sq [x] | |
x) | |
(defmacro mmeta [x] | |
(meta x)) | |
(mmeta (sq | |
(42))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Channels consist of a maximum of 3 queues: | |
;; chan -> [pending-puts buffer pending-takes] | |
;; if a buffer is full or empty, the puts or takers will park, and a callback will | |
;; be put into the pending-puts/pending-takes queue. Once a value is available, a | |
;; callback will be taken from the queue and the callback will be dispatched. | |
;; The 1024 limit is on the pending-puts and pending-takes, not on the buffer | |
;; (the buffer can be any size the user requests). | |
;; This will work (all values can go directly into the buffer) | |
(def c (chan 10000)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun nrepl-eval-expression-at-point-in-repl () | |
(interactive) | |
(let ((form (nrepl-expression-at-point))) | |
;; Strip excess whitespace | |
(while (string-match "\\`\s+\\|\n+\\'" form) | |
(setq form (replace-match "" t t form))) | |
(set-buffer "*nrepl*") | |
(goto-char (point-max)) | |
(insert form) | |
(nrepl-return))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.core.async) | |
(defprotocol ISendable | |
(channel [this])) | |
(defn async-agent [state] | |
(let [c (chan Long/MAX_VALUE) ;; <<-- unbounded buffers are bad, but this matches agents | |
a (atom state)] | |
(go-loop [] | |
(when-let [[f args] (<! c)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns crosstalk.core | |
(:require [eliza-clj.engine :refer :all])) | |
(def engines [(create-engine) | |
(create-engine)]) | |
(reduce | |
(fn [s engine] | |
(let [v (process-input engine s)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns extend-core-logic.core | |
(:require [clojure.core.logic :refer :all] | |
[clojure.core.logic.protocols :refer [walk]] | |
[clojure.java.io :as jio] | |
[clojure.string :as string]) | |
(:import [java.io BufferedReader StringReader])) | |
;; from: http://federalgovernmentzipcodes.us/ | |
(defn load-db [] | |
(let [data (java.io.BufferedReader. (java.io.StringReader. (slurp "/Users/tim/Downloads/free-zipcode-database.csv"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns main-ns) | |
(defprotocol BadReify | |
(do-stuff [this])) | |
(defn wrap-stuff [x] | |
(reify | |
BadReify | |
(do-stuff [this] | |
x))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [take-c (chan 1)] | |
(go | |
(loop [pending [] | |
tout (timeout 1000)] | |
(alt! [take-c] ([v] (let [new-pending (conj pending v)] | |
(if (> max-pending (count new-pending)) | |
(do (thread (process-stuff pending)) | |
(recur [] (timeout 1000))) | |
(recur new-pending tout)))) | |
[tout] ([_] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun nrepl-eval-expression-at-point-in-repl () | |
(interactive) | |
(let ((form (nrepl-expression-at-point))) | |
;; Strip excess whitespace | |
(while (string-match "\\`\s+\\|\n+\\'" form) | |
(setq form (replace-match "" t t form))) | |
(set-buffer (nrepl-find-or-create-repl-buffer)) | |
(goto-char (point-max)) | |
(insert form) | |
(nrepl-return))) |