Skip to content

Instantly share code, notes, and snippets.

View MaxXxiMast's full-sized avatar

Purujit Negi MaxXxiMast

View GitHub Profile
//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];
@MaxXxiMast
MaxXxiMast / flex.csv
Last active November 5, 2018 06:26
Flex Shorthand Cheat-sheet
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
@MaxXxiMast
MaxXxiMast / combinedClassWidth.js
Created May 17, 2018 05:50
Get the combined width of all the elements with specific className present in a DOM
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);
<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:
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)
@MaxXxiMast
MaxXxiMast / youtubeurls.js
Created June 14, 2017 12:29
Getting Youtube Video URls
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
#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)
@MaxXxiMast
MaxXxiMast / countVowels.js
Last active June 1, 2017 19:06
Check the number of vowels in a string
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
@MaxXxiMast
MaxXxiMast / removeDuplicates.js
Created May 30, 2017 15:49
Function to remove duplicate elements from an array
function removeDuplicates(values) {
var uniqueValues = {};
values.forEach(function(i) {
if (!uniqueValues[i]) {
uniqueValues[i] = true;
}
});
return Object.keys(uniqueValues);
}
@MaxXxiMast
MaxXxiMast / flatten.js
Created May 25, 2017 13:32
Function to flatten a multi dimensional array
function flatten(arr) {
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}