This file contains 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
set number | |
set noet ci pi sts=0 sw=4 ts=4 | |
set cursorline | |
set showcmd | |
filetype indent on | |
set wildmenu | |
set lazyredraw | |
set showmatch | |
set incsearch | |
set hlsearch |
This file contains 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
pry-rescue | |
pry-nav | |
pry-rails | |
pry-stack_explorer | |
pry-theme |
This file contains 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
// A simple promise that resolves after a given time | |
const timeOut = (t) => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(`Completed in ${t}`) | |
}, t) | |
}) | |
} | |
// Resolving a normal promise. |
This file contains 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
// A simple promise that resolves after a given time | |
const timeOut = (t) => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(`Completed in ${t}`) | |
}, t) | |
}) | |
} | |
const durations = [1000, 2000, 3000] |
This file contains 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
// A simple promise that resolves after a given time | |
const timeOut = (t) => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
if (t === 2000) { | |
reject(`Rejected in ${t}`) | |
} else { | |
resolve(`Completed in ${t}`) | |
} | |
}, t) |
This file contains 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 durations = [1000, 2000, 3000] | |
promises = durations.map((duration) => { | |
return timeOut(duration).catch(e => e) // Handling the error for each promise. | |
}) | |
Promise.all(promises) | |
.then(response => console.log(response)) // ["Completed in 1000", "Rejected in 2000", "Completed in 3000"] | |
.catch(error => console.log(`Error in executing ${error}`)) |
This file contains 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
// Async function to send mail to a list of users. | |
const sendMailForUsers = async (users) => { | |
const usersLength = users.length | |
for (let i = 0; i < usersLength; i += 100) { | |
const requests = users.slice(i, i + 100).map((user) => { // The batch size is 100. We are processing in a set of 100 users. | |
return triggerMailForUser(user) // Async function to send the mail. | |
.catch(e => console.log(`Error in sending email for ${user} - ${e}`)) // Catch the error if something goes wrong. So that it won't block the loop. | |
}) | |
This file contains 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
// Function to fetch Github info of a user. | |
const fetchGithubInfo = async (url) => { | |
console.log(`Fetching ${url}`) | |
const githubInfo = await axios(url) // API call to get user info from Github. | |
return { | |
name: githubInfo.data.name, | |
bio: githubInfo.data.bio, | |
repos: githubInfo.data.public_repos | |
} | |
} |
This file contains 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
// index.js | |
const {Worker, isMainThread, parentPort, workerData} = require('worker_threads') | |
const worker = new Worker("./worker.js", {workerData: {a: 5, b: 10}}) | |
worker.once('message', (result) => { | |
console.log('The sum is', result) | |
}) | |
This file contains 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 {Worker, isMainThread, parentPort, workerData} = require('worker_threads') | |
// Returns if the script runs in main thread of in worker | |
if (isMainThread) { | |
const arr = [[1, 10],[2, 15],[3, 21],[4, 25],[5, 86]] | |
for (const ele of arr) { | |
const worker = new Worker(__filename, {workerData: {a: ele[0], b: ele[1]}}) | |
worker.on('message', (result) => { | |
console.log(`The sum of ${ele[0]} and ${ele[1]} is ${result}`) |
OlderNewer