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
//Deep copying objects | |
//Method 1 | |
var cloneObject = jsonObject => JSON.parse(JSON.stringify(jsonObject)); | |
//Method 2 | |
function cloneObject(jsonObject){ | |
var cloned_obj = {}; | |
for(let key in jsonObject){ | |
if(jsonObject.hasOwnProperty(key)){ | |
cloned_obj[key] = jsonObject[key]; |
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
Value | Longhand | Summary | |
---|---|---|---|
initial | 0 1 auto | cannot grow but can shrink when there isn't enough space | |
auto | 1 1 auto | can grow and shrink to fit available space | |
none | 0 0 auto | cannot grow or shrink AKA inflexible | |
<positive-number> | <positive-number> 1 0 | can grow and shrink with extent of growth depending on flex factor |
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 classObj = document.querySelectorAll('.mv-title'); | |
const classArr = classObj.map((value,index) => [value.offsetWidth]); | |
const sumOfWidths = classArr.reduce((total, value) => total + value); | |
console.log(sumOfWidths); |
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
<div><form id="submitform"><input type="text" id="ship-pincode" required maxlength="6" placeholder="Enter Delivery Pincode" name="delivery_pincode" value=""><input type="submit"></form><p id="edd"><span></span></p></div><script>!function(){var e;if(void 0===window.jQuery||"3.3.1"!==window.jQuery.fn.jquery){var t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("src","https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"),t.readyState?t.onreadystatechange=function(){"complete"!=this.readyState&&"loaded"!=this.readyState||a()}:t.onload=a,(document.getElementsByTagName("head")[0]||document.documentElement).appendChild(t)}else e=window.jQuery,i();function a(){e=window.jQuery.noConflict(!0),i()}function i(){e(document).ready(function(e){e("#submitform").on("submit",function(t){t.preventDefault(),t.stopPropagation();var a={pickup_postcode:<PICKUP PINCODE>,delivery_postcode:e("#ship-pincode").val(),weight:<WEIGHT OF SHIPMENT IN KGS>,cod:<COD STATUS>};e.ajax({type: |
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
Regex - panNum.match('/[A-Za-z]{3}[p,P,c,C,h,H,f,F,a,A,t,T,b,B,l,L,j,J,g,G]{1}[A-Za-z]{1}\d{4}[A-Za-z]{1}/g') | |
PAN structure is as follows: AAAAA9999A: First five characters are letters, next 4 numerals, last character letter. | |
1) The first three letters are sequence of alphabets from AAA to zzz | |
2) The fourth character informs about the type of holder of the Card. Each assesse is unique:` | |
C — Company | |
P — Person | |
H — HUF(Hindu Undivided Family) |
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 videoUrls = ytplayer.config.args.url_encoded_fmt_stream_map | |
.split(',') | |
.map(item => item | |
.split('&') | |
.reduce((prev, curr) => (curr = curr.split('='), | |
Object.assign(prev, {[curr[0]]: decodeURIComponent(curr[1])}) | |
), {}) | |
) | |
.reduce((prev, curr) => Object.assign(prev, { | |
[curr.quality + ':' + curr.type.split(';')[0]]: curr |
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
#Credits to - https://gist.github.com/ghoseb/25049 | |
#Newbie programmer | |
def factorial(x): | |
if x == 0: | |
return 1 | |
else: | |
return x * factorial(x - 1) | |
print factorial(6) | |
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 countVowels(str){ | |
return (str.match(/[aeiou]/gi) == null) ? 0 : str.match(/[aeiou]/gi).length; | |
} | |
// return (str.match(/[aeiou]/gi) || []).length; - shorter version | |
// [aeiou] can be replaced by any other regex as per requirement |
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 removeDuplicates(values) { | |
var uniqueValues = {}; | |
values.forEach(function(i) { | |
if (!uniqueValues[i]) { | |
uniqueValues[i] = true; | |
} | |
}); | |
return Object.keys(uniqueValues); | |
} |
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 flatten(arr) { | |
return arr.reduce(function (flat, toFlatten) { | |
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten); | |
}, []); | |
} |