Skip to content

Instantly share code, notes, and snippets.

View thbighead's full-sized avatar

Thales Nathan thbighead

  • Brazil, Rio de Janeiro
View GitHub Profile
@thbighead
thbighead / kruskal.py
Created May 7, 2017 00:35
Kruskal MST Algorithm in Python language
grafo = {
'a': {'b': 0, 'd': 1, 'e': 2},
'b': {'a': 0, 'c': 4, 'e': 5},
'c': {'b': 4, 'e': 7},
'd': {'a': 1, 'e': 9},
'e': {'a': 2, 'b': 5, 'c': 7, 'd': 9, 'f': 14},
'f': {'e': 14}
}
def quicksort(vetor,inicio,fim):
Para limpar teu docker todo:
docker system prune -a --volumes
@thbighead
thbighead / busca_em_largura.py
Last active July 4, 2022 13:01
Snippet em Python para criar uma busca em largura de Grafos
grafo = {
'a': ['b', 'd', 'e'],
'b': ['a', 'c', 'e'],
'c': ['b', 'e'],
'd': ['a', 'e'],
'e': ['a', 'b', 'c', 'd', 'f'],
'f': ['e']
}
def busca_em_largura(grafo, vertice_do_grafo):
@thbighead
thbighead / criador_de_grafos.py
Created April 17, 2017 00:55
Criador de grafos em representacao de matriz de adjacencias feito com Python
def cria_grafo(lista_de_vertices, lista_de_arestas):
grafo = {}
for vertice in lista_de_vertices:
grafo[vertice] = []
for aresta in lista_de_arestas:
grafo[aresta[0]].append(aresta[1])
return grafo
@thbighead
thbighead / recursive_copy_folder.php
Last active June 22, 2020 14:14
Copy a folder and every folders and files inside of it
function recursive_copy($source, $destination)
{
if (is_dir($source) === true) {
$success = true;
if (!file_exists($destination)) {
mkdir($destination, 0777, true);
}
$files = array_diff(scandir($source), ['.', '..']);
@thbighead
thbighead / busca_em_profundidade.py
Last active October 29, 2019 22:55
Snippet em Python para criar uma busca em profundidade de Grafos
grafo = {
'a': ['b', 'd', 'e'],
'b': ['a', 'c', 'e'],
'c': ['b', 'e'],
'd': ['a', 'e'],
'e': ['a', 'b', 'c', 'd', 'f'],
'f': ['e']
}
# coisos globais
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;
@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) {
<?php
function validar_cnpj($cnpj)
{
$cnpj = preg_replace('/[^0-9]/', '', (string) $cnpj);
// Valida tamanho
if (strlen($cnpj) != 14)
return false;