Skip to content

Instantly share code, notes, and snippets.

View jasonmcneill's full-sized avatar

Jason McNeill jasonmcneill

View GitHub Profile
@jasonmcneill
jasonmcneill / isMobile
Last active June 9, 2022 17:03
Indicates whether the user's device is a mobile device
function isMobile() {
let isMobile = false;
const isScreenLTE480px = window.matchMedia("only screen and (max-width: 480px)").matches;
const hasCoursePointer = window.matchMedia("(pointer:coarse)").matches;
if (isScreenLTE480px && hasCoursePointer) isMobile = true;
return isMobile;
}
@jasonmcneill
jasonmcneill / getUniqueId
Last active November 19, 2021 23:36
Generate a unique ID
function getUniqueId(numChars = 5) {
const chars =
"1234567890" + "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const charsLen = chars.length;
const id = [];
for (let i = 0; i < numChars; i++) {
id.push(chars[Math.round(Math.random() * 100) % charsLen]);
}
const uniqueId = id.join("");
return uniqueId;