Skip to content

Instantly share code, notes, and snippets.

@matheusb-comp
matheusb-comp / pix_formats.md
Created July 17, 2024 17:04
Exemplos de formato PIX

Formatos PIX

Exemplos da string PIX (geralmente representada por um QR Code), identificando os campos.

Cada campo tem o formato <ID> <tamanho> <valor>.

Mais detalhes no Manual de Padrões.

PIX Estático (seção 6.1)

00 02 01 // Payload format (fixo)
@matheusb-comp
matheusb-comp / merge_url_query.php
Created October 6, 2023 17:20
Parse and rebuild an URL adding new QueryString values
<?php
function mergeUrlQuery(string $url, array $queryData = []): string
{
$parts = parse_url($url);
if (empty($parts['host'])) throw new \InvalidArgumentException('url');
$originalQuery = [];
if (!empty($parts['query'])) {
foreach (explode('&', $parts['query']) as $i => $el) {
@matheusb-comp
matheusb-comp / php-wrapper
Created April 28, 2021 22:43
PHP wrapper to load libreadline at runtime
#!/bin/sh
# PHP installed in AWS EC2 using Amazon-Linux-Extras is compiled with:
# --without-readline --with-libedit
#
# However, for some reason, libedit doesn't accept UTF-8 input:
# https://github.com/bobthecow/psysh/issues/148
#
# Instead of building PHP from the source code, apparently libreadline
# can just be preloaded when running PHP:
@matheusb-comp
matheusb-comp / README.md
Last active January 29, 2021 22:56
Funcionamento orkestral/venom

WAPI Parasite (orkestral/venom)

A biblioteca define uma série de módulos para buscar dentro da variável window['webpackJsonp'], que é o output do Webpack.

Screenshot from 2021-01-29 18-50-38

A cada 100ms o código

@matheusb-comp
matheusb-comp / FileDownloaderService.php
Created October 26, 2020 13:26
PHP class to download files on Laravel, with size limit based on the Content-Type header
<?php
namespace App\Services;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\ResponseInterface;
use Illuminate\Support\Facades\Storage;
@matheusb-comp
matheusb-comp / Lock.js
Created April 12, 2020 18:08
Mutex lock class for JavaScript
/**
* Mutual-exclusion lock acquired through a promise. Based on:
* https://thecodebarbarian.com/mutual-exclusion-patterns-with-node-promises
*/
class Lock {
constructor(timeout = 0) {
this._meta = null
this._token = null
this._locked = false
this._timeout = parseInt(timeout) || 0
@matheusb-comp
matheusb-comp / keep-refs.js
Created September 29, 2019 14:02
Keep references of timeouts and promises to help during graceful shutdown
// Pending promises
let execs = []
// Timeouts waiting to run
let timeouts = []
const exec = (func, ...args) => {
const promise = func(...args).finally(() => {
// Cleanup after the promise settled (resolved or rejected)
execs = execs.filter((el) => el !== promise)
})
@matheusb-comp
matheusb-comp / serve204.sh
Last active June 6, 2019 22:18
Simple server that responds an HTTP 204 No Content to anything received
#!/bin/sh
# Command line variables
HOST=${1:-127.0.0.1}
PORT=${2:-4422}
# Test PORT
nc -z -w 5 127.0.0.1 ${PORT}
if [ $? -eq 0 ]; then
echo "Port ${PORT} in use, choose a different one"
@matheusb-comp
matheusb-comp / fetch-request.js
Last active February 16, 2021 16:54
Simple fetch wrapper to select the proper function to use when processing the response. Also rejects if HTTP code is not in the range 200-299
/**
* Reads the entire response body and process based in the Content-Type header
* https://developer.mozilla.org/en-US/docs/Web/API/Body
*
* @param {object} response A response from a fetch request
* @param {boolean} arrayBuffer When body can't be processed to `text`,
* `json`, or `form-data`, process it to an ArrayBuffer or a Blob (default)
*
* @return {Promise} A promise that resolves after the entire body is processed
*/
@matheusb-comp
matheusb-comp / main.go
Created September 11, 2018 00:37
Stellar CSV
// TODO: Fix the end-case scenario where the FINAL_OP_PT is the last operation the Pool did
package main
import (
"os"
"fmt"
"log"
"time"
"strconv"