Skip to content

Instantly share code, notes, and snippets.

View MaxXxiMast's full-sized avatar

Purujit Negi MaxXxiMast

View GitHub Profile
@MaxXxiMast
MaxXxiMast / script.js
Last active October 19, 2016 07:16
#RegExp for a alphanumeric value not starting with 0, can have no special characters other that _ or -
//validation check for sku of a product
//alphanumeric
var regExp = "/^[^0][A-Za-z0-9_-]{3,50}$/";
// ^ start of string
// [^0] 1st char will not be 0
// [A-Za-z0-9_-] A or B ... Z or a or b or ... z or 0 or 1 or ... 9 or underscores(_) or hyphen/dash (-)
// {3,50} length between 3-50
@MaxXxiMast
MaxXxiMast / noImageReplace.html
Created May 8, 2017 14:18
Replace a 404 Image with a default image in Angular
<img ng-if="product.image" ng-src="{{product.image}}" alt="{{product.name}}" onerror="angular.element(this).scope().product.image = false">
<img ng-if="!product.image" ng-src="http://placehold.it/{{vm.image.width}}x{{vm.image.height}}" alt="{{product.name}}">
@MaxXxiMast
MaxXxiMast / text.txt
Created November 2, 2016 07:18
Tool to build a CMS
http://www.webhook.com/
@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);
}, []);
}
@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 / 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 / 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
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)
<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:
@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);