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 thornydev.go-lightly.boring.select-timeout | |
(:refer-clojure :exclude [peek take]) | |
(:require [thornydev.go-lightly :refer | |
[go stop put take select select-timeout | |
channel timeout-channel with-timeout]])) | |
(defn- boring [msg] | |
(let [ch (channel)] | |
(go (loop [i 0] | |
(put ch (str msg " " i)) |
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
package main; | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
"os" | |
) | |
// Channels-driven concurrency with Go |
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 thornydev.go-lightly.boring.generator-lamina | |
(:require | |
[thornydev.go-lightly.util :refer [go& with-channel-open]] | |
[lamina.core :refer [channel enqueue close | |
closed? read-channel]])) | |
(defn- boring [msg] | |
(let [ch (channel)] | |
(go& (loop [i 0] | |
(when-not (closed? ch) |
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 thornydev.go-lightly.boring.generator-lamina | |
(:require [thornydev.go-lightly.util :refer [go&]] | |
[lamina.core :refer [channel enqueue close | |
closed? read-channel]])) | |
;; this version is REPL-friendly since the deamon go routine | |
;; will exit when the channel is closed | |
(defn- boring [msg] | |
(let [ch (channel)] |
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 thornydev.go-lightly.boring.generator-tq | |
(:require [thornydev.go-lightly :refer [go go& stop]]) | |
(:import (java.util.concurrent LinkedTransferQueue))) | |
(defn- channel [] | |
(LinkedTransferQueue.)) | |
(defn- boring [msg] | |
(let [ch (channel)] |
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 thornydev.go-lightly | |
(:refer-clojure :exclude [peek take]) | |
(:import (java.io Closeable) | |
(java.util ArrayList) | |
(java.util.concurrent LinkedTransferQueue TimeUnit | |
LinkedBlockingQueue TimeoutException))) | |
;; ---[ go routines ]--- ;; | |
(def inventory (atom [])) |
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
package main; | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
"os" | |
) | |
// Channels-driven concurrency with Go |
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 thornydev.top100.heap | |
(:require [thornydev.lib.leftist-heap | |
:refer [pq-first pq-rest pq-insert pq-empty]])) | |
(defn distance [[x y]] | |
(+ (java.lang.Math/abs x) (java.lang.Math/abs y))) | |
(defn dist-lt? [pt1 pt2] | |
(< (distance pt2) (distance pt1))) |
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 thornydev.lib.leftist-heap) | |
;; Implementation of a "leftist priority queue" on an immutable | |
;; heap data structure | |
;; This code was (manually) transpiled into Clojure from | |
;; the Scheme version here: | |
;; http://programmingpraxis.com/2009/05/05/priority-queues/2/ | |
;; ---[ core lib fns ]--- ;; |
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 dist-then-first [pt1 pt2] | |
(let [dist1 (distance pt1) | |
dist2 (distance pt2)] | |
(if (= dist1 dist2) | |
(> (first pt1) (first pt2)) | |
(> dist1 dist2)))) | |
(defn mk-sorted-sift-fn [max-size] | |
(fn [sst pt] | |
(if (< (count sst) max-size) |