Skip to content

Instantly share code, notes, and snippets.

View D1360-64RC14's full-sized avatar
👨‍💻
Learning

Diego Garcia D1360-64RC14

👨‍💻
Learning
View GitHub Profile
@D1360-64RC14
D1360-64RC14 / index.js
Created March 15, 2024 17:53
Hello Wold!
console.log("Hello World!")
@D1360-64RC14
D1360-64RC14 / golang-update.sh
Last active December 16, 2023 20:59
Update golang with only one command. REQUIRED program "jq".
#!/bin/bash
LAST_VERSION_NUMBER=$(curl -s "https://go.dev/dl/?mode=json" | jq ".[0].version" | sed 's/"//g' | sed 's/go//')
DOWNLOAD_URL="https://go.dev/dl/go${LAST_VERSION_NUMBER}.linux-amd64.tar.gz"
BASE_DIR="/opt/go"
FOLDER_NAME="go-${LAST_VERSION_NUMBER}"
UNPACK_DST="${BASE_DIR}/${FOLDER_NAME}"
if [ -d "${UNPACK_DST}" ]; then
echo "Already installed last version ${LAST_VERSION_NUMBER}!"
@D1360-64RC14
D1360-64RC14 / extension.js
Created December 7, 2023 13:24
HTMX Extension class boilerplate
import htmx from "htmx.org";
class ExtensionName {
/** @private @type {WeakMap<HTMLElement, ExtensionName>} */
static _elementInstances = new WeakMap();
/** @private @type {HTMLElement} */ _rootElement;
/**
* @param {HTMLElement} element
@D1360-64RC14
D1360-64RC14 / git-spull
Created October 26, 2023 16:46
Git commands to automate repetitive tasks. Store then in a directory accessible by PATH and do `git <command>`, like `git spull`.
#!/bin/bash
# Stash -> Pull -> Pop
git stash
git pull
git stash pop
@D1360-64RC14
D1360-64RC14 / discord-update-apt.sh
Last active July 21, 2024 04:29
Update discord with only one command
#!/bin/bash
GENERIC_DOWNLOAD_URL='https://discord.com/api/download?platform=linux&format=deb'
FILE_DOWNLOAD_URL=$(curl -v -L -I "$GENERIC_DOWNLOAD_URL" 2>&1 | grep -o -i -E "'https://dl.discordapp.net/.*?'" | sed "s/'//g")
FILE_NAME=$(basename $FILE_DOWNLOAD_URL)
FILE_DEST=/tmp/$FILE_NAME
echo "[*] Installing new Discord '$FILE_NAME' from '$FILE_DOWNLOAD_URL' to '$FILE_DEST'..."
@D1360-64RC14
D1360-64RC14 / bfs_graph_traversal.go
Last active July 20, 2023 02:37
Graph traversal algorithms. Made during Fireship video: https://youtu.be/cWNEl4HE2OE
// Breadth-First Search: check if there are any routes between two points in graph
package main
import (
"errors"
"fmt"
)
var airports = [...]Node{"PHX", "BKK", "OKC", "JFK", "LAX", "MEX", "EZE", "HEL", "LOS", "LAP", "LIM"}
var routes = [...]*Edge[Node]{
@D1360-64RC14
D1360-64RC14 / remap.ts
Created June 25, 2023 20:28
Remap: a way of doing filter and map at the same time.
// remap gets the array you want to process and the callback function, passing to it the same properties as a map.
// The data returned by the callbackFn will be filtered out if undefined, or mapped in if something else.
// Everything at the cost of only one loop pass.
function remap<T, R>(array: T[], callbackFn: (value: T, index: number, array: T[]) => R | undefined): R[] {
const result = new Array<R>();
for (let i = 0; i < array.length; i++) {
const data = callbackFn(array[i], i, array);
if (data !== undefined) result.push(data);
@D1360-64RC14
D1360-64RC14 / ia_names.txt
Created May 19, 2023 16:02
6651 possíveis nomes de IAs
Name source: https://brasil.io/dataset/genero-nomes/files
Code: https://gist.github.com/D1360-64RC14/ac018f8a26eae81f27ad4cf4de5dcae1
MarIA
AntonIA
MarcIA
PatricIA
LeticIA
JulIA
VitorIA
import csv
NAME = 0
FREQUENCY = 1
file = open("nomes.csv", "r")
name_reader = csv.DictReader(file)
# CATIA -> CatIA
@D1360-64RC14
D1360-64RC14 / sudoas.sh
Last active June 8, 2023 16:58
Run last command as sudo. Place the code in .bashrc
function sudoas {
local LAST_COMMAND=$(history 2 | head -n 1 | sed -E 's/ [[:digit:]]+ //')
echo "> sudo $LAST_COMMAND"
sudo $LAST_COMMAND
}