Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am matheusb-comp on github.
  • I am matheusb_comp (https://keybase.io/matheusb_comp) on keybase.
  • I have a public key whose fingerprint is AAC4 EA9A D3DB 323C A0F8 F908 C7DE 6A45 6DE8 A31F

To claim this, I am signing this object:

# First: 83000419088867329 - 2018-08-07T00:04:03Z
https://horizon.stellar.org/accounts/GCCD6AJOYZCUAQLX32ZJF2MKFFAUJ53PVCFQI3RHWKL3V47QYE2BNAUT/operations?cursor=82632129938210817&order=asc&limit=200
# Last: 83002532212809828 - 2018-08-07T01:09:40Z
https://horizon.stellar.org/accounts/GCCD6AJOYZCUAQLX32ZJF2MKFFAUJ53PVCFQI3RHWKL3V47QYE2BNAUT/operations?order=desc&limit=200
Remaining: 1428.2669153 (- 5XLM: 1423.2669153)
package main
import (
"os"
"fmt"
"log"
"flag"
"sync"
"time"
"math"
@matheusb-comp
matheusb-comp / Cookie2Jwt.php
Last active August 30, 2018 03:00
[TESTING] JWT Laravel
<?php
namespace App\Http\Middleware;
use Closure;
class Cookie2Jwt
{
/**
* Handle an incoming request.
@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"
@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 / 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 / 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 / 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 / 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;