Skip to content

Instantly share code, notes, and snippets.

@junaidulqayyumqureshi
Created April 14, 2020 06:00
Show Gist options
  • Save junaidulqayyumqureshi/1f5a1fca2c7db1957d5bd70c20c66e6a to your computer and use it in GitHub Desktop.
Save junaidulqayyumqureshi/1f5a1fca2c7db1957d5bd70c20c66e6a to your computer and use it in GitHub Desktop.
Code snippets which I use more often in projects
@junaidulqayyumqureshi
Copy link
Author

junaidulqayyumqureshi commented Aug 15, 2021

Transfer data from one server to another

Copy files from one SSH to another SSH server

scp /path/to/file username@a:/path/to/destination

Step 1:
Zip the product

zip -r product.zip /var/www/product

Step 2:
Take db dump on host server

mysqldump -u root -p spencer > /var/www/exported.sql

Step 3:
Transfer it to new server

scp /var/www/spencer.zip root@{ipaddresss}:/var/www/product-destination-on-remote-server

@junaidulqayyumqureshi
Copy link
Author

junaidulqayyumqureshi commented Aug 17, 2021

Import Export MySQL DB Command Line

Export Dump.sql WITH/WITHOUT SCHEMA
mysqldump -u root -p DB_NAME > /var/www/exported.sql

mysqldump -u root -p --no-data DB_NAME > /var/www/exported.sql

Import Dump.sql
mysql -u root -p database_name < file.sql

@junaidulqayyumqureshi
Copy link
Author

Find string/substring linux

grep -rnw '/var/www/project' -e 'stringtosearch'

@junaidulqayyumqureshi
Copy link
Author

junaidulqayyumqureshi commented Mar 13, 2023

NodeJS Worker Threads

main.js

const { Worker } = require('worker_threads');
const worker = new Worker('./wthread.js');
worker.on('message', (msg) => {
    console.log(`Msg: ${JSON.stringify(msg)}`);
});
// worker.on('error', reject);
worker.on('exit', (code) => {
    if (code !== 0)
        throw new Error(`stopped with  ${code} exit code`)
})

wthread.js

const { workerData, parentPort } = require('worker_threads')

parentPort.postMessage({ "StartedAt": workerData })
------ Code Logic ------
parentPort.postMessage({ result: result })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment