Skip to content

Instantly share code, notes, and snippets.

View gtrabanco's full-sized avatar
:octocat:

Gabriel Trabanco gtrabanco

:octocat:
  • Spain
View GitHub Profile
@gtrabanco
gtrabanco / import-default-function-or-function-as-edge-function.ts
Created May 28, 2024 17:21
Import function to send as string with post method
import { existsSync } from 'node:fs';
export async function importDefaultFunctionOrFunctionAsEdgeFunction(filePathOrFn: string | Function) {
let fnString = filePathOrFn;
if (typeof filePathOrFn === "string" && existsSync(filePathOrFn)) {
const { default: fn } = await import(filePathOrFn);
fnString = fn.toString();
}
FROM oven/bun:1-debian
ENV DBUS_SESSION_BUS_ADDRESS autolaunch:
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chrome that Puppeteer
# installs, work.
RUN apt update -y
RUN apt install -y wget gnupg
RUN apt install -y \
@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 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 / object-group-by.js
Last active May 14, 2024 21:30
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>