Skip to content

Instantly share code, notes, and snippets.

View nathanclevenger's full-sized avatar
πŸš€

Nathan Clevenger nathanclevenger

πŸš€
View GitHub Profile
@khalidx
khalidx / node-typescript-esm.md
Last active April 15, 2025 14:15
A Node + TypeScript + ts-node + ESM experience that works.

The experience of using Node.JS with TypeScript, ts-node, and ESM is horrible.

There are countless guides of how to integrate them, but none of them seem to work.

Here's what worked for me.

Just add the following files and run npm run dev. You'll be good to go!

package.json

@SomeHats
SomeHats / runDevBrowser.mjs
Last active February 26, 2025 16:13
A hacky local version of cloudflare's browser rendering API. To use this, copy either runDevBrowser.ts or runDevBrowser.mjs and install the puppeteer and ws packages from npm. Run the dev server alongside wranger with `node runDevServer.mjs` or `tsx runDevServer.ts`
/* eslint-disable no-console */
/***
* This is a little server that emulates the protocol used by cloudflare's browser rendering API. In
* local development, you can run this server, and connect to it instead of cloudflare's (strictly
* limited) API. e.g. in your worker you might use a function like this:
*
* ```ts
* import { Browser, launch as launchPuppeteer } from '@cloudflare/puppeteer'
* function launchBrowser(env: Environment) {
* if (env.LOCAL_BROWSER_ORIGIN) {
@DrMint
DrMint / ExampleCollection.ts
Last active April 8, 2025 06:59
Grid View for Payload Uploads Collections
import { CollectionConfig } from "payload/types";
import { UploadsGridView } from "../../components/UploadsGridView/UploadsGridView";
export const Media: CollectionConfig = {
slug: "media",
admin: {
components: { views: { List: UploadsGridView } } // Set the List view to use the Grid view,
},
upload: {
staticURL: "/media",
@paulpopus
paulpopus / middleware.ts
Created August 11, 2023 07:26
Nextjs Middleware for Payload authentication to redirect users based on authentication
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { CheckUserDocument } from '@/graphql/generated/client'
import { CheckUserQuery } from '@/graphql/generated/client'
/* Redirect away from these routes if not authenticated */
const protectedRoutes = ['/profile', '/search']
/* Redirect away from these routes if authenticated */
const publicRoutes = ['/login', '/register']
@nathanclevenger
nathanclevenger / github-proxy-client.js
Created February 19, 2023 19:41 — forked from DavidWells/github-proxy-client.js
Full Github REST api in 34 lines of code
/* Ultra lightweight Github REST Client */
// original inspiration via https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const token = 'github-token-here'
const githubClient = generateAPI('https://api.github.com', {
headers: {
'User-Agent': 'xyz',
'Authorization': `bearer ${token}`
}
})
@stefandanaita
stefandanaita / cf-logpush-destination-worker.ts
Last active January 7, 2023 19:26
Code for a worker that can receive logpush http requests and parse the contents using streams
// SPDX-License-Identifier: MIT-0
export interface Env {
}
export default {
async fetch(
request: Request,
env: Env,
@DavidWells
DavidWells / github-proxy-client.js
Last active March 3, 2025 17:47
Full Github REST api in 34 lines of code
/* Ultra lightweight Github REST Client */
// original inspiration via https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const token = 'github-token-here'
const githubClient = generateAPI('https://api.github.com', {
headers: {
'User-Agent': 'xyz',
'Authorization': `bearer ${token}`
}
})
@MichaelCurrin
MichaelCurrin / README.md
Last active March 28, 2025 00:35
Jekyll - how to build a REST API

Jekyll - how to build a REST API

Serve your data as static JSON

How to make a read-only JSON REST API using Jekyll.

This doesn't need any Ruby plugins - you just use some built-in templating features in Jekyll 3 or 4.

You will end up with a single JSON file contains data for all pages on the site, and another JSON file of just posts. Alternatively, you can replace every HTML page and post with a JSON version.

@stickfigure
stickfigure / cloak.js
Created May 24, 2020 05:42
Cloudflare worker that proxies encrypted urls
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const SECRET_KEY_DATA = encoder.encode('YOUR SECRET KEY');
function normalizeBase64(base64urlencoded) {
return base64urlencoded.replace(/-/g, '+').replace(/_/g, '/');
@AnandChowdhary
AnandChowdhary / πŸ“Š Weekly development breakdown
Last active February 23, 2024 18:31
πŸ“Š Weekly development breakdown
TypeScript 13 hrs 7 mins β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Žβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 48.9%
Svelte 7 hrs 29 mins β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Šβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 27.9%
YAML 1 hr 45 mins β–ˆβ–Žβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 6.5%
JSON 1 hr 12 mins β–‰β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 4.5%
Markdown 1 hr 6 mins β–Šβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 4.1%