Skip to content

Instantly share code, notes, and snippets.

View santoshvijapure's full-sized avatar
🎯
Focusing

Santosh Vijapure santoshvijapure

🎯
Focusing
View GitHub Profile
@santoshvijapure
santoshvijapure / useIsMobile.ts
Created December 5, 2022 02:50
React hook to determine the client device based on the screen size
import { useLayoutEffect, useState } from 'react';
import debounce from 'lodash/debounce';
const useIsMobile = (): boolean => {
const [isMobile, setIsMobile] = useState(false);
useLayoutEffect(() => {
const updateSize = (): void => {
setIsMobile(window.innerWidth < 768);
};
@santoshvijapure
santoshvijapure / countriesWithStates.ts
Created November 30, 2022 03:25
A map of all countries with states and country flags and with some basic information about country. [typescript]
export interface ICountryStates {
name: string;
state_code: string;
}
export interface ICountrySchema {
name: string;
country_code: string;
iso3: string;
phone_code: string;
flag_emoji: string;
@santoshvijapure
santoshvijapure / xpath.js
Created December 27, 2021 07:31
get a DOM node with Xpath
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
// *** use ***
// getElementByXpath(XpathTargetingDOMNode)
@santoshvijapure
santoshvijapure / listeneres.js
Created August 26, 2021 14:33
script to get active event listers attached on window
function listAllEventListeners() {
const allElements = Array.prototype.slice.call(document.querySelectorAll('*'));
allElements.push(document);
allElements.push(window);
const types = [];
for (let ev in window) {
if (/^on/.test(ev)) types[types.length] = ev;
}
@santoshvijapure
santoshvijapure / cloudSettings
Last active November 12, 2021 11:55
Visual Studio Code Settings Sync Gist
{"lastUpload":"2021-11-12T11:55:51.809Z","extensionVersion":"v3.4.3"}