Skip to content

Instantly share code, notes, and snippets.

View reborg's full-sized avatar

reborg reborg

View GitHub Profile
;; (defn full-name ...) is equivalent to:
;; (def full-name (fn []...)) which defines a Var
;; object called full-name pointing at a compiled function
;; returning the static string "Oliv"
(defn full-name [] "Oliv")
;; greetings is a function taking two args.
;; it returns a function of no argument
;; invoking the second argument (f) with no arguments
;; and combining a string with it.
@reborg
reborg / frequencies-rf-xform.clj
Last active November 19, 2017 17:06
Explorations around frequencies as a reducing function for transducers, sequential or parallel.
(require '[criterium.core :refer [quick-bench]])
(require '[clojure.core.reducers :as r])
(import '[java.util HashMap Collections Map]
'java.util.concurrent.atomic.AtomicInteger
'java.util.concurrent.ConcurrentHashMap)
(set! *warn-on-reflection* true)
;; 500k maps with the same key. value are overlapping 1/5 of the time.
(def data
(into []
@reborg
reborg / count-enterprise-ed.clj
Created November 16, 2017 14:00
Investigations on fast counting
(require '[criterium.core :refer [quick-bench]])
(require '[clojure.core.reducers :as r])
(import 'java.util.concurrent.atomic.AtomicInteger)
(set! *warn-on-reflection* true)
(def data
(into []
(map hash-map
(repeat :samplevalue)
(concat
@reborg
reborg / split-by.clj
Created December 15, 2017 14:42
split-by transducer
; Stats by burst with the split-by transducer.
; The input for this example is a (potentially large) collection of events.
; A simplified list of tab separated events would appear like the following:
; 2017-05-04T13:08:57Z\tmsg1
; 2017-05-04T13:10:52Z\tmsg2
; 2017-05-04T13:13:33Z\tmsg3
; 2017-05-04T23:14:10Z\tmsg4
; 2017-05-04T23:16:23Z\tmsg5
@reborg
reborg / runningdiff.clj
Last active February 7, 2018 13:28
Different ways of producing the same running diff with lazy-seqs, core.async or transducers.
;; different ways of producing the same running diff with lazy-seqs, core.async or transducers.
;; the running diff injects a :diff key to each of the maps in the list. The :diff is the difference
;; between the current :value and the :value of the previously seen entry with the same :id.
;; it can be easily changed to process id-related items in a different way.
(def entries [{:id 1 :value 88}
{:id 2 :value 99}
{:id 1 :value 98}
{:id 3 :value 5}
{:id 2 :value 100}

State of Clojure Survey 2018 - Open comment question

This is a selection of the most articulated critique found in the open comments section Q25 at the bottom of the survey. Recurring themes are:

  1. Elitism, ivory tower, "not smart enough to get it" attitude of frequent speaker or early adopters.
  2. Poor basic documentation, error messages, beginner friendly resources.
  3. Fear of contribution (with reasons like a. community-built tools open to attack and replacement by core team b. hostile contribution environment c. closed development process)
  • The community has to grow to create more opportunities. Many organizations don't want to even consider using it because they fear not being able to find Clojure developers. Unless you have a mentor or are extremely motivated, Clojure scares away most imperative developers. My suggestions is to team up with a university and get a Clojure course on Coursera or a similar platform. This is the only way I got in
@reborg
reborg / astar.clj
Last active August 17, 2018 00:59
Clojure implementation of the A* path finding algorithm
;; This is the Wikipedia entry example encoded graph.
(def graph {:orig [{:a 1.5 :d 2} 0]
:a [{:orig 1.5 :b 2} 4]
:b [{:a 2 :c 3} 2]
:c [{:b 3 :dest 4} 4]
:dest [{:c 4 :e 2} 0]
:e [{:dest 2 :d 3} 2]
:d [{:orig 2 :e 3} 4.5]})
(defn a* [graph orig dest]
@reborg
reborg / deps.edn
Last active August 1, 2018 08:15
core.async master/worker pattern with throttling timeout
;; Install Clojure deps and try with:
;; clojure -Sdeps
;; '{:deps {user {:git/url "https://gist.github.com/reborg/ba05335edb09d50e1bd9f0fc5d6593f1"
;; :sha "435181444970c1fa2091283285830c63076fda4b"}}}' -e '(process [1 2 3])'
{:paths ["."]
:deps {org.clojure/core.async {:mvn/version "0.4.474"}}}
@reborg
reborg / conference-radar.md
Last active January 28, 2019 17:56
Conference Radar
@reborg
reborg / clojure-survey-2019-highlights.md
Last active February 4, 2019 23:42
A selection of the most insightful (my opinion) comments to the 2019 Clojure survey

1/8/2019 11:30 AM Clojure was my language of choice for quite a long time, but all the recent developments in the community[1] and lack of clear publicly available vision of the language's future alienates me greatly and makes me feel as an unwanted member of the community. Because of this I'm not considering Clojure anymore for any new development and don't really want to help growing the community by releasing new libraries/supporting existing ones, mentoring new Clojure engineers, speaking at meetups, or just simply recommending Clojure to people I know :( [1] Drift to being dogmatic and hostlie to any alternative thoughts community (or better say cult?), which started long time ago, reached unbearable level last year and I'm not interested in participating in any community even resembling a totalitarian one, even if the language itself is perfect (which Clojure is not). Disclaimer: my feelings are obviously mine alone and I don't claim it's the universal truth and "Clojure is dead", it's just my perso