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 / 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 / debian-based-server-initial.sh
Last active April 19, 2024 15:06
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 / 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 / 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 / typescript.json
Last active July 16, 2023 15:44
Snippets for typescript VSCode
{
"zschema": {
"prefix": "zschema",
"body": [
"export const $1Schema = z.$2($3);",
"export type ${1/(.*)/${1:/pascalcase}/} = z.infer<typeof $1Schema>;",
"",
"$0"
],
"description": "Creates a function wrapper for a model's attribute."
@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);
@gtrabanco
gtrabanco / snake-camel.ts
Created June 27, 2023 16:32
Snake & Camel cases conversors
77
export type RemoveUnderscoreFirstLetter<S extends string> =
S extends `${infer FirstLetter}${infer U}`
? `${FirstLetter extends '_' ? U : `${FirstLetter}${U}`}`
: S;
export type CamelToSnakeCase<S extends string> =
S extends `${infer T}${infer U}`
? `${T extends Capitalize<T> ? '_' : ''}${RemoveUnderscoreFirstLetter<
Lowercase<T>
@gtrabanco
gtrabanco / parser.ts
Last active May 23, 2023 00:54
Idea to parse document
import { genericMapToType } from './generic-map-to-type.ts';
export type ScraperSetter = (property: string, value?: any) => void;
type Key = Exclude<any, Function>;
type Value = Exclude<any, Function>;
export type ScrapeHandler = {
selector: string;
handler: HTMLRewriterTypes.HTMLRewriterElementContentHandlers;
@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`