Skip to content

Instantly share code, notes, and snippets.

View campeterson's full-sized avatar

Cam Peterson campeterson

View GitHub Profile
@burbma
burbma / npmap.clj
Last active December 22, 2020 21:27
Clojure pmap with variable number of threads. Optionally operate on results real time via async/channel.
(defn npmap
"Like pmap but also takes n to specify the number of threads. Also differs
in that it can return the results on a channel. If you don't specify a
channel you will get all the results back in a vector after they are all
done. If you do pass in a channel results will be put on that channel
(by async/pipeline) as they are available. When all computation is done
async/pipeline closes said results channel."
([f n coll]
(->> coll
(npmap f n (async/chan))

React Native + macOS + Clojurescript

image

Project Catalyst

Since the recent release of Catalina, macOS has shipped with the ability to allow iOS/iPAD apps to run on macOS without any modification via a featureset known as Project Catalyst.

This is exciting, as writing React Native + Clojurescript apps as a target for the desktop is much more compelling than a pure Electron app (imo).

I've been working with Apache Kafka for over 7 years. I inevitably find myself doing the same set of activities while I'm developing or working with someone else's system. Here's a set of Kafka productivity hacks for doing a few things way faster than you're probably doing them now. 🔥

Get the tools

@jacekschae
jacekschae / cljs-and-js-comparision.cljs
Last active December 30, 2021 03:49
ClojureScript and JavaScript Comparison - ClojureScript Examples
;; Functions
(defn sum [x y] (+ x y))
;; Shorthand Functions
(def sum #(+ %1 %2))
;; Function Invocation
(sum 3 4)
@jacekschae
jacekschae / cljs-and-js-comparision.js
Last active May 30, 2019 16:51
ClojureScript and JavaScript Comparison - JavaScript Examples
// Functions
function sum(x, y) {
return x + y;
}
// Shorthand Functions
const sum = (x, y) => x + y;
// Function Invocation
sum(3, 4)
@semperos
semperos / deps.edn
Last active September 5, 2019 19:32
Clojure deps.edn Workflow
{:aliases {:dev {:extra-deps
{org.clojure/tools.nrepl {:mvn/version "0.2.13"}
cider/cider-nrepl {:mvn/version "0.17.0-SNAPSHOT"}}}
:std {:extra-paths ["resources"]}
:test {:extra-paths ["test"]}}
:mvn/repos {"private-repo" {:url "https://example.com/repository/maven-releases/"}}}
@ghadishayban
ghadishayban / fuse.clj
Last active January 26, 2019 04:13
"stream fusion" example using transducers
;; lots of garbage
;;
(->> coll ;; original collection
(map #(assoc % :foo :bar)) ;; intermediate Chunked collection 1
(filter :baz) ;; intermediate Chunked collection 2
(map :feature) ;; intermediate Chunked collection 3
(into [])) ;; reduction using #'conj over Chunked collection #3
;; -- direct reduction using transducers --
;; differences from scheme unfold
;; even initial value is lazy
;; predicate sense reversed
;; internal state == produced value, no special mapper-fn
;; no tail-gen
(defn series
"Produces a sequence of values.
`f` is a function that given a value, returns the next value.
`continue?` is a predicate that determines whether to produce
@reborg
reborg / rich-already-answered-that.md
Last active September 25, 2024 17:06
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

@ghadishayban
ghadishayban / productions.clj
Last active November 20, 2021 00:06
unified generators
;;
;; Example usages at the bottom of the file
;;
(defn productions
"Returns a sequence of values by repeatedly calling `produce!` until it
returns `fin`. The sequence can be used lazily/caching or reducible/non-caching.
The arity-2 variant's `produce!` takes no arguments and returns a value
or the terminator.