This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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([ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { entity, field } = require('@herbsjs/herbs') | |
| const required = { validation: { presence: true } } | |
| const requiredString = { | |
| validation: { | |
| ...required.validation, | |
| length: { minimum: 3, maximum: 255 }, | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { entity, field } = require('@herbsjs/herbs') | |
| const required = { validation: { presence: true } } | |
| module.exports = entity('Sale', { | |
| id: field(Number, { | |
| // Optional option | |
| validation: { | |
| presence: true, | |
| numericality: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { entity, field } = require('@herbsjs/herbs') | |
| const requiredString = { | |
| validation: { | |
| presence: true, | |
| length: { minimum: 3, maximum: 255 }, | |
| } | |
| } | |
| const Customer = entity('Customer', { |
NewerOlder