Skip to content

Instantly share code, notes, and snippets.

View thbighead's full-sized avatar

Thales Nathan thbighead

View GitHub Profile
Para limpar teu docker todo:
docker system prune -a --volumes
function download(filename, text) {
let element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
@thbighead
thbighead / validar_cpf.php
Created July 7, 2019 16:45 — forked from rafael-neri/validar_cpf.php
Validar CPF em PHP (Completo)
<?php
function validaCPF($cpf) {
// Extrai somente os números
$cpf = preg_replace( '/[^0-9]/is', '', $cpf );
// Verifica se foi informado todos os digitos corretamente
if (strlen($cpf) != 11) {
return false;
<?php
function validar_cnpj($cnpj)
{
$cnpj = preg_replace('/[^0-9]/', '', (string) $cnpj);
// Valida tamanho
if (strlen($cnpj) != 14)
return false;
@thbighead
thbighead / ArrayToXml.php
Last active June 25, 2019 16:59
Métodos para transformar arrays em XMLs
/**
* Transforma array em XML. Este método trata os casos de repetição para chaves com
* valores de arrays sequenciais onde o objetivo é criar múltiplas tags com estas chaves.
*
* @param array $data
* @param SimpleXMLElement $xml_data
*/
function array_to_xml(array $data, SimpleXMLElement $xml_data)
{
foreach ($data as $key => $value) {
@thbighead
thbighead / remove_flagged_columns.php
Last active June 11, 2019 18:56
Regex to remove selected columns in a SQL query which have dynamic alias pointed by [anythinghere] flags
<?php
preg_replace('/(SELECT\s*\S*\s+\[[^\[\]]*\]|([a-zA-Z]*\(.*)?,\s*\S*\s+\[[^\[\]]*\])/', '', $input_lines);
@thbighead
thbighead / cleanMemoryWithGC.php
Created May 13, 2019 18:24
Using return_bytes, this helper runs the Garbage Collector when the memory usage passes a given percentage
/**
* @param float $percentage A value between 0 and 1
*/
function cleanMemoryWithGC($percentage)
{
if ((return_bytes(ini_get('memory_limit')) * $percentage) <= memory_get_usage()) {
$percentage *= 100;
Log::info('cleanMemoryWithGC', ['message' => "Rodando o Garbage Collector, pois mais de $percentage% do limite de memória disponível para o PHP está sendo utilizado..."]);
gc_collect_cycles();
}
@thbighead
thbighead / return_bytes.php
Last active May 13, 2019 20:25
Function to cast the shorthand memory notation value to bytes
/**
* Converts shorthand memory notation value to bytes
* From http://php.net/manual/en/function.ini-get.php
*
* @param string $val memory size shorthand notation string
* @return int|string
*/
function return_bytes($val)
{
$val = trim($val);
@thbighead
thbighead / MainActivity.java
Created November 7, 2018 22:51
Primeiro projeto Android Native com Fragments (parece não estar funcionando, não troca para o segundo fragmento)
package com.example.andersonvieira.exemplo_fragments;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
@thbighead
thbighead / MainActivity.java
Created October 11, 2018 00:13
Doideira com recuperação de imagens
package projetolc.usuario.app.anotherdoideira;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {