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
app.get('/cpu-intensive/:type/:num/:threads', (req,res) => { | |
console.log('Type: ',req.params.type) | |
console.log('Num:' ,req.params.num) | |
console.log('Threads:' ,req.params.threads) | |
// switch method to run based on TYPE | |
// increasing NUM means increasing CPU-operations | |
// THREADS are the threads to use when using arrays of workers | |
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
//worker.js | |
const {parentPort} = require("worker_threads"); | |
const calculus = require('./calculus') | |
parentPort.on("message", data => { | |
parentPort.postMessage({input: data.num, output: calculus.execute(data.num)}); | |
}); | |
const worker_calculus = (num) => { | |
return new Promise((resolve, reject) => { |
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
let numberOfThreads = 10; | |
const workerArray = []; | |
for (let n = 0; n < numberOfThreads; n++) { | |
workerArray.push(new Worker("./project_modules/worker.js")) | |
} | |
let i = 0; | |
const worker_array_calculus = (num,threads) => { | |
return new Promise((resolve, reject) => { | |
let workerNum = i % threads; |
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 fs = require('fs'); | |
const searchFull = (filename, text) => { | |
return new Promise((resolve) => { | |
const regEx = new RegExp(text, "i") | |
const result = []; | |
fs.readFile('file/' + filename + ".txt", 'utf8', function (err, contents) { |
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 fs = require('fs'); | |
const readline = require('readline'); | |
const stream = require('stream'); | |
const searchStream = (filename, text) => { | |
return new Promise((resolve) => { | |
const inStream = fs.createReadStream('file/' + filename + ".txt"); | |
const outStream = new stream; | |
const rl = readline.createInterface(inStream, outStream); |
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 osType = require('os').type(); | |
const {spawn} = require('child_process'); | |
const searchOs = (filename, text) => { | |
return new Promise((resolve) => { | |
if (osType === 'Windows_NT') { | |
console.log('Searching using WINDOWS FIDSTR'); | |
let child = spawn('findstr', [ |
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
import com.fasterxml.jackson.databind.ObjectMapper; | |
String content = "{\"params\":{\"preference\":1620226203317,\"index\":\"filebeat*\",\"body\":{\"version\":true,\"size\":2000,\"sort\":[{\"@timestamp\":{\"order\":\"desc\",\"unmapped_type\":\"boolean\"}}],\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"fixed_interval\":\"3h\",\"time_zone\":\"Europe/Rome\",\"min_doc_count\":1}}},\"stored_fields\":[\"*\"],\"script_fields\":{},\"docvalue_fields\":[{\"field\":\"@timestamp\",\"format\":\"date_time\"},{\"field\":\"azure.enqueued_time\",\"format\":\"date_time\"},{\"field\":\"event.created\",\"format\":\"date_time\"},{\"field\":\"event.end\",\"format\":\"date_time\"},{\"field\":\"event.ingested\",\"format\":\"date_time\"},{\"field\":\"event.start\",\"format\":\"date_time\"},{\"field\":\"file.accessed\",\"format\":\"date_time\"},{\"field\":\"file.created\",\"format\":\"date_time\"},{\"field\":\"file.ctime\",\"format\":\"date_time\"},{\"field\":\"file.mtime\",\"format\":\"date_time\"},{\"field\":\"kafk |
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
List<String> bigList = Arrays.asList("1","2"....."6000") | |
for (int i = 0; i < bigList.size(); i++) { | |
String tokenToSearch = bigList.get(i); | |
if (i % 100 == 0) { | |
if (i != 0) { | |
bufferedWriter.close(); | |
} |
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
import React from "react"; | |
import socketIOClient from "socket.io-client"; | |
import {generateUniqueID} from "web-vitals/dist/lib/generateUniqueID"; | |
import debounce from 'lodash.debounce'; | |
import throttle from 'lodash.throttle'; | |
class App extends React.Component { |
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 express = require("express"); | |
const http = require("http"); | |
const socketIo = require("socket.io"); | |
const cors = require('cors') | |
const bodyParser = require('body-parser'); | |
const port = process.env.PORT || 4001; | |
const app = express(); | |
app.use(cors()); |