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
// In this example, we have two types of elements: Leaf and Node. Both implement the Element interface, | |
// which defines an accept method that takes a Visitor object as an argument. | |
// The Visitor interface defines two methods, visit(Leaf) and visit(Node), | |
// which are called by the accept method of the corresponding element. | |
// | |
// The PrintVisitor class implements the Visitor interface and provides an implementation for each of the visit methods. | |
// In this case, it simply prints a message to the console. | |
// | |
// Finally, in the main method, we create a tree of elements and | |
// traverse it using the accept method of the root element and a PrintVisitor object. |
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
require 'fileutils' | |
files = Dir.glob("*.{mp3,m4a,wav}") | |
converted_dir = "converted" | |
FileUtils.mkdir_p converted_dir | |
puts "Enter the bitrate:" | |
bitrate = gets.chomp |
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 http = require("http"); | |
async function task (ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
function getRndInteger(min, max) { | |
return Math.floor(Math.random() * (max - min + 1) ) + min; | |
} |
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 http = require("http"); | |
async function task (ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
function getRndInteger(min, max) { | |
return Math.floor(Math.random() * (max - min + 1) ) + min; | |
} |
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 http = require("http"); | |
function computeTerm(term) { | |
setTimeout(() => { | |
delete computeTerm[term]; | |
}, 1000); | |
return computeTerm[term] || (computeTerm[term] = compute()); | |
function compute() { | |
return Buffer.alloc(1e3); |
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 http = require("http"); | |
function computeTerm(term) { | |
return computeTerm[term] || (computeTerm[term] = compute()); | |
function compute() { | |
return Buffer.alloc(1e3); | |
} | |
} | |
const server = http.createServer((req, res) => { | |
res.end(computeTerm(Math.random())); |
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
// Simulate crash | |
if (cluster.isWorker) { | |
setTimeout(() => { | |
process.exit(1) // death by random timeout | |
}, Math.random() * 100000); | |
} | |
// Add this to the callback | |
cluster.on("exit", function(worker, code, signal) { |
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
// Require the framework and instantiate it | |
const os = require("os"); | |
const cluster = require("cluster"); | |
const fastify = require('fastify')({ | |
logger: false, | |
disableRequestLogging: true | |
}); | |
const clusterWorkerSize = os.cpus().length; |
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
// Require the framework and instantiate it | |
const fastify = require('fastify')({ | |
logger: true, | |
disableRequestLogging: true | |
}); | |
// Declare a route | |
fastify.get('/', async (request, reply) => { | |
return { hello: 'world' }; | |
}) |
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
// userService/testClient.js | |
const messages = require('./proto/user_pb'); | |
const services = require('./proto/user_grpc_pb'); | |
const grpc = require('@grpc/grpc-js'); | |
function main() { | |
const client = new services.UserSvcClient('localhost:8080', grpc.credentials.createInsecure()); | |
let registerReq = new messages.RegisterRequest(); |
NewerOlder