Skip to content

Instantly share code, notes, and snippets.

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

Italo José italojs

🏠
Working from home
View GitHub Profile
#!/bin/zsh
# Script to stop all mongod from local replica set
# Kills all mongod processes started with --replSet rs0
REPLSET_NAME="rs0"
# Terminates all mongod from replica set
pkill -f "mongod.*--replSet $REPLSET_NAME"
#!/bin/zsh
# Path to Meteor's mongod binary
MONGOD_BIN="$HOME/.meteor/packages/meteor-tool/.3.3.0-rc.0.98m07w5jwdt++os.osx.arm64+web.browser+web.browser.legacy+web.cordova/mt-os.osx.arm64/dev_bundle/mongodb/bin/mongod"
# Base directory for data
DATA_DIR="./mongo-replica"
# Ports for nodes
/* Results from my local Intel Mac i9 16gb
fs.readFileSync + JSON.parse:
Min: 0.0174 ms
Max: 0.7195 ms
Average: 0.0221 ms
require:
Min: 0.0006 ms
Max: 0.4166 ms
Average: 0.0010 ms
const { MongoClient } = require('mongodb');
class MongoDBClient {
constructor(uri, dbName) {
this.uri = uri;
this.dbName = dbName;
this.client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
}
async connect() {
@italojs
italojs / server.js
Last active February 9, 2024 21:17
const fastify = require('fastify')({ logger: true });
const MongoDBClient = require('./MongoDBClient');
const uri = process.env.DB_URI;
const dbName = 'bancoDeDadosDaAPI';
const dbClient = new MongoDBClient(uri, dbName);
async function setupRoutes() {
// Pré-cadastro de clientes
await dbClient.insertClientes([
const {
Worker,
isMainThread,
parentPort,
workerData } = require('worker_threads');
const { performance } = require('perf_hooks');
// Função para encontrar números primos em um intervalo
const findPrimes = (start, end) => {
const primes = [];
@italojs
italojs / map.js
Created September 25, 2023 22:38
map-performance
const { performance } = require('perf_hooks');
// Generate a list of products
const productArray = Array.from({ length: 1000000 }, (_, i) => ({
id: i,
name: `product${i}`,
price: i * 0.5
}));
// Convert the product list to a Map for faster lookups
const { entity, field } = require('@herbsjs/herbs')
const required = { validation: { presence: true } }
const requiredString = {
validation: {
...required.validation,
length: { minimum: 3, maximum: 255 },
}
}
const { entity, field } = require('@herbsjs/herbs')
const required = { validation: { presence: true } }
module.exports = entity('Sale', {
id: field(Number, {
// Optional option
validation: {
presence: true,
numericality: {
@italojs
italojs / customer.js
Last active September 16, 2021 15:28
const { entity, field } = require('@herbsjs/herbs')
const requiredString = {
validation: {
presence: true,
length: { minimum: 3, maximum: 255 },
}
}
const Customer = entity('Customer', {