Skip to content

Instantly share code, notes, and snippets.

View srebalaji's full-sized avatar
🎯
Focusing

Srebalaji Thirumalai srebalaji

🎯
Focusing
View GitHub Profile
@srebalaji
srebalaji / main.js
Created April 7, 2020 06:12
Message channel in Worker threads
const { MessageChannel } = require('worker_threads')
const {port1, port2} = new MessageChannel()
port1.once('message', (msg) => {
console.log(msg)
})
port2.postMessage({msg: "hello world"})
@srebalaji
srebalaji / main.js
Created April 7, 2020 14:25
Message channels between workers
// main.js
const {Worker, parentPort, MessageChannel} = require('worker_threads')
const worker = new Worker('./worker.js')
const messageChannel = new MessageChannel()
// As you can see there are two parameters passed in `postMessage`
worker.postMessage({yourPort: messageChannel.port1}, [messageChannel.port1])
@srebalaji
srebalaji / workerPool.js
Last active April 8, 2020 08:04
Worker thread pool - Manage worker threads pool in NodeJS
// workerPool.js
// Worker Thread pool
const {Worker, parentPort, MessageChannel} = require('worker_threads')
class WorkerPool {
constructor(size, worker) {
this.size = size
this.worker = worker
this.pool = []
@srebalaji
srebalaji / readme.md
Created April 11, 2020 07:25
How to fix React router redirection in webpack production build - Netlify
@srebalaji
srebalaji / git-hard-delete
Last active October 10, 2023 13:10
Examples of git custom command
#!/bin/sh
branch=$1
if [ ! -z "$1" ]
then
git branch -D $branch
git push -d origin $branch
else
echo "Branch name is not specified"
@srebalaji
srebalaji / checkout.sh
Created April 10, 2023 08:15
Bash script to checkout to new branch if you have any files with updated index
#!/bin/bash
# Set the branch name as the first argument passed to the script
branch_name=$1
# Cancel the skip-worktree changes for all files
git ls-files -v | grep ^S | cut -c 3- | xargs git update-index --no-skip-worktree
# Stash all files
git stash save --keep-index --include-untracked "Stashing skip-worktree files"