Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢

bartuka wandersoncferreira

🐢
View GitHub Profile
@wandersoncferreira
wandersoncferreira / complex_business_process_example.clj
Last active Aug 9, 2021
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
View complex_business_process_example.clj
(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 Jun 14, 2021
pgFormatter installer for Fedora 34
View pgformatter_installer.sh
#!/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 Mar 20, 2021
Integration of Pomegranate with clj-refactor to bring back hot-reload of new dependencies
View pomegranate-and-clj-refactor.el
;; 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
View fold-clojure-setup.el
;;; 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 Dec 19, 2020
Open magit-diff-buffer using other-window
View setup-git.el
(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 Dec 8, 2020
Select candidates from minubuffer using M-{number} (up to 10 candidates)
View setup-minibuffer.el
(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)
View demangle.clj
(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
View data_readers.md

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

View clojure-assertion.md

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

View test-check.contracts.clj
(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)))))