Skip to content

Instantly share code, notes, and snippets.

View caioaao's full-sized avatar
🏠
Working from home

Caio Oliveira caioaao

🏠
Working from home
View GitHub Profile
export const useCancelTask = (taskUUID: string) => {
const queryClient = useQueryClient();
return useMutation(
() => (
api.cancelTask(taskUUID).then(res => res.data)
), {
onSuccess: data => defaultOnSuccess(queryClient, data),
mutationKey: ["tasks", "cancel", {uuid: taskUUID}],
}
);
@caioaao
caioaao / helm-eglot-code-actions.el
Created February 17, 2021 13:01
Example snippet using Eglot code-actions with Helm
(defun helm-eglot--build-code-actions-source (menu-items)
(let* ((execute-selected-action (lambda (action) (eglot--code-actions-execute-action (cdr (assoc action menu-items))))))
(helm-build-sync-source "Eglot Code actions"
:candidates
(lambda () (mapcar #'car menu-items))
:action `(("Execute action" . ,execute-selected-action)))))
(defun helm-eglot-code-actions (beg &optional end action-kind)
"Offer to execute code actions between BEG and END using helm.
Interactively, if a region is active, BEG and END are its bounds,
@caioaao
caioaao / Audio-Technica ATH-M40x ParametricEQ.json
Created January 29, 2021 13:08
PulseEffects presets for ATH-M40X, as described here: https://github.com/jaakkopasanen/AutoEq
{"spectrum": {"show": "true", "n-points": "100", "height": "100", "use-custom-color": "false", "fill": "true", "show-bar-border": "true", "scale": "1", "exponent": "1", "sampling-freq": "10", "line-width": "2", "type": "Bars", "color": ["1", "1", "1", "1"], "gradient-color": ["0", "0", "0", "1"]}, "output": {"blacklist": "", "plugins_order": ["limiter", "autogain", "gate", "multiband_gate", "compressor", "multiband_compressor", "convolver", "bass_enhancer", "exciter", "crystalizer", "stereo_tools", "reverb", "equalizer", "delay", "deesser", "crossfeed", "loudness", "maximizer", "filter", "pitch"], "bass_enhancer": {"state": "false", "input-gain": "0", "output-gain": "0", "amount": "0", "harmonics": "8.5", "scope": "100", "floor": "20", "blend": "0", "floor-active": "false", "listen": "false"}, "compressor": {"state": "false", "input-gain": "0", "output-gain": "0", "mode": "Downward", "attack": "20", "release": "100", "threshold": "-12", "ratio": "4", "knee": "-6", "makeup": "0", "sidechain": {"listen": "false
(load-extension "libfive-guile" "scm_init_libfive_modules")
(use-modules (libfive kernel) (libfive vec) (libfive csg) (libfive shapes) (libfive transforms))
(define test-shape
(difference
(sphere 1 #[0 0 0])
(cylinder-z 0.6 2 #[0 0 -1])
(reflect-xz (cylinder-z 0.6 2 #[0 0 -1]))
(reflect-yz (cylinder-z 0.6 2 #[0 0 -1]))))
(shape->mesh test-shape "out.stl" 10 '((-2 . 2) (-2 . 2) (-2 . 2)))
@caioaao
caioaao / common_config.clj
Last active February 14, 2020 15:57
buddy keys aero tagged literals
(ns common.config
(:require [aero.alpha.core :as aero.alpha]
[aero.core :as aero]
[clojure.java.io :as io]
[buddy.core.keys :as buddy.keys]))
(defn- rewrap [tl]
(fn [v] (tagged-literal (:tag tl) v)))
(defmethod aero.alpha/eval-tagged-literal 'priv-key
@caioaao
caioaao / core.clj
Created February 6, 2020 18:14
Testing garbage collection of keywords
(ns leak-test.core
(:gen-class))
(def alphanumerics (concat (map char (range (int \A) (inc (int \Z))))
(range 0 10)))
(defn random-alphanumeric-string [len]
"Generates a pseudo-random alphanumeric string"
(apply str (repeatedly len #(rand-nth alphanumerics))))
@caioaao
caioaao / playground.clj
Last active January 29, 2020 14:53
state-flow stack trace
(ns playground
(:require [state-flow.core :as state-flow]
[state-flow.state :as state]))
(defn inc-a [s]
(update s :a inc))
(defn change-state []
(state/modify inc-a))
@caioaao
caioaao / range_consolidation.clj
Created April 22, 2019 12:34
Solution for range consolidation challenge from purelyfunctional.tv newsletter
(ns caioaao.purely-functional.solutions.range-consolidation)
(defn ranges->events [vs]
(mapcat (fn [[a b]] [[:open a] [:close b]]) vs))
(def type->priority
{:open 1
:close 2})
;; since range includes both ends, `open` events have priority over `close`

PF.tv challenge

Let’s first write a function to check the outputs. Since it’s quite simple, I’ll use the example from the problem definition and a couple of corner cases:

(defn spy [x] (prn x) x)
(ns aeron-cluster-test.core
(:require [clojure.stacktrace :refer [print-stack-trace]])
(:import [org.agrona CloseHelper]
[org.agrona.concurrent AgentTerminationException]
[org.agrona ExpandableArrayBuffer]
[org.agrona ErrorHandler]
[io.aeron.cluster ClusteredMediaDriver ConsensusModule ConsensusModule$Context]
[io.aeron.cluster.client EgressListener AeronCluster AeronCluster$Context ]
[io.aeron.cluster.service ClusteredService ClusteredServiceContainer ClusteredServiceContainer$Context Cluster ClusteredServiceAgent ClientSession]