Skip to content

Instantly share code, notes, and snippets.

View yurimorales's full-sized avatar

Yuri Morales yurimorales

  • Palhoça, SC - Brazil
View GitHub Profile
@yurimorales
yurimorales / Logger.php
Last active April 3, 2025 18:48
Logger helper class php file
<?php
namespace Helpers;
class Logger
{
private $logFile;
public function __construct($logFile = 'app.log')
{
@yurimorales
yurimorales / docker_compose_install.sh
Created February 26, 2025 17:25
Install docker-composer lts version
#!/bin/bash
VERSION=$(/usr/bin/curl --silent https://api.github.com/repos/docker/compose/releases/latest | grep -Po '"tag_name": "\K.*\d')
DESTINATION='/usr/local/bin/docker-compose'
sudo /usr/bin/curl -L https://github.com/docker/compose/releases/download/$VERSION/docker-compose-$(uname -s)-$(uname -m) -o $DESTINATION
sudo /usr/bin/chmod +x $DESTINATION
echo $(docker-compose --version)
@yurimorales
yurimorales / free_swap_clean.sh
Created February 6, 2025 19:57
Free swap memory shell script
#!/bin/bash
function echo_mem_stat () {
mem_total="$(free | grep 'Mem:' | awk '{print $2}')"
free_mem="$(free | grep 'Mem:' | awk '{print $7}')"
mem_percentage=$(($free_mem * 100 / $mem_total))
swap_total="$(free | grep 'Swap:' | awk '{print $2}')"
used_swap="$(free | grep 'Swap:' | awk '{print $3}')"
swap_percentage=$(($used_swap * 100 / $swap_total))
@yurimorales
yurimorales / remove-accents.php
Created September 13, 2024 15:20
Remove acentuações strings PHP - Exemplo com 3 abordagens
<?php
$string = "Av Doutor Mário Guimarães - Nova Iguaçu";
echo "\n";
echo "String Original: {$string}" . PHP_EOL;
echo "\n";
function corrigirCodificacao($string) {
// Detecta a codificação da string
$encoding = mb_detect_encoding($string, mb_list_encodings(), true);
@yurimorales
yurimorales / yield.php
Last active February 5, 2025 18:14
Exemplo de utilização do yield
<?php
// https://sergheipogor.medium.com/efficient-data-processing-with-php-generators-unlocking-memory-management-secrets-0bea9377e2b8
function foo()
{
for ($i = 0; $i < 10; $i++) {
yield $i;
}
}
@yurimorales
yurimorales / sanitize_string.php
Last active February 17, 2025 17:13
Remove caracteres com acentos em string php
<?php
$word = "Belém do Pará";
$foo = function ($string)
{
if (!preg_match('/[\x80-\xff]/', $string))
return $string;
$chars = array(
@yurimorales
yurimorales / password_generator.sh
Created October 16, 2023 11:53
Secure password command generator in terminal linux
#!/bin/bash
# Gerando senhas fortes no terminal do linux
# Usando gpg para gerar uma senha segura com 12 caracteres
gpg --gen-random --armor 1 12
# Usando openssl para gerar uma senha segura com 12 caracteres
openssl rand -base64 12
@yurimorales
yurimorales / sh
Created March 16, 2023 18:30
Verify string in file shell script
#!/bin/bash
grep -q "word" filename.txt && echo "yes" || echo "no"
@yurimorales
yurimorales / iin_card
Created April 7, 2021 15:56 — forked from gusribeiro/iin_card
Regex para identificar bandeiras do cartão de crédito
Amex: /^3[47][0-9]{13}/
Aura: '^507860'
Banese Card: '^636117'
Cabal: '(60420[1-9]|6042[1-9][0-9]|6043[0-9]{2}|604400)'
Diners: '(36[0-8][0-9]{3}|369[0-8][0-9]{2}|3699[0-8][0-9]|36999[0-9])
Discover: /^6(?:011|5[0-9]{2})[0-9]{12}/
Elo: ^4011(78|79)|^43(1274|8935)|^45(1416|7393|763(1|2))|^504175|^627780|^63(6297|6368|6369)|(65003[5-9]|65004[0-9]|65005[01])|(65040[5-9]|6504[1-3][0-9])|(65048[5-9]|65049[0-9]|6505[0-2][0-9]|65053[0-8])|(65054[1-9]|6505[5-8][0-9]|65059[0-8])|(65070[0-9]|65071[0-8])|(65072[0-7])|(65090[1-9]|6509[1-6][0-9]|65097[0-8])|(65165[2-9]|6516[67][0-9])|(65500[0-9]|65501[0-9])|(65502[1-9]|6550[34][0-9]|65505[0-8])|^(506699|5067[0-6][0-9]|50677[0-8])|^(509[0-8][0-9]{2}|5099[0-8][0-9]|50999[0-9])|^65003[1-3]|^(65003[5-9]|65004\d|65005[0-1])|^(65040[5-9]|6504[1-3]\d)|^(65048[5-9]|65049\d|6505[0-2]\d|65053[0-8])|^(65054[1-9]|6505[5-8]\d|65059[0-8])|^(65070\d|65071[0-8])|^65072[0-7]|^(65090[1-9]|65091\d|650920)|^(65165[2-9]|6516[6-7]\d)|^(65500\d|65501\d)|^(65502[1-9]|6550[3-4]\d|65505[0-8])
Fort
@yurimorales
yurimorales / mysql-export-table-to-csv.sh
Last active January 15, 2021 17:05
Export data from table MySQL to csv file, with linux command line
mysql -u<user> -p<password> <database-name> -B -e "select * from \'<table-name-from-database>\';" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > /path-to-save/<name-from-file-to-save>.csv