Skip to content

Instantly share code, notes, and snippets.

View vvvvalvalval's full-sized avatar

Valentin Waeselynck vvvvalvalval

View GitHub Profile
@vvvvalvalval
vvvvalvalval / aynchronous-errors.clj
Last active February 27, 2024 15:49
Asynchronous error management in Clojure(Script)
;; Synchronous Clojure trained us to use Exceptions, while asynchronous JavaScript has trained us to use Promises.
;; In contexts where we work asynchronously in Clojure (in particular ClojureScript), it can be difficult to see a definite way of managing failure. Here are some proposals.
;; OPTION 1: adapting exception handling to core.async CSPs
;; As proposed by David Nolen, with some macro sugar we use Exceptions in go blocks with core async in the same way we would do with synchronous code.
(require '[clojure.core.async :as a :refer [go]])
;; defining some helper macros
(defn throw-err "Throw if is error, will be different in ClojureScript"
@vvvvalvalval
vvvvalvalval / gist:c6c2d991bdc96cce4c14
Last active February 11, 2024 19:34
Asynchronous map function with clojure.core.async
(require '[clojure.core.async :as a])
(defn- seq-of-chan "Creates a lazy seq from a core.async channel." [c]
(lazy-seq
(let [fst (a/<!! c)]
(if (nil? fst) nil (cons fst (seq-of-chan c)) ))))
(defn map-pipeline-async "Map for asynchronous functions, backed by clojure.core.async/pipeline-async .
From an asynchronous function af, and a seq coll, creates a lazy seq that is the result of applying the asynchronous function af to each element of coll.
@vvvvalvalval
vvvvalvalval / datomic_datalog_count-related-entities-with-zero-sums.clj
Last active December 15, 2023 23:40
Datomic datalog: counting related entities with 0 sums
@vvvvalvalval
vvvvalvalval / keywordize_at_keys.clj
Last active May 18, 2023 18:17
Clojure : keywordize values at specific keys
(ns utils.keywordize-at-keys
(:require [clojure.walk :as walk]))
(defn- coerced-to-keyword
[k]
(when (string? k)
(keyword k)))
(defn keywordize-at-keys
@vvvvalvalval
vvvvalvalval / datomic-erasing-data-migration.clj
Created April 25, 2018 09:59
Erasing data from Datomic via a manual data migration
;; # EMULATING DATOMIC EXCISION VIA MANUAL DATA MIGRATION
;; *************************************
;; ## Introduction
;; *************************************
;; This Gist demonstrates a generic way to migrate an entire Datomic database
;; from an existing 'Origin Connection' to a clean 'Destination Connection',
;; while getting rid of some undesirable data and otherwise preserving history.
@vvvvalvalval
vvvvalvalval / Day6.kt
Last active December 26, 2018 21:45 — forked from ygrenzinger/Day6.kt
Advent of Code
import java.io.File
import java.util.*
import java.util.concurrent.atomic.AtomicInteger
data class Coordinate(val x: Int, val y: Int)
data class Point(val label: Int, val coordinate: Coordinate)
data class area(val associatedToPoint: Point, val size: Int = 0)
var seqId = AtomicInteger(1)
@vvvvalvalval
vvvvalvalval / README.md
Last active November 7, 2018 10:32
REPLCP - Copy last REPL output

REPLCP

Small dev utility for copying REPL output to the clipboard.

Installation

Via deps.edn, typically in an alias:

{:deps
@vvvvalvalval
vvvvalvalval / mock-connection.clj
Last active September 19, 2018 06:09
Mocking datomic.Connection for fast in-memory testing
(ns bs.utils.mock-connection
"Utilities for using Datomic"
(:require [datomic.api :as d])
(:use clojure.repl clojure.pprint)
(:import (java.util.concurrent BlockingQueue LinkedBlockingDeque)
(datomic Connection)))
(defrecord MockConnection
[dbAtom, ^BlockingQueue txQueue]
@vvvvalvalval
vvvvalvalval / log4j.properties
Last active September 1, 2018 22:29
Clojure Logging: routing Timbre logs to Papertrail via log4j
log4j.rootLogger=INFO, syslog
log4j.appender.syslog=org.apache.log4j.net.SyslogAppender
log4j.appender.syslog.Facility=LOCAL7
log4j.appender.syslog.FacilityPrinting=false
log4j.appender.syslog.Header=true
log4j.appender.syslog.SyslogHost=<PAPERTRAIL_HOST>.papertrailapp.com:<PAPERTRAIL_PORT>
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.syslog.layout.ConversionPattern==%p: (%F:%L) %x %m %n
(defn pprint-to-clipboard
"Copies a pretty-printed representation of value `v` to the clipboard.
When `v` is not supplied, copies the last REPL output (*1).
Useful for copying and pasting REPL output to an editor buffer."
([]
(pprint-to-clipboard *1))
([v]
(-> (java.awt.Toolkit/getDefaultToolkit)
.getSystemClipboard
(.setContents