Skip to content

Instantly share code, notes, and snippets.

View gtrabanco's full-sized avatar
:octocat:

Gabriel Trabanco gtrabanco

:octocat:
View GitHub Profile
@gtrabanco
gtrabanco / debian-based-server-initial.sh
Last active April 27, 2024 14:26
Initial setup for ubuntu/debian server
#!/usr/bin/env bash
if ! command -p sudo -n -v > /dev/null 2>&1; then
echo "Execute this script as admin by using sudo writing:"
echo " sudo !!"
echo
fi
# Update
apt update -y
@gtrabanco
gtrabanco / tua.yaml
Last active April 21, 2024 20:59
Rest sensor for Oviedo local Buses
# You need to change last param of the resource url for your stop number
# You need to change "A" for whatever your line it is
# You can view all default params information stop here:
#. https://www.tua.es/es/lineas-y-horarios/paradas/uria-centro-1218.html?idLinea=6#paradasIda
# homeassistant:
# packages:
# rest: !include tua.yaml
input_text:
@gtrabanco
gtrabanco / git-public-keys.sh
Last active April 19, 2024 16:11
Shell script to use my github ssh keys to access my server and updates automatically daily =)
#!/usr/bin/env bash
# GIT_USERNAME=""
GIT_PUBLIC_KEYS_AUTHORIZED_KEYS_FILE="${GIT_PUBLIC_KEYS_AUTHORIZED_KEYS_FILE:-${HOME}/.ssh/authorized_keys}"
GIT_PUBLIC_KEYS_START="## Start of git public keys"
GIT_PUBLIC_KEYS_STOP="## End of git public keys"
tmp_file=$(mktemp)
clean() {
rm -f "$tmp_file" "${GIT_PUBLIC_KEYS_AUTHORIZED_KEYS_FILE}.gitkeys"
@gtrabanco
gtrabanco / object-group-by.js
Last active March 28, 2024 18:07
Object.groupBy polyfill
if(typeof Object.groupBy === typeof undefined) {
Object.groupBy = (arr, callback) => {
return arr.reduce((acc = {}, ...args) => {
const key = callback(...args);
acc[key] ??= []
acc[key].push(args[0]);
return acc;
}, {})
}
}
@gtrabanco
gtrabanco / TunnelToLocalhost.sh
Last active February 17, 2024 11:16
Tunnel remote connection to ssh server tunneling to localhost to move files to local, copy files, use copy&paste...
#!/usr/bin/env bash
# To use this script see comments
write::out() {
echo "$@"
}
write::log() {
[[ ! -z "$DEBUG" ]] && write::out "$@"
#!/bin/bash
# Delete all duplicate rules
/sbin/service iptables save
/sbin/iptables-save | awk '/^COMMIT$/ { delete x; }; !x[$0]++' > /tmp/iptables.conf
/sbin/iptables -F
/sbin/iptables-restore < /tmp/iptables.conf
/sbin/service iptables save
/sbin/service iptables restart
if [ -f /tmp/iptables.conf ] ; then /bin/rm -f /tmp/iptables.conf ; fi
@gtrabanco
gtrabanco / bun-sse.ts
Created November 15, 2022 15:00
Bun Server Sent Events
// bun --hot sse.ts
import { randomUUID } from "node:crypto";
import { EventEmitter } from "node:events";
const sseEvents = new EventEmitter();
export const sse = (data) => {
sseEvents.emit(
"sse",
`id: ${randomUUID()}\ndata: ${JSON.stringify(data)}\n\n`
@gtrabanco
gtrabanco / keybase-gpg.sh
Last active October 14, 2023 21:27
Import existing GPG keys from Keybase wizard and configure it for GIT
#!/usr/bin/env bash
#shellcheck disable=SC2016
set -euo pipefail
if [[ -z "${DOTLY_PATH:-}" ]] || ! output::empty_line > /dev/null 2>&1; then
red='\033[0;31m'
green='\033[0;32m'
bold_blue='\033[1m\033[34m'
normal='\033[0m'
@gtrabanco
gtrabanco / style.css
Created August 31, 2023 13:25
Dark mode en 3 líneas
/* Source: https://twitter.com/midudev/status/1652957687015940097 */
background-color: Canvas;
color: CanvasText;
color-scheme: light dark;
@gtrabanco
gtrabanco / runtime.js
Last active August 24, 2023 16:20
Get the runtime, browser or web worker
function isBun() {
return Boolean(globalThis.Bun);
}
function isDeno() {
return Boolean(globalThis.Deno);
}
function isNode() {
return Boolean(globalThis.process?.versions?.node);