Skip to content

Instantly share code, notes, and snippets.

@RafaelGSS
RafaelGSS / RESULT.md
Created March 7, 2024 13:13
util.styleText benchmark against alternatives
@RafaelGSS
RafaelGSS / index.js
Created March 15, 2023 20:52
Example custom connect fetch
const { setGlobalDispatcher, Agent } = require('undici')
setGlobalDispatcher(
new Agent({
connect: (opts) => {
console.log('Called with', opts)
// implement custom dns lookup
}
})
)
@RafaelGSS
RafaelGSS / print-radix-tree.cpp
Created December 7, 2022 19:12
PrintTree helper to visualize the fs prefix radix tree
void PrintTree(FSPermission::RadixTree::Node* node, int spaces = 0) {
std::string whitespace = "";
for (int i = 0; i < spaces; ++i) {
whitespace += " ";
}
if (node == nullptr) {
std::cout << whitespace << "Node nullptr" << std::endl;
return;
}
@RafaelGSS
RafaelGSS / repro.js
Created October 20, 2022 16:47
Undici v19 support
const Fastify = require('./fastify')
const { Client } = require('undici')
const assert = require('assert')
const fastify = Fastify({
return503OnClosing: true,
forceCloseConnections: false
})
fastify.get('/', (req, reply) => {
rafaelgss@rafaelgss-desktop:~/repos/os/undici-ghsa-pgw7-wx7w-2w33$ node examples/proxy-agent.js
node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: self-signed certificate in certificate chain
    at TLSSocket.onConnectSecure (node:_tls_wrap:1531:34)
    at TLSSocket.emit (node:events:527:28)
    at TLSSocket._finishInit (node:_tls_wrap:945:8)
@RafaelGSS
RafaelGSS / incoming-request.dto.ts
Created February 1, 2021 17:59
Fastify + Typebox Example
import { Type, Static } from '@sinclair/typebox';
export const SendTextMessage = Type.Object({
body: Type.String(),
chatId: Type.Number(),
options: Type.Optional(
Type.Object({ previewUrl: Type.Optional(Type.Boolean()) }),
),
});
@RafaelGSS
RafaelGSS / producer.js
Created September 2, 2019 00:29
Communication between microservices - RabbitMQ - Producer
const amqp = require('amqplib')
async function createConnection (uri = 'guest:guest@localhost:5672') {
const connection = await amqp.connect('amqp://' + uri)
return connection
}
createConnection()
.then(conn => conn.createChannel())
.then(ch => {
@RafaelGSS
RafaelGSS / consumer.js
Last active September 1, 2019 23:54
Communication between microservices - RabbitMQ - CW Pattern - consumer
const amqp = require('amqplib')
async function createConnection (uri = 'guest:guest@localhost:5672') {
const connection = await amqp.connect('amqp://' + uri)
return connection
}
createConnection()
.then(conn => conn.createChannel())
.then(ch => {
@RafaelGSS
RafaelGSS / index.js
Created July 26, 2019 01:13
Index Example Fastify Plugin
const fastify = require('fastify')()
fastify.decorate('configuration', {
db: 'alguma-database',
port: 800
})
//Plugin1
fastify.register(require('./plugin1.js'))
//Plugin2
fastify.register(require('./plugin2.js'))
@RafaelGSS
RafaelGSS / index.js
Last active July 25, 2019 16:48
Example of Fastify+Swagger
const fastify = require('fastify')()
// Registrando o Swagger
fastify.register(require('fastify-swagger'), {
routePrefix: '/docs', // Rota para acessar a UI do Swagger
exposeRoute: true,
swagger: {
host: 'localhost:3000',
schemes: ['http'],
consumes: ['application/json'],