Skip to content

Instantly share code, notes, and snippets.

View lucivaldo's full-sized avatar
🏠
Working from home

Lucivaldo lucivaldo

🏠
Working from home
View GitHub Profile
/* eslint-disable @typescript-eslint/no-explicit-any */
/** biome-ignore-all lint/suspicious/noExplicitAny: <> */
/**
* Aguarda um tempo em milissegundos.
* @param ms - Quantidade de milissegundos para aguardar.
*/
export function delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
@lucivaldo
lucivaldo / update_dependencies.sh
Last active April 14, 2025 20:51
Script para atualizar as dependências package.json de um projeto Javascript
#!/usr/bin/env bash
# Interrompe o script se ocorrer algum erro
set -e
# Verifica se jq está instalado
if ! command -v jq &> /dev/null; then
echo "Erro: 'jq' não está instalado. Instale com: https://jqlang.github.io/jq/"
exit 1
fi
@lucivaldo
lucivaldo / getMonthBehavior.ts
Last active May 30, 2024 20:12
Função Typescript para gerar um intervalo de objetos Date Javascript para ser utilizado na construção de calendários de meses
const makeDate = (year: number, month: number, day: number) =>
new Date(year, month, day, 0, 0, 0)
const makeRangeBetweenDates = (start: Date, end: Date) => {
const range: Date[] = []
for (
const i = new Date(start);
i.getTime() <= end.getTime();
i.setDate(i.getDate() + 1)
@lucivaldo
lucivaldo / csv_builder.rb
Created March 5, 2024 11:30
Classe Ruby simples para gerar arquivos CSV de maneira mais dinâmica
require 'csv'
class CSVBuilder
def initialize
@columns = []
@data = []
end
def add_column(column_name)
@columns << column_name
@lucivaldo
lucivaldo / elapsed_time.rb
Created January 18, 2024 21:50
Classe Ruby para medir o tempo de execução de um código passado como bloco de código
class ElapsedTime
def elapsed
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield if block_given?
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
elapsed_time = "%.2f" % (end_time - start_time)
puts "Tempo decorrido: #{elapsed_time} segundos"
@lucivaldo
lucivaldo / Dockerfile
Last active December 31, 2024 04:49
Exemplo de arquivo Dockerfile para projetos Rails somente API usando Alpine e com banco de dados SQLite
FROM ruby:3.2.2-alpine
LABEL maintainer="Fulano de Tal <[email protected]>"
RUN apk update && apk add --virtual build-dependencies build-base
RUN apk add \
less \
mailcap \
sqlite-dev \
tzdata
@lucivaldo
lucivaldo / text_to_fuzzy_search.rb
Last active March 22, 2023 15:47
Função para converter texto em um array de textos para buscas fuzzy
def text_to_fuzzy_search(text)
first_word, *rest_words = text.split
rest_words_chars = rest_words.map { _1.split('') }
search = first_word.dup
array = [search]
rest_words_chars.each do |chars|
search += " "
@lucivaldo
lucivaldo / ConfirmDialog.tsx
Created May 26, 2022 21:08
Provider para fornecer a funcionalidade de dialogo de confirmação globalmente em aplicações React
import { faCheck, faTimes, faWarning } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
Box,
Button,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
Backdrop,
@lucivaldo
lucivaldo / getGitLabIssuesByMilestone.js
Last active September 18, 2021 17:38
Exemplo de código JS para realizar várias chamadas assíncronas para API backend utilizando iterables e for await...of
const fetchAllResources = async (resources, params) => {
const asyncIterable = {
[Symbol.asyncIterator]() {
return {
page: '1',
finished: false,
async next() {
if (!this.finished) {
const response = await api.get(resources, {
params: { ...params, page: this.page },
@lucivaldo
lucivaldo / config.fish
Last active October 31, 2024 21:46
My fish config
set -x GITLAB_PERSONAL_ACCESS_TOKEN abc
set -x ATHENAS_API_TOKEN abc
set -x SOLAR_API_TOKEN abc
set -x JQ_ATHENAS '.results[0] | { field1, field2, field3, field4: field4.subfield1.name }'
# go lang
fish_add_path /usr/local/go/bin
# flutter