Skip to content

Instantly share code, notes, and snippets.

View jahilldev's full-sized avatar
⏱️
Perf.

James Hill jahilldev

⏱️
Perf.
View GitHub Profile
{"success":true,"samplesPurchased":[[{"id":"gid://shopify/Product/9775822799151","title":"New Leaf","handle":"new-leaf","description":"","onlineStoreUrl":null,"featuredImage":null,"variants":[{"id":"gid://shopify/ProductVariant/48996506665263","sku":"NELE30ML20"}],"isDiscovery":false,"isFragrance":true,"isGift":false,"isSample":false},{"id":"gid://shopify/Product/9128802648367","title":"No Reason","handle":"example-product-1","description":"","onlineStoreUrl":null,"featuredImage":{"width":1460,"height":1457,"altText":null,"url":"https://cdn.shopify.com/s/files/1/0839/6806/5839/products/TEST.jpg_0005_Layer0.jpg?v=1695820293"},"variants":[{"id":"gid://shopify/ProductVariant/47408366125359","sku":"NORE30ML25"}],"isDiscovery":false,"isFragrance":true,"isGift":false,"isSample":false},{"id":"gid://shopify/Product/9775824142639","title":"Slow Exhale","handle":"slow-exhale","description":"","onlineStoreUrl":null,"featuredImage":null,"variants":[{"id":"gid://shopify/ProductVariant/48996521836847","sku":"SLEX30ML20"}],
import Document, {
Main,
NextScript,
Head,
Html
} from 'next/document'
import {readFileSync} from "fs"
import {join} from "path"
class InlineStylesHead extends Head {
@jahilldev
jahilldev / memoize.ts
Created July 8, 2022 11:32
Fully typed Memoize function, maintains argument function and expected return types
function memoize<T extends (...args: any[]) => any>(
func: T
): (...funcArgs: Parameters<T>) => ReturnType<T> {
const results = {};
return (...args: Parameters<T>): ReturnType<T> => {
const cacheKey = JSON.stringify(args);
if (!results[cacheKey]) {
results[cacheKey] = func(...args);
@jahilldev
jahilldev / is-target-element.js
Last active September 13, 2022 13:00
Function to match an element via a target selector in the provided tree. Useful for event delegation.
function isTargetElement(element, selector) {
let target = element;
while (target) {
if (target?.matches && target?.matches(selector)) {
break;
}
target = target?.parentNode;
}
@jahilldev
jahilldev / get-hash-from-value.js
Created May 30, 2022 15:47
Generate a non-secure reproducible hash from an input seed value (not suitable for passwords, or sensitive data)
function getHash(value, length = 16) {
let hash = 0;
for (let index = 0; index < value.length; index++) {
hash = (hash << 5) - hash + value.charCodeAt(index);
hash = hash & hash;
}
hash = Math.abs(hash);
function isPrimeNumber(value) {
for(let index = 2; index < value; index++) {
if(value % index === 0) {
return false;
}
return value > 1;
}
return false;
@jahilldev
jahilldev / tiny-debounce.js
Last active July 28, 2022 17:05
Tiny JavaScript debounce function
function debounce(callback, frequency = 250, timer = null) {
return (...args) => (
clearTimeout(timer), (timer = setTimeout(callback, frequency, ...args))
);
}