This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Remove all files and subdirectories from a specific directory (recursively). | |
* | |
* @param string $dir The directory to be removed. | |
* | |
* @return | |
*/ | |
function rm_rf($dir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
/** | |
* Simple TCP Chat. | |
* | |
* @author Thiago Prates <[email protected]> | |
*/ | |
final class SimpleTcpChat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* List all files in a directory and their respective subdirectories recursively. | |
* | |
* @param string $directory | |
* @return null|Generator | |
*/ | |
function scandir_all(string $directory): ?Generator | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Brazil's election for president 2022 | |
// Author: Thiago Prates | |
$url = 'https://resultados.tse.jus.br/oficial/ele2022/544/dados-simplificados/br/br-c0001-e000544-r.json'; | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
// Link: https://curl.se/docs/caextract.html | |
// curl_setopt($ch, CURLOPT_CAINFO, './cacert.pem'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Brazil's election for president 2022 | |
// Author: Thiago Prates | |
import fetch from "node-fetch"; | |
const url = "https://resultados.tse.jus.br/oficial/ele2022/544/dados-simplificados/br/br-c0001-e000544-r.json"; | |
const response = await fetch(url); | |
const json = await response.json(); | |
const results = json["cand"].reduce((acc, { /* candidato */ nm, /* porcentagem */ pvap }) => { | |
const pct = parseFloat(pvap.replace(/,/g, ".")); |
OlderNewer