Skip to content

Instantly share code, notes, and snippets.

💭
Currently working on klip.space

Srebalaji Thirumalai srebalaji

💭
Currently working on klip.space
Block or report user

Report or block srebalaji

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@srebalaji
srebalaji / promise-all-map.js
Last active Mar 23, 2019
A sample Promise.all in map
View promise-all-map.js
// 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
}
}
@srebalaji
srebalaji / Promise all example to send email.js
Last active Apr 11, 2019
A simple Promise all example to send emails
View Promise all example to send email.js
// 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.
})
@srebalaji
srebalaji / sample-promise-all-handle-rejection.js
Last active Apr 11, 2019
A sample promise all to handle rejections
View sample-promise-all-handle-rejection.js
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}`))
@srebalaji
srebalaji / sample-promise-all-in-rejection.js
Last active Mar 23, 2019
A sample promise all with rejection
View sample-promise-all-in-rejection.js
// 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)
@srebalaji
srebalaji / sample-promise-in-map.js
Last active Mar 23, 2019
A sample promise with map
View sample-promise-in-map.js
// 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]
@srebalaji
srebalaji / sample-promise.js
Created Mar 4, 2019
A simple JS file that explains Promise.all
View sample-promise.js
// 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.
@srebalaji
srebalaji / Gemfile
Last active May 5, 2019
Pry plugins
View Gemfile
pry-rescue
pry-nav
pry-rails
pry-stack_explorer
pry-theme
@srebalaji
srebalaji / .vimrc
Last active Oct 30, 2017
Vim configuration
View .vimrc
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
You can’t perform that action at this time.