Skip to content

Instantly share code, notes, and snippets.

View LeonanCarvalho's full-sized avatar
🏠
Working from home

Leonan LeonanCarvalho

🏠
Working from home
View GitHub Profile
@LeonanCarvalho
LeonanCarvalho / consumer.js
Created April 19, 2024 12:51
AWS - FIFO SQS Consumer in Batch
const AWS = require('aws-sdk');
const SQS = new AWS.SQS({ region: 'us-east-1' });
const { Parallel } = require('async'); // npm install async
const queueUrl = 'SQS_URN';
const batchSize = 10;
async function processBatch(messages) {
// Implement your message processing
console.log('Batch size', messages.length);
@LeonanCarvalho
LeonanCarvalho / 0-partial-error.json
Last active November 9, 2023 14:20
Bulk response
{
"trace_id": "xpto",
"success":false,
"success_ids" [0,2,3,4,...,998],
"errors":[
{
"id":1,
"error":{
"code":"already_used",
"message":"This receiver is already used and cannot be deleted"
@LeonanCarvalho
LeonanCarvalho / 2WAN2LAN-LACP.md
Last active July 24, 2023 17:05
Setting up dual WAN link aggregation on an Asus RT-AX88U router with an EdgeRouter X

Setting up dual WAN link aggregation on an Asus RT-AX88U router with an EdgeRouter X

This is a proof of concept I did, use at your own risk. I am not responsible for any damage you may cause to your equipment as a result of applying these commands. If you have suggestions or even corrections, you can write them in the comments.

Requirements:

  1. Ubiquiti EdgeRouter X (firmware v2.0.9-hotfix.7)
  2. Asus RT-AX88U Router (firmware 3.0.0.4.388_22525-gd35b8fe) (Maybe applies to any other router/switch with LACP turned on)
  3. Load Balancer configured from EdgeRouter X's Wizard
@LeonanCarvalho
LeonanCarvalho / 0_index.md
Last active August 25, 2022 12:24
CSRF token Protection, the basics

Cross-site request forgery (CSRF)

Cross-site request forgery (also known as CSRF) is a web security vulnerability that allows an attacker to induce users to perform actions that they do not intend to perform. It allows an attacker to partly circumvent the same origin policy, which is designed to prevent different websites from interfering with each other.

image

More details at:

/**
Run at developer consol to get total from paypal report
**/
const tableSelector = '#app-container > div.css-1a33u3k.e177xzf81.ppvx_container > div > div > div.css-d5zi6y.ewjo4hi0 > div:nth-child(3) > div > div > div:nth-child(1) > div > div > div > div > div > div > table > tbody > tr > td:nth-child(7) > p';
const values = document.querySelectorAll(tableSelector);
let total = 0;
for (let value of values) {
total += parseFloat(value.innerText.split(' ')[1])
}
@LeonanCarvalho
LeonanCarvalho / dayjs-issue-1827.js
Last active March 11, 2022 14:37
DayJs bug at dayjs.tz()
//Changing the TZ also change results.
//process.env.TZ = 'UTC';
//process.env.TZ = 'America/Sao_Paulo'; //BUG: Returning with DST, but since 2018 Brazil didn't have it.
//process.env.TZ = 'America/Recife'; //Workaround: Using recife because it hasn't DST previously.
//PS: may the bug with TZ is a SO/nodeJS related
const now = new Date();
const dayjs = require('dayjs');
const utc = require('dayjs/plugin/utc');
@LeonanCarvalho
LeonanCarvalho / ___2001-to-2022-holidays.json
Last active March 4, 2022 17:03
FEBRABAN Holidays from 2001 to 2022
{
"2001": [
"2001-01-01",
"2001-02-26",
"2001-02-27",
"2001-04-13",
"2001-04-21",
"2001-05-01",
"2001-06-14",
"2001-09-07",
@LeonanCarvalho
LeonanCarvalho / custom_tracer.js
Last active January 26, 2022 14:56
NewRelic Tests
//This implementation was a lab to understand how newrelic transactions work
const newrelic = require('newrelic');
module.exports = class NewRelicTracer {
constructor(name) {
this.name = name;
}
start(group = '') {
let payload;
// Call newrelic.getTransaction to retrieve a handle on the current transaction, if exists
@LeonanCarvalho
LeonanCarvalho / Task.js
Last active March 12, 2021 20:14
Simple demonstration how to use Workers on electron main process
//Task.js
const path = require('path');
const fs = require('fs');
const { Worker } = require('worker_threads')
function checkFileHashTask(files, cwd = "./", hashType = 'md5', msgHandler){
return new Promise((resolve, reject) => {
const workerData = {cwd: cwd, files:files,hashType:hashType};
@LeonanCarvalho
LeonanCarvalho / POST.json
Created September 24, 2020 13:14
Kepler Payload (Upload)
This file has been truncated, but you can view the full file.
{\"name\":\"teste1 (Copy)\",\"description\":\"teste\",\"contents\":\"{\\\"datasets\\\":[{\\\"version\\\":\\\"v1\\\",\\\"data\\\":{\\\"id\\\":\\\"lfx93ilco\\\",\\\"label\\\":\\\"342.json\\\",\\\"color\\\":[143,47,191],\\\"allData\\\":[[{\\\"type\\\":\\\"Feature\\\",\\\"properties\\\":{\\\"AREA\\\":496077216,\\\"PERIMETER\\\":150985,\\\"NAZEV\\\":\\\"Hlavn� m�sto Praha\\\",\\\"OB91\\\":1214174,\\\"OB01\\\":1180131,\\\"OB_311202\\\":1161938,\\\"OKRES\\\":3100,\\\"NUTS4\\\":\\\"CZ0110\\\",\\\"NUTS3\\\":\\\"CZ011\\\",\\\"NUTS2\\\":\\\"CZ01\\\",\\\"KRAJ1960\\\":3100,\\\"NK\\\":\\\"HP\\\",\\\"KN\\\":1,\\\"KNOK\\\":100,\\\"NAZKR\\\":\\\"Hlavn� m�sto Praha\\\",\\\"NAZEV_ENG\\\":\\\"Hlavni mesto Praha\\\",\\\"NAZKR_ENG\\\":\\\"Hlavni mesto Praha\\\",\\\"NEZAM\\\":24571,\\\"index\\\":0},\\\"geometry\\\":{\\\"type\\\":\\\"Polygon\\\",\\\"coordinates\\\":[[[14.55496454528594,50.01215521174626],[14.555661985922347,50.01090393810035],[14.551420549326107,50.00771654302379],[14.543149917147526,50.007945135220254],[14.53499580