Skip to content

Instantly share code, notes, and snippets.

View tsprates's full-sized avatar
🖥️
Working from home

Thiago Prates tsprates

🖥️
Working from home
View GitHub Profile
@tsprates
tsprates / rm_rf.php
Last active April 19, 2022 22:41
Remove all files and subdirectories from a specific directory.
<?php
/**
* Remove all files and subdirectories from a specific directory (recursively).
*
* @param string $dir The directory to be removed.
*
* @return
*/
function rm_rf($dir)
@tsprates
tsprates / simple_tcp_chat.php
Last active December 25, 2023 17:29
Simple TCP Chat in plain PHP
<?php
declare(strict_types=1);
/**
* Simple TCP Chat.
*
* @author Thiago Prates <[email protected]>
*/
final class SimpleTcpChat
@tsprates
tsprates / scandir_all.php
Last active October 10, 2022 02:42
List all files in a directory and their respective subdirectories recursively
<?php
/**
* List all files in a directory and their respective subdirectories recursively.
*
* @param string $directory
* @return null|Generator
*/
function scandir_all(string $directory): ?Generator
{
@tsprates
tsprates / president-election-brazil-2022.php
Last active October 26, 2022 15:07
Script to check Brazil's Election for President 2022
<?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');
// 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, "."));