Skip to content

Instantly share code, notes, and snippets.

View uqmessias's full-sized avatar
🤓
Being a Nerd...

Uilque Messias uqmessias

🤓
Being a Nerd...
View GitHub Profile
/**
* @param {number} num
* @returns {string}
*/
function formatMoney(num) {
return `R$ ${num
.toFixed(2)
.replace('.', ',')
.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1.')}`;
}
@uqmessias
uqmessias / aposentadoria.js
Created July 26, 2024 15:49
Função para calcular a quantidade de meses que alguém poderia gastar um determinado dinheiro considerando o rendimento desse dinheiro e também para calcular quanto de dinheiro se consegue juntar com o rendimento mensal.
const fs = require("fs");
const path = require("path");
const crypto = require("crypto");
const stream = require("stream/promises");
const readline = require("readline");
const { totalmem } = require("os");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
@uqmessias
uqmessias / README.md
Last active July 20, 2024 01:21
CLI tool to help me to remove duplicate files in a folder (recursively)

Remove duplicate files CLI

How to use it

$ node ./removeDuplicateFilesCli.js
const SALARIO_MINIMO_MENSAL = 1320;
/**
* @param {number} valor
* @param {number} casaDecimais (para o valor `10.2345678`, usar 0 => 10, 1 => 10.2, 2 => 10.23, 3 => 10.235)
*/
function arredondar(valor, casasDecimais) {
const multiplicador = Math.pow(10, casasDecimais);
return Math.round(valor * multiplicador) / multiplicador;
}
@uqmessias
uqmessias / rgb-color-bitwise-conversion-kotlin.kt
Created February 20, 2023 23:46
It converts an RGB Int into a vector with R, G, and G color parts. It also does the same by inverting the R with G (this is needed for an internal project). And all of this in Kotlin
import java.awt.Color
/**
* Got from https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS44LjEwIiwicGxhdGZvcm0iOiJqYXZhIiwiYXJncyI6IiIsIm5vbmVNYXJrZXJzIjp0cnVlLCJ0aGVtZSI6ImlkZWEiLCJjb2RlIjoiaW1wb3J0IGphdmEuYXd0LkNvbG9yXG4vKipcbiAqIFlvdSBjYW4gZWRpdCwgcnVuLCBhbmQgc2hhcmUgdGhpcyBjb2RlLlxuICogcGxheS5rb3RsaW5sYW5nLm9yZ1xuICovXG5mdW4gbWFpbigpIHtcbiAgICB2YWwgcmdiOiBJbnQgPSAweDFmOGI1NFxuICAgIFxuICAgIHZhbCByZ2JSZWRDb2xvcjogSW50ID0gKHJnYiBzaHIgMTYpIGFuZCAweEZGXG4gICAgdmFsIHJnYkdyZWVuQ29sb3I6IEludCA9IChyZ2Igc2hyIDgpIGFuZCAweEZGXG4gICAgdmFsIHJnYkJsdWVDb2xvcjogSW50ID0gcmdiIGFuZCAweEZGXG4gICAgXG4gICAgdmFsIGdiclJlZENvbG9yOiBJbnQgPSByZ2IgYW5kIDB4RkZcbiAgICB2YWwgZ2JyR3JlZW5Db2xvcjogSW50ID0gKHJnYiBzaHIgOCkgYW5kIDB4RkZcbiAgICB2YWwgZ2JyQmx1ZUNvbG9yOiBJbnQgPSAocmdiIHNociAxNikgYW5kIDB4RkZcbiAgICBcbiAgICB2YWwgZ2JyOiBJbnQgPSAocmdiUmVkQ29sb3IgYW5kIDB4RkYpIG9yICgocmdiR3JlZW5Db2xvciBhbmQgMHhGRikgc2hsIDgpIG9yICgocmdiQmx1ZUNvbG9yIGFuZCAweEZGKSBzaGwgMTYpXG4gICAgXG5cdHByaW50bG4oXCJSR0IgIyR7cmdiLnRvU3RyaW5nKDE2KX0sICRyZ2IgKFtyOiAkcmdiUmVkQ29sb

It sums a list of amounts within a markdown snippet

_**2079,30** (2022/01)_<br>  
_**2014,40** (2022/02)_<br>  
_**2161,51** (2022/03)_<br>  
_**226,29** (2022/04)_<br>  
_**2.283,29** (2022/05)_<br>  
_**223,92** (2022/06)_<br>  
_**222,48** (2022/07)_<br>  
@uqmessias
uqmessias / toCurrency.js
Created October 7, 2022 19:51
Format number to currency format
const toCurrency = num => num.toFixed(2).replace('.', ',').replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1.");
@uqmessias
uqmessias / base64.js
Created December 21, 2021 14:39
Function to transform string into base64
/**
*
* @param {string} str
*/
function base64(str) {
const base64Characters = [
"A",
"B",
"C",
"D",
@uqmessias
uqmessias / ffmpeg.md
Created April 13, 2020 23:08 — forked from protrolium/ffmpeg.md
using ffmpeg to extract audio from video files

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

Convert WAV to MP3, mix down to mono (use 1 audio channel), set bit rate to 64 kbps and sample rate to 22050 Hz:

@uqmessias
uqmessias / dec2hex.ts
Last active February 1, 2020 05:05
Converts an input parameter from Decimal to Hexadecimal
/**
* If you want to use it, you first need to install
* Deno at https://deno.land and run:
* deno https://gist.github.com/uqmessias/66f3de0da2f60419b39f26ca243f3e2a/raw 222
*/
function throwError(wrongArgument = null) {
const argumentError =
wrongArgument === null
? ""
: `"${wrongArgument}" is not a valid argument!\n\n`;