Skip to content

Instantly share code, notes, and snippets.

View wandersoncferreira's full-sized avatar
🐢

bartuka wandersoncferreira

🐢
View GitHub Profile
@wandersoncferreira
wandersoncferreira / complex_business_process_example.clj
Last active August 9, 2021 12:42
Example of a complex business process to implement in Clojure. Alternative implementation using State Machine. Link to didibus original https://gist.github.com/didibus/ab6e15c83ef961e0b7171a2fa2fe925d
(ns didibus-example.core
"A stupid example of a more complex business process to implement as a flowchart."
(:require [tilakone.core :as tk :refer [_]]))
;;;; Config
(def config
"When set to :test will trigger the not-boosted branch which won't write to db.
When set to :prod will trigger the boosted branch which will try to write to the db."
@wandersoncferreira
wandersoncferreira / pgformatter_installer.sh
Created June 14, 2021 12:51
pgFormatter installer for Fedora 34
#!/usr/bin/env bash
# 1. Download pgFormatter Release
wget https://github.com/darold/pgFormatter/archive/refs/tags/v5.0.zip
# 2. Unzip
unzip v5.0.zip
# 3. Install Perl Dependencies
sudo dnf install perl-ExtUtils-MakeMaker perl-autodie perl-open perl-FindBin
@wandersoncferreira
wandersoncferreira / pomegranate-and-clj-refactor.el
Last active March 20, 2021 12:05
Integration of Pomegranate with clj-refactor to bring back hot-reload of new dependencies
;; Experimental configuration to hotload refactor
;; using Pomegranate from Cemerick
;; From https://www.eigenbahn.com/2020/05/06/fast-clojure-deps-auto-reload
;; and integrated into clj-refactor.
(defun bk/send-to-repl (sexp eval ns)
(cider-switch-to-repl-buffer ns)
(goto-char cider-repl-input-start-mark)
(delete-region (point) (point-max))
(save-excursion
;;; fold-clojure-setup --- provide dwim folding for Clojure buffers
;;; Commentary:
;; Based on this great work from Alpaphapha
;; https://gist.github.com/alphapapa/79ea7c33d03c9c975634559b1a776418
;;; Code:
(defcustom bk/clj-outline-regexp "\\(;;;?\\{1,8\\} \\|\\((\\w+\\)\\)"
@wandersoncferreira
wandersoncferreira / setup-git.el
Last active December 19, 2020 13:49
Open magit-diff-buffer using other-window
(defun bk/magit-display-diff-other-window (buffer)
"Display BUFFER in same-window but for magit-diff use other-window instead."
(display-buffer
buffer (if (with-current-buffer buffer (derived-mode-p 'magit-diff-mode))
'(display-buffer-pop-up-window)
'(display-buffer-same-window))))
(setq magit-display-buffer-function
#'bk/magit-display-diff-other-window)
@wandersoncferreira
wandersoncferreira / setup-minibuffer.el
Last active December 8, 2020 14:15
Select candidates from minubuffer using M-{number} (up to 10 candidates)
(use-package general
:ensure t)
(defun selectrum-define-keys ()
(dotimes (i (min selectrum-num-candidates-displayed 10))
(general-define-key
:keymaps 'selectrum-minibuffer-map
(format "M-%d" (mod (1+ i) 10))
`(lambda ()
(interactive)
(defmacro demangle [sym]
(let [prefix# (str (gensym))
name# (symbol (str prefix# sym))
fn# `(defn ~name# [] (str (quote ~sym)))]
`(-> ~fn#
var-get
class
str
(clojure.string/split (re-pattern ~prefix#))
last

Data Readers

I've read about the subject, but I want to look closer. The following analysis will be ECA (Exploratory Clojure Analysis) on data readers and I hope more people can benefit from it.

What are data readers?

Functions used to read specific tagged literals. For example, #inst "2020-10-05" is a built-in literal in Clojure and if you

Clojure assertion

Discussing with a colleague about some issues with dynamic programming languages and I quickly run into the rationale that programming with assertions is a common practice around this world. The idea would be to protect your function from a bad input or output state.

I am not entirely sure on that, and by far I can't speak for the industry, and I found fews posts about the subject such as Life with dynamic typing from David Nolen, but nothing too concrete. Anyway, I want to dig

(ns secland.gen-contract
(:require [cadastro-de-pessoa.cnpj :as cnpj]
[clojure.test.check.generators :as gen]
[java-time :as java-time])
(:import java.time.ZoneId))
(defn date-converter [date]
(java-time/java-date
(.toInstant
(.atStartOfDay date (ZoneId/systemDefault)))))