This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function debounce(callback, frequency = 250, timer = null) { | |
return (...args) => ( | |
clearTimeout(timer), (timer = setTimeout(callback, frequency, ...args)) | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isTargetElement(element, selector) { | |
let target = element; | |
while (target) { | |
if (target?.matches && target?.matches(selector)) { | |
break; | |
} | |
target = target?.parentNode; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isPrimeNumber(value) { | |
for(let index = 2; index < value; index++) { | |
if(value % index === 0) { | |
return false; | |
} | |
return value > 1; | |
} | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Document, { | |
Main, | |
NextScript, | |
Head, | |
Html | |
} from 'next/document' | |
import {readFileSync} from "fs" | |
import {join} from "path" | |
class InlineStylesHead extends Head { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"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"}], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Try.ts | |
// By Colin Teahan | |
// August 14th, 2024 | |
// | |
// This TypeScript file enables usage of the .try() method which will return a result tuple of [T?, Error?] | |
// from any function or async function. This works by defining a new property on the global Object.prototype | |
// and then do some type-fu. | |
// | |
// Example usage: | |
// https://www.typescriptlang.org/play/?target=99#code/MYewdgziA2CmB0w4EMBOAKAlAKGwejwAJCAVVAT3gBcJ8jCAhcwgYRgEsxTZkALZMHWIBBAK4BzURCqEAjABYqvADSEATAAY18ukNK92EUuQAOsAMrBU7EzIBm7OIVhhkAIzhGpycbEIg7QiU-agosQgBbWCUQABNCAHcDYF5Ex2hCVGjRVC5kTNgIUWgZKlETJwDCAG0SAH5VAFFUVBBUOoBdPTtWiMIBZjtRMGAqdnB-VH6IchHCIZGx8Hh9Q0S2gGsjN2ZY2AcwTnF+wjBYBMITVrNUKmYJ4MJxaBA3ZAyAeTcAK1hR+CuICoQNMsD0AniwS4sRAhCgUSCoIAtEN4LoCMRGgAPZARCp+by+ABc6PoC1G4y4vioAFUILBUEwAJKxdDsWJE06iCJuBmYQgAbz0xGI7ECbPiAB4ALyEDT8pStC5nC7NVoYADknAAbu92YQpAzCOyNTgMSLiFkyrlBadcbBORqGK8Nap9QBfPSegh6UCQGTVQ2oVQM9UdQiy6l0hnM2KhcjoeWESVIpHOFptNLQDK8grWs6xX3gaQ1IMhjOocOR6LRxnkFnx9CyfkptNBwhOl3GoxWnIF0nEAByHxIjU5JAMRjW0nSJwSm2NXEB4iyECMEO7pyBcNE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
- This is undocumented behaviour, and works as of React 16.x | |
- Any HTML rendered within this <div /> will not be wiped by React | |
- For example, an advert provider can output markup to this container without React removing on re-render | |
*/ | |
function ReactThirdParty() { | |
return ( | |
<div | |
dangerouslySetInnerHTML={{ __html: '' }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const query = `#graphql | |
query getSubscriptions($email: String!) { | |
Subscriptions( | |
where: { | |
StorefrontUser: { email: { _eq: $email } } | |
}, | |
order_by: { createdAt: desc } | |
) { | |
id | |
platformId |