This file contains hidden or 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 topics.core | |
(:require [clamq.activemq :refer :all] | |
[clamq.protocol.connection :as connection] | |
[clamq.protocol.producer :as producer] | |
[clamq.protocol.consumer :as consumer])) | |
(def broker (activemq-connection "tcp://localhost:61616")) | |
(def topic "computational-topic") | |
(def producer (connection/producer broker {:pubSub true})) |
This file contains hidden or 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
(defn divider [a b] | |
(try | |
(/ a b) | |
(catch java.lang.ArithmeticException e | |
"Dividing by 0!"))) | |
(divider 10 2) ; => 5 | |
(divider 10 0) ; => Dividing by 0! |
This file contains hidden or 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
(defn divider [a b] | |
(/ a b)) | |
(with-handler! #'divider | |
java.lang.ArithmeticException | |
(fn [e a b] "Dividing by 0!")) | |
(divider 10 2) ; => 5 | |
(divider 10 0) ; => Dividing by 0! |
This file contains hidden or 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 dire-example.core | |
(:require [dire.core :refer [with-precondition with-precondition! supervise]])) | |
(defn func1 [x] | |
{:pre [(< x 2)]} | |
"I have the precondition inline! (Clojure default)" | |
(println x " received a number smaller 2")) | |
(defn func2 [y] | |
"I outsourced the precondition in a cool AOP style using dire" |
This file contains hidden or 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 dire-examples.bad-core | |
(:require [dire.core :refer [with-precondition! with-postcondition!]])) | |
(defn save-user [& {:keys [username email password state]}] | |
(if (and (and (> (count username) 4) (< (count username) 11)) | |
(and (> (count password) 6) (re-matches #".*\d.*" password)) | |
(re-matches #"\w+@\w+\.\w+" "[email protected]") | |
(re-matches #"[A-Z]{2}" state)) | |
(let [result :ok] ; Or :not-ok | |
"Persist the user to a database here." |
This file contains hidden or 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
def divider a, b | |
a / b | |
end | |
handlers = {} | |
handlers[TypeError] = | |
Proc.new { |e| puts "Type exception occured." } | |
handlers[ZeroDivisionError] = |
This file contains hidden or 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 clotp.core | |
(:require [clojure.core.match :refer [match]])) | |
(def next-process-id (atom 0)) | |
(def processes (atom {})) | |
(defn next-pid [] | |
(swap! next-process-id inc)) | |
(defn spawn [f & args] |
This file contains hidden or 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
user> (def fiz (take 15 (cycle [nil nil "Fiz"]))) | |
#'user/fiz | |
user> (def buzz (take 15 (cycle [nil nil nil nil "Buzz"]))) | |
#'user/buzz | |
user> (map (partial apply str) (map list fiz buzz)) | |
("" "" "Fiz" "" "Buzz" "Fiz" "" "" "Fiz" "Buzz" "" "Fiz" "" "" "FizBuzz") |
This file contains hidden or 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
-module(core). | |
-export([future/1, f/0]). | |
f() -> | |
timer:sleep(20000), | |
"My result.". | |
future(F) -> | |
Res = F(), % Evaluate ASAP. | |
receive % Wait until it's dereferenced to divulge the result. |
This file contains hidden or 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
-module(core). | |
-export([front_end_task/0, task/1, main/1]). | |
%% Call fn | |
%% Get back a future | |
%% Dereference | |
%% - Blocks until if not done, then returns | |
%% - If done, returns immediately | |
task(Pid) -> |