Skip to content

Instantly share code, notes, and snippets.

View serioga's full-sized avatar

Sergey Trofimov serioga

View GitHub Profile
;; The deps.edn file describes the information needed to build a classpath.
;;
;; When using the `clojure` or `clj` script, there are several deps.edn files
;; that are combined:
;; - install-level
;; - user level (this file)
;; - project level (current directory when invoked)
;;
;; For all attributes other than :paths, these config files are merged left to right.
;; Only the last :paths is kept and others are dropped.
@serioga
serioga / exception.clj
Created August 3, 2023 14:11
Helper functions to work with exceptions
(ns lib.clojure.exception
(:require [clojure.test :as test]
[lib.clojure-string.core :as string']
[lib.clojure.lang :as lang])
(:import (clojure.lang Associative ExceptionInfo)))
(set! *warn-on-reflection* true)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@serioga
serioga / map_entries.clj
Last active May 6, 2022 06:54
Create map from sequence using transducer
(ns map-entries
(:import (clojure.lang MapEntry)))
(defn map-entries
"Returns transducer collecting map-entries from the sequence of keys/values.
Map key is `(kf k)` or just key if `kf` is nil. Map value is `(vf k v)` or
just value if `vf` is nil. Raises exception in case of odd amount of elements
in the input sequence."
([] (map-entries nil nil))
([kf] (map-entries kf nil))
@serioga
serioga / flexiana_test_task.clj
Last active December 29, 2021 05:40
flexiana-test-task
(ns user.flexiana-test-task
"https://twitter.com/itunderhood/status/1475580051571757065
https://github.com/Terbiy/flexiana-test-task/blob/main/test/flexiana_test_task/core_test.clj"
(:require [clojure.test :refer :all]))
(set! *warn-on-reflection* true)
;;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
(defn scramble? [a b]
@serioga
serioga / browser.cljc
Created August 10, 2021 07:24
CLJS REPL in browser.
(ns dev.env.cljs-repl.browser
"CLJS REPL in browser. See https://clojurescript.org/reference/repl.
Run local clojure.main REPL with `-m dev.env.cljs-repl.browser` parameters to work from Cursive."
(:require [cljs.repl :as repl]
[cljs.repl.browser :as browser]))
;•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
(def ^:private output-dir "out/repl/browser")
(ns edn-benchmark
"For https://twitter.com/GirlGameDev/status/1299153999057375237
https://github.com/naomijub/edn-duration-benchmark"
(:require [clojure.edn :as edn]))
(set! *warn-on-reflection* true)
;;;; tested in REPL with `criterium.core/quick-bench`
;;;; windows 10, CPU 3.30 GHz, RAM 16 GB
;;;; clojure "1.10.1", java 11
@serioga
serioga / core.clj
Created May 7, 2020 16:45
Example how to handle postgresql arrays in result set (next.jdbc)
(ns app.database.core
(:require
[app.database.sql-array :as sql-array]))
(set! *warn-on-reflection* true)
; SQL Helper functions
(defn text-array
@serioga
serioga / integrant.clj
Created January 27, 2020 13:55
Integrant extention for parallel initialization
(ns app.lib.util.integrant
"Adapted integrant functionality.
Features:
- system rollback on failures;
- futures in `init-key` and `halt-key!` for parallel initialization."
(:require
[app.lib.util.exec :as exec]
[clojure.tools.logging :as log]
[integrant.core :as ig]
[vonstierlitz.online.util.logging-context :as logging-context]))
@serioga
serioga / armstrong.clj
Last active January 9, 2020 10:17
Armstrong
(ns task.armstrong
"Task description: create function to check if integer is an
armstrong number https://en.wikipedia.org/wiki/Narcissistic_number.
For https://t.me/clojure_ru/103457."
(:require
[clojure.test :as t]))
(set! *warn-on-reflection* true)
@serioga
serioga / cljs_logging.cljc
Created February 23, 2019 19:18
Simple logging to console in ClojureScript
(ns app.lib.util.cljs-logging
#?(:cljs
(:require-macros app.lib.util.cljs-logging)))
#?(:clj (set! *warn-on-reflection* true) :cljs (set! *warn-on-infer* true))
#?(:cljs
(do
(def console-fns