Skip to content

Instantly share code, notes, and snippets.

View SagarBajpai's full-sized avatar

Sagar Bajpai SagarBajpai

View GitHub Profile
@SagarBajpai
SagarBajpai / disable-back-swipe.js
Created July 8, 2025 05:56 — forked from spint/disable-back-swipe.js
Disabling back history navigation with swipe (chrome)
// http://stackoverflow.com/questions/15829172/stop-chrome-back-forward-two-finger-swipe
$(document).on('mousewheel', function(e) {
var $target = $(e.target).closest('.scrollable-h');
if ($target.scrollLeft () <= 4) {
$target.scrollLeft(5);
return false;
}
});
@SagarBajpai
SagarBajpai / truncate.css
Created February 22, 2024 09:30 — forked from elky/truncate.css
text-overflow ellipsis with 100% width
/*
Demo: https://jsfiddle.net/elky/f6khaf2t/
<div class="element">
<div class="truncate">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
(?i)((access_key|access_token|admin_pass|admin_user|algolia_admin_key|algolia_api_key|alias_pass|alicloud_access_key|amazon_secret_access_key|amazonaws|ansible_vault_password|aos_key|api_key|api_key_secret|api_key_sid|api_secret|api.googlemaps AIza|apidocs|apikey|apiSecret|app_debug|app_id|app_key|app_log_level|app_secret|appkey|appkeysecret|application_key|appsecret|appspot|auth_token|authorizationToken|authsecret|aws_access|aws_access_key_id|aws_bucket|aws_key|aws_secret|aws_secret_key|aws_token|AWSSecretKey|b2_app_key|bashrc password|bintray_apikey|bintray_gpg_password|bintray_key|bintraykey|bluemix_api_key|bluemix_pass|browserstack_access_key|bucket_password|bucketeer_aws_access_key_id|bucketeer_aws_secret_access_key|built_branch_deploy_key|bx_password|cache_driver|cache_s3_secret_key|cattle_access_key|cattle_secret_key|certificate_password|ci_deploy_password|client_secret|client_zpk_secret_key|clojars_password|cloud_api_key|cloud_watch_aws_access_key|cloudant_password|cloudflare_api_key|cloudflare_auth_k
@SagarBajpai
SagarBajpai / GSTINValidation.js
Last active December 8, 2022 05:28
GSTIN number format validation in JavaScript
const GSTINFORMAT_REGEX = "[0-9]{2}[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9A-Za-z]{1}[Z]{1}[0-9a-zA-Z]{1}";
const GSTN_CODEPOINT_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
function validGSTIN(gstin) {
let isValidFormat = false;
if (checkPattern(gstin, GSTINFORMAT_REGEX)) {
isValidFormat = verifyCheckDigit(gstin);
}
return isValidFormat;
}
@SagarBajpai
SagarBajpai / Eyeballing-This.md
Created November 8, 2020 06:29 — forked from zcaceres/Eyeballing-This.md
Understanding Binding and 'this' in Javascript by zach.dev

How to Eyeball Your ‘This’ Context in Javascript

The early programmer struggles with the Javascript keyword this. But understanding your this context is easier than it seems.

This is all about where a function is invoked. Often, early programmers worry about where the function was declared. Perhaps the function was declared in a specific file or a particular object. Surely this changes it's this!

Nope.

//Debounce Function
function debounce(func, delay){
clearTimeout(timerId);
timerId = setTimeout(func, delay);
}
function throttling(event, func, delay){
event.persist(); // if you are using react
const evt = event;
if(timerIdT)
return;
timerIdT = setTimeout(()=>{
func(evt);
timerIdT = undefined;
}, delay);