Skip to content

Instantly share code, notes, and snippets.

View magicspon's full-sized avatar
🤘

Dave Stockley magicspon

🤘
View GitHub Profile
@magicspon
magicspon / create-page.tsx
Created August 6, 2024 16:32 — forked from Pagebakers/create-page.tsx
Next.js createPage helper with loader pattern
import { AnyZodObject, z } from 'zod'
import { Metadata, ResolvingMetadata } from 'next'
type InferParams<Params> = Params extends readonly string[]
? {
[K in Params[number]]: string
}
: Params extends AnyZodObject
? z.infer<Params>
: unknown
@magicspon
magicspon / parseRichText.ts
Last active October 31, 2021 15:51
Next/Image from html string
import React from 'react'
import ReactDOMServer from 'react-dom/server'
import Image from 'next/image'
import Parse, {
HTMLReactParserOptions,
DOMNode,
Element,
} from 'html-react-parser'
const isElement = (domNode: DOMNode): domNode is Element => {
@magicspon
magicspon / index.tsx
Last active September 14, 2021 12:32
nextAuth/Craft/codegen usage
import * as React from 'react'
import { GetServerSideProps } from 'next'
import {
providers,
getSession,
csrfToken,
ClientSafeProvider,
} from 'next-auth/client'
import { getSdk } from '@schema/graphql'
import cmsClient from '@healthwave/utils/cms/graphqlClient'
@magicspon
magicspon / sso-login.ts
Last active April 20, 2023 09:19 — forked from jorgemasta/sso-login.ts
SSO Login to BigCommerce using a (Next) API Route
import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'
import jwt from 'jsonwebtoken';
import {v4 as uuidv4} from 'uuid';
import concatHeader from '../utils/concat-cookie'
import getConfig from '../utils/get-config'
function getSsoLoginUrl(customerId: number, storeHash: string, storeUrl: string, clientId: string, clientSecret: string) {
const dateCreated = Math.round((new Date()). getTime() / 1000);
const payload = {
"iss": clientId,
@magicspon
magicspon / machine.js
Last active April 26, 2020 21:24
Generated by XState Viz: https://xstate.js.org/viz
const playerMachine = {
id: "player",
initial: "waiting",
states: {
waiting: {
on: {
PLAY: "playing",
},
},
@magicspon
magicspon / machine.js
Created April 26, 2020 20:58
Generated by XState Viz: https://xstate.js.org/viz
const waiting = {
on: {
BET: "playing",
RAISE: "betting",
},
}
const playing = {
on: {
FOLD: "folded",
CHECK: "waiting",
@magicspon
magicspon / server.js
Created November 7, 2018 09:48
using https with next
const https = require('https')
const { parse } = require('url')
const next = require('next')
const fs = require('fs')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const options = {
@magicspon
magicspon / animationEnd.js
Last active March 21, 2018 00:27
animation/transition end event prop
export default (type = 'transition') => {
let types =
type === 'transition'
? {
OTransition: 'oTransitionEnd',
WebkitTransition: 'webkitTransitionEnd',
MozTransition: 'transitionend',
transition: 'transitionend'
}
: {
@magicspon
magicspon / webpack.config.js
Created January 19, 2018 10:44
Webpack config - common chunks outputting arrow functions in generated js
/* global */
const webpack = require('webpack')
const path = require('path')
const ProgressBarPlugin = require('progress-bar-webpack-plugin')
const querystring = require('querystring')
const { removeEmpty } = require('webpack-config-utils')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
let BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin
const fractal = require('@frctl/fractal').create()
const paths = {
build: PATH_CONFIG.build,
src: PATH_CONFIG.src,
static: PATH_CONFIG.static,
}
const stamp = global.production ? `.${TASK_CONFIG.stamp}` : ''
const mandelbrot = require('@frctl/mandelbrot')({