Skip to content

Instantly share code, notes, and snippets.

View iDVB's full-sized avatar
💭
Work'n

Dan Van Brunt iDVB

💭
Work'n
View GitHub Profile
@iDVB
iDVB / ScrollRestoration.js
Created August 27, 2024 15:07
Custom NextJS ScrollRestoration with async triggerRestore
import React, { createContext, useContext, useEffect, useRef } from 'react'
import Head from 'next/head'
import Router from 'next/router'
const ScrollRestorationContext = createContext(null)
export const useScrollRestoration = ({ router, ignorePattern: optsIgnorePattern }) => {
const shouldScrollRestore = useRef(true)
import middy from '@middy/core'
import ssm from '@middy/ssm'
import { ApolloServer } from 'apollo-server-lambda'
import { makeExecutableSchema, mergeSchemas } from '@graphql-tools/schema'
import {
introspectSchema,
wrapSchema,
TransformObjectFields,
FieldNodeTransformer,
} from '@graphql-tools/wrap'
@iDVB
iDVB / graphql.ts
Last active October 20, 2021 20:13
Apollo Proxy for Remote Schema
import { Handler } from 'aws-lambda'
import { ApolloServer } from 'apollo-server-lambda'
import { makeExecutableSchema, mergeSchemas } from '@graphql-tools/schema'
import { introspectSchema, wrapSchema } from '@graphql-tools/wrap'
import { AsyncExecutor } from '@graphql-tools/utils'
import { fetch } from 'cross-fetch'
import { printSchema, print } from 'graphql'
const { CONTENTFUL_CDA, CONTENTFUL_SPACE } = process.env
import * as sst from '@serverless-stack/resources'
import * as iam from '@aws-cdk/aws-iam'
import * as apigw from '@aws-cdk/aws-apigatewayv2'
export default class MyStack extends sst.Stack {
constructor(scope: sst.App, id: string, props?: sst.StackProps) {
super(scope, id, props)
const { account, region } = scope
@iDVB
iDVB / StaticSite.ts
Created June 17, 2021 16:15
Gatsby Cache-Control in CDK
const deployment1 = new s3deploy.BucketDeployment(this, 'BucketDeployment1', {
sources: [
s3deploy.Source.asset(props.siteAssetsPath, {
ignoreMode: cdk.IgnoreMode.GIT,
exclude: ['*.*', '!*.js', '!*.css', 'sw.js', '!static/**', '_redirects'],
}),
],
memoryLimit: 512,
cacheControl: [s3deploy.CacheControl.fromString('public,max-age=31536000,immutable')],
destinationBucket: primaryBucket,
@iDVB
iDVB / index.js
Created May 6, 2021 16:09
Cypress Recursive Request
const reqHSContactByEmail = async (email, retryNum = 0) => {
expect(retryNum).to.be.lessThan(10)
return cy
.request({
url: `${HUBSPOT_CONTACT_API(email)}?hapikey=${Cypress.env(
'HUBSPOT_API_KEY'
)}`,
failOnStatusCode: false,
})
.then((resp) => {
@iDVB
iDVB / automation
Last active April 10, 2021 03:47
automation
# From:
- service: ozw.set_config_parameter
data:
node_id: 23
parameter: 14
value: Red
# To:
- service: zwave_js.set_config_parameter
target:
@iDVB
iDVB / _redirects
Created April 24, 2020 17:15
DIY Netlify _redirects
# Place this file in the route of your S3 bucket
# https://www.npmjs.com/package/middy-reroute
# Redirect with 301
/home /
/google https://www.google.com
# Redirect with 302
/my-redirect / 302
@iDVB
iDVB / useScrollSpy.js
Created April 21, 2020 19:23
useScrollSpy similar to MUI docs https://bit.ly/3cArBBr
import { useState, useEffect, useRef, useCallback } from 'react';
import useThrottledOnScroll from './useThrottledOnScroll';
const useScrollSpy = ({ items = [], target = window } = {}) => {
const itemsWithNodeRef = useRef([]);
useEffect(() => {
itemsWithNodeRef.current = getItemsClient(items);
}, [items]);
const [activeState, setActiveState] = useState(null);
@iDVB
iDVB / template.yaml
Created August 5, 2019 17:36
Dynamically named S3 Bucket Trigger
Transform: AWS::Serverless-2016-10-31
Resources:
Lambda:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs8.10
InlineCode: |
exports.handler = (event, ctx, cb) => {
console.log(JSON.stringify(event));