Skip to content

Instantly share code, notes, and snippets.

Avatar

Dave Stockley magicspon

View GitHub Profile
@magicspon
magicspon / index.tsx
Last active Sep 14, 2021
nextAuth/Craft/codegen usage
View index.tsx
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 May 21, 2021 — forked from jorgemasta/sso-login.ts
SSO Login to BigCommerce using a (Next) API Route
View sso-login.ts
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,
View machine.js
const playerMachine = {
id: "player",
initial: "waiting",
states: {
waiting: {
on: {
PLAY: "playing",
},
},
View machine.js
const waiting = {
on: {
BET: "playing",
RAISE: "betting",
},
}
const playing = {
on: {
FOLD: "folded",
CHECK: "waiting",
@magicspon
magicspon / server.js
Created Nov 7, 2018
using https with next
View server.js
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 Mar 21, 2018
animation/transition end event prop
View animationEnd.js
export default (type = 'transition') => {
let types =
type === 'transition'
? {
OTransition: 'oTransitionEnd',
WebkitTransition: 'webkitTransitionEnd',
MozTransition: 'transitionend',
transition: 'transitionend'
}
: {
@magicspon
magicspon / webpack.config.js
Created Jan 19, 2018
Webpack config - common chunks outputting arrow functions in generated js
View webpack.config.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
View fractal.js
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')({
@magicspon
magicspon / rows.js
Last active Mar 20, 2017
Vue... split content into rows based on screen width
View rows.js
/*eslint no-unused-vars: ["warn", { "argsIgnorePattern": "h" }]*/
import Vue from 'vue'
import Viewport from '../helpers/viewport'
import axios from 'axios'
import chunk from 'lodash.chunk'
const fetchTeam = () => {
const response = response || axios.get('/team.json')
return response
@magicspon
magicspon / examples.js
Created Feb 10, 2017
esbeautify issues
View examples.js
/*
BEFORE
*/
import React, { Component } from 'react'
export const Icon = props => (
<div className={`icon icon--${props.icon}`}>
<svg>