Skip to content

Instantly share code, notes, and snippets.

View PraveenMistry's full-sized avatar
🎯
Focusing

Praveen PraveenMistry

🎯
Focusing
View GitHub Profile
@PraveenMistry
PraveenMistry / median-of-two-sorted-arrays.js
Created August 12, 2022 16:28
4. Median of Two Sorted Arrays
/*
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
The overall run time complexity should be O(log (m+n)).
Example 1:
Input: nums1 = [1,3], nums2 = [2]
Output: 2.00000
@PraveenMistry
PraveenMistry / longest-substring-without-repeating-characters.js
Created August 12, 2022 16:23
Longest Substring Without Repeating Characters
/*
Longest Substring Without Repeating Characters
Example 1:
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:
Given an array nums of distinct integers, return all the possible permutations.
You can return the answer in any order.
Example 1:
Input: nums = [1,2,3]
Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Example 2:
Input: nums = [0,1]
@PraveenMistry
PraveenMistry / promiseWithRetry
Created December 31, 2019 17:22
Reinvoked function if not success with promise object
var prom = function(number) {
return new Promise((resolve, reject) => {
console.log('request start',number)
setTimeout(() => {
console.log('request finish')
let ran = Math.random();
if (ran < 0.1)
resolve(true);
@PraveenMistry
PraveenMistry / dbBackupScript.sh
Created November 17, 2019 12:08
Backup-MYSQL-DB-shell-script
# Basic configuration: datestamp e.g. YYYYMMDD
DATE=$(date +"%Y%m%d")
# Location of your backups (create the directory first!)
BACKUP_DIR="/backup"
# MySQL login details
@PraveenMistry
PraveenMistry / async-await.js
Created June 9, 2019 07:24
Async functions can make use of the await expression. This will pause the async function and wait for the Promise to resolve prior to moving on.
function doubleAfter2Seconds(x) {
return new Promise(resolve => {
setTimeout(() => {
resolve(x * 2);
}, 2000);
});
}
async function addAsync(x) {
const a = await doubleAfter2Seconds(10);
function doubleAfter2Seconds(x) {
return new Promise(resolve => {
setTimeout(() => {
resolve(x * 2);
}, 2000);
});
}
function addPromise(x){
return new Promise(resolve => {
var message = "";
promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
message += "my";
resolve(message);
}, 2000)
})
promise2 = new Promise((resolve, reject) => {
var request = require("request");
var userDetails;
function getData(url) {
// Setting URL and headers for request
var options = {
url: url,
headers: {
'User-Agent': 'request'
}
@PraveenMistry
PraveenMistry / promise.js
Created June 9, 2019 07:21
Promises are such constructs which are introduced to reduce the complexity of Asynchronous JavaScript code.
var request = require("request");
var userDetails;
function initialize() {
// Setting URL and headers for request
var options = {
url: 'https://api.github.com/users/praveenmistry',
headers: {
'User-Agent': 'request'
}