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
// 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, "."));
@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');
@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 / 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 <tsprates@gmail.com>
*/
final class SimpleTcpChat
@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 / bandit.txt
Last active February 25, 2024 17:16
The Bandit wargame is aimed at absolute beginners.
# https://overthewire.org/wargames/bandit/
bandit1 NH2SXQwcBdpmTEzi3bvBHMM9H66vVXjL
bandit2 rRGizSaX8Mk1RTb1CNQoXTcYZWU6lgzi
bandit3 aBZ0W5EmUfAf7kHTQeOwd8bauFJ2lAiG
bandit4 2EW7BBsr6aMMoJ2HjW067dm8EgX26xNe
bandit5 lrIWWI6bB37kxfiCQZqUdOIYfr6eEeqR
bandit6 P4L4vucdmLnm8I7Vl7jG1ApGSfjYKqJU
bandit7 z7WtoNQU2XfjmMtWA8u5rN4vzqu4v99S
bandit8 TESKZC0XvTetK0S9xNwm25STk5iWrBvP
@tsprates
tsprates / binary-tree.c
Last active April 30, 2022 11:23
A Binary Tree implementation in C
// Binary Tree
// Author: Thiago Prates <tsprates@hotmail.com>
#include <stdio.h>
#include <stdlib.h>
typedef struct _node {
int data;
struct _node* left;
struct _node* right;
@tsprates
tsprates / quicksort.js
Last active August 29, 2015 14:16
Quicksort implementation in JS.
/**
* Quicksort implementation.
*
* @see {@link http://en.wikipedia.org/wiki/Quicksort}
* @param {array} arr
* @result {array} Sorted array
.*/
var quicksort = function(arr) {
function partition(arr, left, right) {
@tsprates
tsprates / to_ascii.js
Last active March 17, 2022 21:13
Correspondent ASCII characters.
/**
* To ASCII.
*
* @param {string} text
* @returns {string}
*/
function toAscii(text) {
var noAscii = 'áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ';
var ascii = 'aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC';
var resultText = '';
@tsprates
tsprates / caesar_cipher.js
Last active August 29, 2015 14:15
Caesar Cipher
/**
* Caesar cipher.
*
* @link http://en.wikipedia.org/wiki/Caesar_cipher
* @param {string} msg
* @param {number} shift
* @return {string}
*/
function caesarCipher(msg, shift) {
var result = "",