Skip to content

Instantly share code, notes, and snippets.

View jclem's full-sized avatar
🪄

Jonathan Clem jclem

🪄
View GitHub Profile
@jclem
jclem / bush.sh
Created January 6, 2023 16:07 — forked from brasic/bush.sh
homer bush
#!/bin/sh
set -euxo
cleanup() {
rm -f 1.mp4 2.mp4 3.mp4 4.mp4 palette.png
}
trap cleanup EXIT
# extend the last frame
import {PrismaAdapter} from '@next-auth/prisma-adapter'
import {PrismaClient} from '@prisma/client'
import NextAuth from 'next-auth'
import {Adapter, AdapterUser} from 'next-auth/adapters'
import {Provider} from 'next-auth/providers'
import GitHubProvider from 'next-auth/providers/github'
function PrismaAdapterAugmentation(
prisma: PrismaClient
): Pick<Adapter, 'createUser' | 'linkAccount'> {
@jclem
jclem / string-scanner.ts
Created October 20, 2021 18:35
string-scanner.ts
/**
* Scans over a string, character by character
*/
export default class StringScanner {
pos = 0
constructor(private readonly data: string) {}
/**
* Fetch the next character.
@jclem
jclem / README.md
Last active October 20, 2021 15:46

Notice the only compilation difference between the string-scanners is that the version in 4.4.4 declares data and pos = 0 in the class body itself. The compilation output for decode.ts is identical.

However, the benchmarks are significantly different:

logfmt2#decode3 x 1,246,767 ops/sec ±2.22% (83 runs sampled)
logfmt2#decode4 x 879,750 ops/sec ±1.68% (85 runs sampled)
@jclem
jclem / withQuery.tsx
Last active July 14, 2021 21:03
A Next.js getInitialProps wrapper
import localForage from 'localforage'
import {NextPage, NextPageContext} from 'next'
import {getDisplayName} from 'next/dist/next-server/lib/utils'
import {ComponentType} from 'react'
import {
hashQueryKey,
QueryFunction,
QueryKey,
useQuery,
UseQueryResult
#!/usr/bin/env python3
# From https://gist.github.com/FradSer/de1ca0989a9d615bd15dc6eaf712eb93#gistcomment-3649575
import asyncio
import iterm2
async def changeTheme(theme_parts, connection):
# Themes have space-delimited attributes, one of which will be light or dark.
if "dark" in theme_parts:
@jclem
jclem / Dockerfile
Last active January 28, 2019 21:25
Using a database in GitHub Actions
FROM debian
RUN apt-get update
RUN apt-get install -y supervisor
RUN apt-get install -y redis-server
RUN apt-get install -y netcat
COPY *.conf /etc/supervisor/conf.d/
COPY entrypoint.sh /entrypoint.sh
import { createRef, useState } from 'react';
export default ({src}) => {
const [showPrompt, setShowPrompt] = useState(true)
const videoRef = createRef()
const playVideo = () => {
setShowPrompt(false)
videoRef.current.play()
}
@jclem
jclem / week-of.js
Last active January 24, 2019 12:52
dateSubtract(
prop("Date"),
((toNumber(formatDate(prop("Date"), "d")) - 1) % 7 + 7) % 7,
"days"
)
const data = {
numbers: [1, 2, 3],
strings: ['a', 'b', 'c'],
notNumbers: 'Hello, world.'
}
deleteFromArray(data, 'numbers', num => num === 2)
function deleteFromArray<O, K extends keyof O, T>(
obj: O,