Skip to content

Instantly share code, notes, and snippets.

View javascripto's full-sized avatar
:octocat:
Focusing

Yuri Almeida javascripto

:octocat:
Focusing
  • São Paulo - SP
  • 10:20 (UTC -03:00)
View GitHub Profile
@javascripto
javascripto / try-catch.ts
Created May 9, 2025 17:15
await tryCatch
type Success<T> = [T, null];
type Failure<E=Error> = [null, E];
type Result<T, E> = Success<T> | Failure<E>;
/**
* A utility function that wraps a promise and returns a tuple.
* The first element of the tuple is the resolved value or null,
* and the second element is the error or null.
*
* @param promise - The promise to wrap.
# Função para lidar com argumentos nos cinco formatos: -n=valor, e -nValor, -n valor, --nome=valor, --nome valor
# Função para lidar com argumentos nos cinco formatos: -n=valor, -n valor, -nValor, --nome=valor, --nome valor
funcao-com-flag() {
local nome="fulano"
# Processar argumentos curtos, longos e curtos com e sem "="
while [[ $# -gt 0 ]]; do
case "$1" in
# Argumentos curtos sem igual (-n valor)
@javascripto
javascripto / dmg-generator.sh
Last active September 26, 2024 23:05
MacOS bash script app bundle generator (app name + icon path)
#!/bin/bash
if [ -z "$1" ]; then
echo "Use: $0 /path/to/AppBundle.app"
exit 1
fi
APP_PATH="$1"
APP_NAME=$(basename "$APP_PATH" .app)
TMP_DIR="/tmp/${APP_NAME}_dmg"
@javascripto
javascripto / FakeWallpaper.cs
Last active August 13, 2024 22:36
Set a fake wallpaper when user has no permission to set windows wallpaper
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
// Copile with:
// C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:winexe FakeWallpaper.cs
// Compilar with icon file:
@javascripto
javascripto / calculate_MP4_duration.sh
Created September 4, 2023 01:07
A simple shell script to calculate duration of some videos in the current directory with *.MP4 extension
#!/usr/bin/env zsh
pad_zero() {
local NUMBER=$1
if [[ $NUMBER -lt 10 ]]; then echo 0$NUMBER; else echo $NUMBER; fi
}
convert_seconds_to_hours() {
local SECONDS=$1
HOURS=$(expr $SECONDS / 3600)
from http.server import HTTPServer, BaseHTTPRequestHandler
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.end_headers()
file = open('index.html', 'r')
index = file.read()
@javascripto
javascripto / filename-sanitizer.py
Last active September 4, 2022 00:02
File name sanitizer for FAT partitions that does not accept some characters on filename
#!/usr/bin/env python3
import os, re, argparse
NOT_ALLOWED_CHARACTERS_REGEX = r'["*|/\\:<>?\[\]]'
def parse_arguments():
parser = argparse.ArgumentParser(description='Rename file or folder with only allowed characters on FAT partitions')
class CPF {
static CPF_MASK = '$1.$2.$3-$4';
static CPF_REGEX = /(\d{3})(\d{3})(\d{3})(\d{2})/;
static generateFormated() {
return this.format(this.generate());
}
static format(cpf) {
return cpf.replace(this.CPF_REGEX, this.CPF_MASK);
}
export function openTestingPlayground() {
const exec = require("util").promisify(require("child_process").exec);
const originalLogFn = console.log.bind(console);
console.log = function (...args) {
const url = args[0].match(/http.*/)[0];
const commandsForEachPlatform = {
linux: `xdg-open ${url}`,
win32: `start chrome "${url}"`,
darwin: `open ${url}`,
};
@javascripto
javascripto / searchTermInObjectAndPrintPath.js
Created July 31, 2021 09:23
Deep search for term in object keys and values. It logs the path to access the item
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n)
}
function searchTermInObjectAndPrintPath(object, text, path = '') {
text = text.toLowerCase()
for (let [key, value] of Object.entries(object)) {
if (key.toLowerCase().includes(text)) {
// encontrou na key
console.log(path)