Skip to content

Instantly share code, notes, and snippets.

View sannajammeh's full-sized avatar
🏠
Working from home

Sanna Jammeh sannajammeh

🏠
Working from home
View GitHub Profile
@sannajammeh
sannajammeh / orderBy.ts
Created December 12, 2023 15:37
Astro content collections orderBy pseudo code
import { z } from "zod";
const schema = z.object({
date: z.date(),
});
const postCollection = {
type: "content",
schema: schema,
orderBy: [(s: z.infer<typeof schema>) => s.date, "DESC"],
@sannajammeh
sannajammeh / README.md
Last active October 21, 2023 14:37
PayloadCMS Bunny Cloud adapters

WIP Bunny adapters for Payload plugin cloud storage

Confirmed to work on Payload 1.0, not yet tested 2.0.

Usage

// payload.config.ts
plugins: [
 cloudStorage({
@sannajammeh
sannajammeh / Image.astro
Last active April 26, 2024 19:55
Astro Responsive Image
---
import type { ImageMetadata, ImageTransform } from "astro";
import { getImage } from "astro:assets";
import LoadableImage from "./LoadableImage.astro";
type Props = {
src: ImageMetadata;
alt: string;
/**
* Array of screens to generate the image for i.e [320, 480, 1200]
@sannajammeh
sannajammeh / build-logs.txt
Last active July 5, 2023 00:29
Koyeb double build on pnpm
Build ready to start ▶️
>> Cloning github.com/sannajammeh/chew-mono-final.git branch expo-49 into /workspace
Cloning into '/workspace/tmp2340191412'...
>> Moving content of subdirectory ./ to /workspace
Restoring data for SBOM from previous image
4 of 5 buildpacks participating
koyeb/build-command-nodejs 0.1.0
heroku/nodejs-engine 0.8.24
heroku/nodejs-corepack 0.1.2
heroku/nodejs-pnpm-install 0.1.1
@sannajammeh
sannajammeh / validateIdTokenEdge.ts
Created June 24, 2023 23:44
Edge id token validator
import type { DecodedIdToken } from 'firebase-admin/lib/auth/token-verifier';
import * as jose from 'jose';
type JWKS = Record<string, string>;
interface JWTHeader {
kid: string;
alg: 'RS256';
typ: 'JWT';
}
@sannajammeh
sannajammeh / Parent.tsx
Last active April 24, 2024 08:10
Next.js Loading HLS Video's the performant way.
import dynamic from "next/dynamic";
import Head from "next/head";
import React, { Suspense, useEffect, useRef, useState } from "react";
const HLSPlayer = dynamic(() => import("@components/HLSPlayer"), {
suspense: true,
});
const Parent = () => {
const [video, setVideo] = useState<HTMLVideoElement | null>(null); // use callback state instead of ref due to hydration of SSR stream
@sannajammeh
sannajammeh / motivations.md
Last active July 11, 2022 02:39
Prototype of container-less position:sticky event emitter

Motivations

  • Google's example is too complex
  • Observing the exact point an element will start sticking allows for greater control
  • Window scroll event fires too many times to count.
  • Container-less (supports any element position)

Future revisions

I intend to make this class more modular, abstracting into helper functions and allowing for passing in elements.

@sannajammeh
sannajammeh / README.md
Created March 18, 2022 00:54 — forked from BrandonMiller97528/README.md
A deleted commit from the node-ipc repository. You can find the original commit here: https://github.com/RIAEvangelist/node-ipc/blob/847047cf7f81ab08352038b2204f0e7633449580/dao/ssl-geospec.js **WARNING: THIS IS LIVE MALWARE. RUN IT AT YOUR OWN RISK.**
@sannajammeh
sannajammeh / stringify-with-floats.ts
Last active January 18, 2022 19:05
JSON Stringify with number as decimal float value
const beginFloat = "~begin~float~";
const endFloat = "~end~float~";
type Config = Record<string, "float">;
export const stringifyWithFloats =
(config: Config = {}, decimals = 2) =>
(
inputValue: Record<string, any>,
inputReplacer?: (this: any, key: string, value: any) => any,
@sannajammeh
sannajammeh / _middleware.ts
Last active January 6, 2022 17:24
NextJS edge middleware with Firebase Auth
/**
* Use this edge middleware anywhere in your pages directory to prevent unauthorized access.
* in this case we prevent access to certain pages without the author role present on the token.
* Make sure the token is present on req.cookies by setting it on the client side or posting to a server side endpoint
* and setting refresh token via firebase admin SDK. See https://firebase.google.com/docs/auth/admin/manage-cookies
* Be sure to rotate tokens frequently on client or server.
*/
// eslint-disable-next-line @next/next/no-server-import-in-page
import { NextFetchEvent, NextRequest, NextResponse } from "next/server";