Skip to content

Instantly share code, notes, and snippets.

View angeloashmore's full-sized avatar

Angelo Ashmore angeloashmore

View GitHub Profile
@angeloashmore
angeloashmore / data.json
Last active February 9, 2024 19:55
Prismic integration field mock endpoint
{
"results_size": 1,
"results": [
{
"id": "1",
"title": "Item Title",
"description" : "Description of the item.",
"image_url" : "https://images.unsplash.com/photo-1577401239170-897942555fb3?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1600&q=80",
"last_update" : 1509364426938,
"blob": {
#!/usr/bin/env node
const { createSliceMachineManager } = require("@slicemachine/manager");
/**
* @param {import("@slicemachine/manager").SliceMachineManager} manager
*/
async function loginIfNecessary(manager) {
const isLoggedIn = await manager.user.checkIsLoggedIn();
@angeloashmore
angeloashmore / encodeFormData.ts
Created December 14, 2022 21:42
Encode FormData in preparation for a network request.
/**
* The following code is a modified version of the following sources:
*
* 1. `formDataToBlob()` from `jimmywarting/FormData` on GitHub
*
* Source:
* https://github.com/jimmywarting/FormData/blob/820421ba9ee291cbf6b1b21aaa14ae1846d7c66c/formdata-to-blob.js
*
* MIT License
*
@angeloashmore
angeloashmore / OmitNested.ts
Created December 7, 2022 04:04
`OmitNested` - A TypeScript type that omits nested object properties using dot notion.
type AppendDotPathSegment<
TPath extends string,
TSegment extends string,
> = TPath extends "" ? TSegment : `${TPath}.${TSegment}`;
type AnyFunction = (...args: any[]) => any;
type Primitives =
| boolean
| string
| number
@angeloashmore
angeloashmore / example-page.tsx
Last active September 1, 2022 20:14
An example Next.js page file written in TypeScript.
// src/pages/index.tsx
import type { InferGetStaticPropsType, GetStaticPropsContext } from 'next'
// PageProps is typed using the inferred return type from `getStaticProps()`.
type PageProps = InferGetStaticPropsType<typeof getStaticProps>
export default function Page({ fetchedData }: PageProps) {
// `fetchedData` is typed as the return value of `client.someAPI()`.
}
@angeloashmore
angeloashmore / prismic-custom-type-model-with-singleton-field.ts
Created June 30, 2021 21:26
Takes a record of fields and ensures only one instance of a field value type exists.
// Takes a record of fields and ensures only one instance of a field value type exists.
// See: @prismicio/types
type WithSingletonField<
Fields extends Record<string, CustomTypeField>,
FieldType extends CustomTypeField,
FieldName extends string,
> = {
[P in keyof Fields as Fields[P] extends FieldType
? P extends FieldName
@angeloashmore
angeloashmore / shell.nix
Last active April 20, 2021 00:30
Node.js Nix shell file
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "node";
buildInputs = [
yarn
nodejs-14_x
];
}
@angeloashmore
angeloashmore / improving-prismic-previews-dx.md
Last active May 8, 2020 08:30
Improving the developer experience when implementing Prismic Previews with gatsby-source-prismic.

Improving the Prismic Preview developer experience

gatsby-source-prismic v3 introduced a client-side preview system that integrates with Prismic's REST API via prismic-javascript.

The core APIs powering previews is the new usePrismicPreview hook and mergePrismicPreviewData utility function. Under the hood, usePrismicPreview fetches preview data and runs it through the same data transformers used in the source plugin at build-time.

@angeloashmore
angeloashmore / package.json
Created December 3, 2019 21:48
Temp Yarn workspace
{
"private": true,
"workspaces": {
"packages": [
"packages/*"
],
"nohoist": [
"**/husky",
"**/husky/**"
]
@angeloashmore
angeloashmore / Calendar.js
Created November 15, 2019 07:24
Render a calendar in React
import React, { useState, useMemo } from 'react'
import {
addMonths,
addWeeks,
format,
getTime,
getWeeksInMonth,
isSameMonth,
startOfMonth,
startOfWeek,