Skip to content

Instantly share code, notes, and snippets.

View sandeep-cs-dev's full-sized avatar

Sandeep Patel sandeep-cs-dev

View GitHub Profile
@sandeep-cs-dev
sandeep-cs-dev / AesGcm256Pbkdf2StringEncryption.java
Created October 24, 2024 21:15
AesGcm256Pbkdf2StringEncryption
import javax.crypto.*;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
@sandeep-cs-dev
sandeep-cs-dev / worker-shared-handle.js
Created September 29, 2024 14:37
worker-shared-handle.js
const net = require('net');
process.on('message', (message, serverHandle) => {
if (message === 'server') {
createServerAndListen(serverHandle);
}
});
function createServerAndListen(serverHandle) {
const server = net.createServer(handleConenction);
@sandeep-cs-dev
sandeep-cs-dev / primary-shared-handle.js
Last active September 30, 2024 23:57
primary-shared-handle.js
const {
fork
} = require('child_process');
const net = require('net');
const os = require('os');
const numCPUs = os.cpus().length;
const workers = [];
// Fork workers
@sandeep-cs-dev
sandeep-cs-dev / worker-round-robin-policy.js
Created September 29, 2024 14:29
worker-round-robin-policy.js
const net = require('net');
const handleConenction = (socket) => {
console.log("New connection");
socket.on('close', () => {
console.log('Client has disconnected');
});
// Handle 'data' event to process data from the client
@sandeep-cs-dev
sandeep-cs-dev / primary-round-robin-policy.js
Last active September 30, 2024 23:57
primary-round-robin-policy.js
const { fork } = require('child_process');
const net = require('net');
const os = require('os');
const numCPUs = os.cpus().length;
const workers = [];
let workerIndex = 0;
// Fork workers
for (let i = 1; i <=numCPUs; i++) {
const worker = fork('worker-round-robin-policy.js'); // Fork the worker process
@sandeep-cs-dev
sandeep-cs-dev / docker-compose.yml
Created March 24, 2023 18:17 — forked from onjin/docker-compose.yml
example docker compose for postgresql with db init script
postgres:
image: postgres:9.4
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
@sandeep-cs-dev
sandeep-cs-dev / README.md
Created March 13, 2023 20:52 — forked from jasonk/README.md
MongoDB Update Pipeline Tricks

Starting with MongoDB 4.2, you can use [aggregation pipelines to update documents][$pipelines]. Which leads to some really cool stuff.

For example, prior to this you could easily add sub-documents to an array using [$addtoSet][$addtoSet], and you could remove documents from an array using [$pull][$pull], but you couldn't do both in the same operation, you had to send two separate update commands if you needed to remove some and add some.

With 4.2, now you can, because you can format your update as a pipeline, with multiple $set and $unset stages, which makes those things possible. However, since this is so new I had a really hard time finding examples of many of the things I wanted to do, so I started to collect some here for my reference (and yours).

See also:

console.time('eventlooplag');
//event-loop timer phase
setTimeout(() =>console.timeEnd('eventlooplag'), 100);
/*blocking code, stalling event loop, delaying the execution of the setTimeout ie lag in the event loop
*/
const min = 2;
const max = 3e6;
const primes = [];
function generatePrimes(start, range) {
let isPrime = true;
let stop = false;
//event-loop timer phase
//set stop to true after 100 ms
setTimeout(() => stop = true, 100);
/*blocking code
Event loop timer phase or any other phase could not be executed
*/
--log_gc (Log heap samples on garbage collection for the hp2ps tool.)
type: bool default: false
--expose_gc (expose gc extension)
type: bool default: false
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0