Skip to content

Instantly share code, notes, and snippets.

View nikolavojicic's full-sized avatar

Nikola Vojičić nikolavojicic

View GitHub Profile
@michiakig
michiakig / ants.clj
Created July 19, 2011 22:37
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;dimensions of square world
@daveray
daveray / seesaw-repl-tutorial.clj
Created December 7, 2011 04:55
Seesaw REPL Tutorial
; A REPL-based, annotated Seesaw tutorial
; Please visit https://github.com/daveray/seesaw for more info
;
; This is a very basic intro to Seesaw, a Clojure UI toolkit. It covers
; Seesaw's basic features and philosophy, but only scratches the surface
; of what's available. It only assumes knowledge of Clojure. No Swing or
; Java experience is needed.
;
; This material was first presented in a talk at @CraftsmanGuild in
; Ann Arbor, MI.
(ns file-watcher
(:require [clojure.set :refer [rename-keys]]
[clojure.java.io :refer [file]])
(:import
[java.nio.file
FileSystems
Path
Paths
StandardWatchEventKinds]))
@ptaoussanis
ptaoussanis / transducers.clj
Last active December 8, 2024 03:24
Quick recap/commentary: Clojure transducers
(comment ; Fun with transducers, v2
;; Still haven't found a brief + approachable overview of Clojure 1.7's new
;; transducers in the particular way I would have preferred myself - so here goes:
;;;; Definitions
;; Looking at the `reduce` docstring, we can define a 'reducing-fn' as:
(fn reducing-fn ([]) ([accumulation next-input])) -> new-accumulation
;; (The `[]` arity is actually optional; it's only used when calling
;; `reduce` w/o an init-accumulator).
@fasiha
fasiha / learn_datalog_today.clj
Created May 10, 2016 03:32
Learn Datalog Today ported to DataScript & Clojure (JVM)
; Learn Datalog Today (http://www.learndatalogtoday.org) is a great resource for
; reading but its interactive query interface is broken. Below is how we can
; load the same data into a Clojure REPL and play with it using DataScript.
; After running the code below, many/most/all? of the queries on Learn Datalog
; Today should be functional.
;
; Create a new lein project, add `[datascript "0.15.0"]` to `project.clj`'s
; `dependencies`, run `lein deps && lein repl` and copy-paste the following in
; chunks, inspecting the outputs as needed.
@cgrand
cgrand / set-game.clj
Last active November 15, 2021 16:42
the SET game in clojure.spec
;; the SET game in clojure.spec
;; inspired by https://github.com/jgrodziski/set-game
(require '[clojure.spec :as s])
(s/def ::shape #{:oval :diamond :squiggle})
(s/def ::color #{:red :purple :green})
(s/def ::value #{1 2 3})
(s/def ::shading #{:solid :striped :outline})
(s/def ::card (s/keys :req [::shape ::color ::value ::shading]))
@reborg
reborg / rich-already-answered-that.md
Last active May 12, 2025 12:44
A curated collection of answers that Rich gave throughout the history of Clojure

Rich Already Answered That!

A list of commonly asked questions, design decisions, reasons why Clojure is the way it is as they were answered directly by Rich (even when from many years ago, those answers are pretty much valid today!). Feel free to point friends and colleagues here next time they ask (again). Answers are pasted verbatim (I've made small adjustments for readibility, but never changed a sentence) from mailing lists, articles, chats.

How to use:

  • The link in the table of content jumps at the copy of the answer on this page.
  • The link on the answer itself points back at the original post.

Table of Content

@olieidel
olieidel / delete_recursive.clj
Last active June 4, 2023 16:12
Delete Directories recursively with Clojure in only 4 lines of code.
(ns yourproject.yourns
(:require [clojure.java.io :as io]))
(defn delete-directory-recursive
"Recursively delete a directory."
[^java.io.File file]
;; when `file` is a directory, list its entries and call this
;; function with each entry. can't `recur` here as it's not a tail
;; position, sadly. could cause a stack overflow for many entries?
;; thanks to @nikolavojicic for the idea to use `run!` instead of
@bhb
bhb / multimethod_selector.clj
Last active November 13, 2019 10:22 — forked from mtnygard/multimethod_selector.clj
A clojure.spec.gen.alpha generator that picks a multimethod implementation from the known set.
(require '[clojure.spec.gen.alpha :as sgen])
;; original
(defn multimethod-selector
"Returns a generator that picks one dispatch value from the known
dispatch values of a multimethod. Defers the lookup of dispatch
values until sampling time, so any defmethods evaluated after the
generator is created may still be selected."
[s]
#(sgen/bind
@robertbraeutigam
robertbraeutigam / CompletionOrderStream.java
Last active March 24, 2020 15:41
Converting a collection of CompletableFutures to completion order Streams.
public static <T> Stream<T> inCompletionOrder(Collection<CompletableFuture<T>> futures) {
BlockingQueue<CompletableFuture<T>> queue = new LinkedBlockingQueue<>();
for (CompletableFuture<T> future: futures) {
future.whenComplete((value,exception) -> queue.add(future));
}
return Stream.generate(noException(queue::take))
.map(CompletableFuture::join)
.limit(futures.size());
}