Skip to content

Instantly share code, notes, and snippets.

View MonkeyAndres's full-sized avatar
🧠
Unlearning what I give for granted

Andrés Martín Angulo MonkeyAndres

🧠
Unlearning what I give for granted
View GitHub Profile
@MonkeyAndres
MonkeyAndres / result.ts
Created May 15, 2024 05:01
Result implementation in TS for easier error handling.
type Success<T> = {
success: true;
data: T;
};
type Failure<E = Error> = {
success: false;
error: E;
};
@MonkeyAndres
MonkeyAndres / rabbit-kata.md
Last active July 8, 2022 13:28
Hopping rabbit kata.

Rabbit kata

There's a piece of land with N number of boxes and a rabbit. You're playing a guessing game with the rabbit, you have to guess in which box the rabbit is but before every guess the rabbit is going to jump either to the box on the left or the one on the right.

The function below implements the rabbit logic and allow you to perform guesses. You must write a function capable of finding the rabbit every time.

const startRabbitGame = (fieldLength) => {
  let rabbitPosition = Math.floor(Math.random() * fieldLength)
@MonkeyAndres
MonkeyAndres / .skhdrc
Last active June 25, 2022 15:13
Custom configuration for skhd keyboard shortcuts
# SPACES
alt + cmd - 1 : yabai -m space --focus 1
alt + cmd - 2 : yabai -m space --focus 2
alt + cmd - 3 : yabai -m space --focus 3
alt + cmd - 4 : yabai -m space --focus 4
alt + cmd - 5 : yabai -m space --focus 5
alt + cmd - 6 : yabai -m space --focus 6
alt + cmd - 7 : yabai -m space --focus 7
# MOVE WINDOW TO SPACE
@MonkeyAndres
MonkeyAndres / .yabairc
Created June 25, 2022 15:10
Custom configuration for Yabai window manager.
#!/usr/bin/env sh
sudo yabai --load-sa
yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"
yabai -m config layout bsp
yabai -m config window_topmost off
yabai -m config auto_balance off
yabai -m config split_ratio 0.50
const EXAMPLE_GRAPH = {
A: [['B', 2]],
B: [['C', 1], ['D', 3], ['E', 5]],
C: [['D', 2]],
D: [['C', -3]],
E: []
}
const getPathFromParents = (start, end, parents) => {
// NOTE: Impossible to find path due to a negative cycle
@MonkeyAndres
MonkeyAndres / topological-sort.js
Created June 16, 2022 17:35
Custom implementation of Topological Sort algorithm.
const EXAMPLE_GRAPH = {
A: ['B'],
B: ['C', 'D', 'E'],
C: ['D'],
D: [],
E: []
}
const topologicalSort = (graph) => {
const reverselySortedStack = []
@MonkeyAndres
MonkeyAndres / connected-components.js
Created June 16, 2022 16:51
Algorithm to identify connected components inside a graph
const EXAMPLE_GRAPH = {
A: ['B', 'C'],
B: [],
C: [],
D: ['E'],
E: ['F'],
F: []
}
@MonkeyAndres
MonkeyAndres / depth-first-search.js
Created June 16, 2022 16:28
Custom implementation of DFS algorithm.
const EXAMPLE_GRAPH = {
A: ['B', 'C'],
B: [],
C: ['D'],
D: []
}
const depthFirstSearch = (graph, startingNode) => {
const visited = {}
@MonkeyAndres
MonkeyAndres / knn-algorithm.js
Last active June 14, 2022 14:05
Custom implementation of KNN. (only for educational purposes)
const WEATHER_CONDITIONS = {
SUNNY: 0,
CLOUDY: 1,
RAINING: 2,
};
const CLOTHES = {
HOT: 0, // Short bottom and top
MID_HOT: 1, // Short bottom and light jacket
MID_COLD: 2, // Long bottom and mid jacket
@MonkeyAndres
MonkeyAndres / binarySearch.js
Created June 13, 2022 16:22
Custom implementation of Binary Search.
const binarySearch = (sortedList, query) => {
if (sortedList.length === 0) {
throw new Error('Not here')
}
const halfIndex = Math.floor((sortedList.length - 1) / 2)
if (sortedList[halfIndex] === query) {
return sortedList[halfIndex]
}