Skip to content

Instantly share code, notes, and snippets.

@guimadaleno
guimadaleno / percentage-difference-variation.php
Last active September 1, 2022 15:17
Calculate difference and variation
<?php
/**
* Calculate percentage increase or decrease
* @param int $length
*/
function percentage_difference ($old = 0, $new = 0)
{
@guimadaleno
guimadaleno / restore-dump-oracle-11-xe.sh
Created September 1, 2022 15:13
Installing and restoring DUMP file into Oracle 11.2.0 XE Server via Docker
# Credentials
# ========================================
# hostname: localhost
# port: 49161
# sid: xe
# username: system
# password: oracle
# On host
@guimadaleno
guimadaleno / php.Dockerfile
Created March 29, 2022 14:11
PHP Docker with MySQL, GIT, ZIP, MBString and GD
FROM php:7.4.3-apache
RUN apt-get update -y && apt-get install -y build-essential libssl-dev zlib1g-dev libpng-dev libjpeg-dev libfreetype6-dev libonig-dev libzip-dev git
RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN docker-php-ext-install mbstring
RUN docker-php-ext-install zip
RUN docker-php-ext-install gd
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg
@guimadaleno
guimadaleno / macos-php-module-codesign-homebrew.sh
Created March 8, 2022 18:18
If you installed PHP 8 on Mac OS Monterey and you're unable to start Apache...
# 1. Check why Apache isn't starting
sudo apachectl configtest
# 2. If the message has something like "Code signing absent - not loading module at..." please continue to this walkthrough...
# 3. On MacOS, open Keychain Access, go to menu Keychain Access > Certificate Assistant > Create a certificate.
# 4. Type a name and select the type "Code signing" then proceed to create it.
# 5. After creation, type the following command on the Terminal:
sudo codesign --verbose --sign "YOUR_CERTIFICATE_NAME" /usr/local/opt/php/lib/httpd/modules/libphp.so --force
@guimadaleno
guimadaleno / cidades-brasil.json
Created April 30, 2020 21:41
Lista de cidades do Brasil em JSON
{
"AC": [
"ACRELANDIA",
"ASSIS BRASIL",
"BRASILEIA",
"BUJARI",
"CAPIXABA",
"CRUZEIRO DO SUL",
"EPITACIOLANDIA",
"FEIJO",
@guimadaleno
guimadaleno / bucket-policy.txt
Last active February 25, 2019 23:11
Transferindo dados de um bucket AWS S3 para outro em outra conta
=======================================================================================================
Cole esta política no bucket que contém os dados a serem transferidos
Nota: No exemplo abaixo, 000000000000 é a ID da conta da AWS que receberá os dados a serem transferidos
=======================================================================================================
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DelegateS3Access",
@guimadaleno
guimadaleno / load-installed-timezones.php
Last active March 8, 2022 18:31
List all timezones in PHP
<?php
$tzList = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
var_dump($tzList);
@guimadaleno
guimadaleno / error-reporting-types.php
Last active March 8, 2022 18:31
Make PHP show or hide parse errors, notices and warnings
<?php
# Exibe erros de parsing, exceto notices e warnings
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
# Exibe erros de parsing e warnings, exceto notices
error_reporting(E_ALL ^ E_NOTICE);
@guimadaleno
guimadaleno / find-and-replace-multiple-rows.sql
Last active March 8, 2022 18:31
Find and replace string data on multiple rows
UPDATE `table` SET `column` = REPLACE(`column`, 'origin', 'destiny');
@guimadaleno
guimadaleno / validar-cpf.php
Last active March 8, 2022 18:20
Função simples para validar CPF (autor desconhecido)
<?php
function is_cpf_valid ($cpf)
{
$cpf = preg_replace("/[^0-9]/", "", $cpf);
$digitoUm = 0;
$digitoDois = 0;
for($i = 0, $x = 10; $i <= 8; $i++, $x--):
$digitoUm += $cpf[$i] * $x;
endfor;