Skip to content

Instantly share code, notes, and snippets.

@will-t-harris
will-t-harris / auth0-rule-shopify-multipass.js
Created January 29, 2024 19:54 — forked from drovani/auth0-rule-shopify-multipass.js
Auth0 Rule to Generate a Multipass token and redirect the user back to the Shopify store
function (user, context, callback) {
if (context.clientMetadata && context.clientMetadata.shopify_domain && context.clientMetadata.shopify_multipass_secret)
{
const RULE_NAME = 'shopify-multipasstoken';
const CLIENTNAME = context.clientName;
console.log(`${RULE_NAME} started by ${CLIENTNAME}`);
const now = (new Date()).toISOString();
let shopifyToken = {
email: user.email,
@will-t-harris
will-t-harris / api.ts
Created May 17, 2023 23:49 — forked from JaysonChiang/api.ts
Example of Axios with TypeScript
import axios, { AxiosError, AxiosResponse } from 'axios';
import token from './somewhere';
interface Todo {
id: string;
title: string;
}
interface User {
id: string;
@will-t-harris
will-t-harris / useMediaQuery.js
Created October 30, 2020 07:40
React useMediaQuery
/** Takes a media query and returns a boolean value for whether or not specified media query was hit.
* -- e.g. '(min-width: 567px)'
*/
export const useMediaQuery = (query: string): boolean => {
const mediaMatch: MediaQueryList = window.matchMedia(query);
const [matches, setMatches] = useState<boolean>(mediaMatch.matches);
useEffect(() => {
const handler = e => setMatches(e.matches);
mediaMatch.addEventListener('change', handler);
@will-t-harris
will-t-harris / useTimeout.js
Created October 30, 2020 07:39
React useTimeout
/** Takes a callback and a delay, and deals with clearing timeouts as the callback value changes */
export const useTimeout = (callback: () => void, delay: number | null) => {
// Hook found in this SO post
// https://stackoverflow.com/questions/53090432/react-hooks-right-way-to-clear-timeouts-and-intervals/53090848
const timeoutRef = useRef<number>(0);
const callbackRef = useRef<() => void>(callback);
// Remember the latest callback:
// Without this, if you change the callback, when setTimeout kicks in, it
// will still call your old callback.
@will-t-harris
will-t-harris / InstagramGallery.js
Last active June 6, 2020 06:36
useInstagramFeed
import React from "react"
import { useInstagramFeed } from "../useInstagramFeed"
const InstagramGallery = () => {
let photos = useInstagramFeed({
userId: "3468531814",
thumbnailWidth: 640,
photoCount: 12,
})
@will-t-harris
will-t-harris / ecdh.py
Created March 6, 2020 18:55 — forked from mrinalwadhwa/ecdh.py
Elliptic Curve Diffie-Hellman key exchange from scratch
#!/usr/bin/env python3
# The below code is an attemt to understand Elliptic Curve Cryptography
# by implementing Elliptic Curve Diffie-Hellman key exchange from scratch.
# DON'T USE THIS CODE IN YOUR APP!!
# It is not safe and is intended only as a learning tool.
import secrets