Skip to content

Instantly share code, notes, and snippets.

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

James Hill jahilldev

⏱️
Perf.
View GitHub Profile
<link rel="stylesheet" href="/apps/invites/checkout-snippet.css">
<script src="/apps/invites/checkout-snippet.js" crossorigin="anonymous"></script>
<!-- sovendus code begin -->
<div style="margin-top: 30px" id="sovendus-container-1"></div>
<script type="text/javascript">
const sovendusIdsByCountry = {
GB: {
trafficSourceNumber: "7473",
@jahilldev
jahilldev / skio-api-query.ts
Created September 5, 2024 15:50
Example Skio API Request (Hangs, Timeout)
const query = `#graphql
query getSubscriptions($email: String!) {
Subscriptions(
where: {
StorefrontUser: { email: { _eq: $email } }
},
order_by: { createdAt: desc }
) {
id
platformId
@jahilldev
jahilldev / react-component-for-external-markup.jsx
Created August 29, 2024 20:09
React Third Party - Component to render container for third party rendered HTML markup
/**
- 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: '' }}
@jahilldev
jahilldev / try.ts
Created August 16, 2024 22:40 — forked from asleepace/try.ts
A simple extension for TypeScript which enables the `.try(args)` method on functions. This works for both normal & async functions, and reduces a lot of boilerplate.
// 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
{"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;