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

Setup udev rule for HDMI cable

Create script that checks HDMI status and executes xrandr:

#!/usr/bin/env bash

export DISPLAY=":0.0"

USER="$(who | grep ${DISPLAY}\) | cut -f 1 -d ' ' | head -n1)"
@caioaao
caioaao / collisions.clj
Last active May 4, 2022 23:09
Solution to Nubank's collision exercise, in Clojure
(ns collisions.core
(:require [clojure.string :as str])
(:gen-class))
(defn str->edge [s]
(->> (str/split s #" ")
(map #(Integer/parseInt %))))
(defn file-contents->edges [s]
(->> (str/split s #"\n")
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`