Skip to content

Instantly share code, notes, and snippets.

View flybayer's full-sized avatar
🤓
CEO Flightcontrol + Pilot

Brandon Bayer flybayer

🤓
CEO Flightcontrol + Pilot
View GitHub Profile
@flybayer
flybayer / machine.js
Created November 27, 2019 04:56
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@flybayer
flybayer / machine.js
Created February 6, 2020 04:49
Generated by XState Viz: https://xstate.js.org/viz
const checkoutAppMachine = Machine(
{
id: "checkoutApp",
initial: "studentEntry",
strict: true,
context: {
currentStepNumber: 0,
account: {
authenticated: false,
},
const res = await fetch(action, {
method,
body: data,
headers: {
Accept: 'application/json',
},
})
@flybayer
flybayer / Link.tsx
Last active July 1, 2021 07:40
Much nicer and more intuitive Next.js Link abstraction
@flybayer
flybayer / env.ts
Created September 15, 2020 23:10
zod env validation
// config/env.ts
import assert from "utils/assert"
import * as z from "zod"
assert(typeof window === "undefined",
"The config/env.ts file cannot be used in the browser")
const isProduction = process.env.NODE_ENV === "production"
const isDevelopment = process.env.NODE_ENV === "development"
const isTest = process.env.NODE_ENV === "test"
import { SessionContext } from "blitz"
import db from "db"
import { authenticateUser, hashPassword } from "app/auth/auth-utils"
import * as z from "zod"
// --------------------------------------------
// PROTECT UTIL
type Ctx = { session: SessionContext }
type ProtectArgs<T> = { schema: T; authorize?: boolean }
@flybayer
flybayer / 1-BEFORE.ts
Last active January 27, 2021 23:37
Production Blitz.js Code Before & After New Pipe Utilities
// app/test-results/queries/getTestResult.ts
import { Ctx, NotFoundError } from "blitz"
import db, { Prisma, TestResult as TestResultBase } from "db"
import { ReportData } from "../types"
type GetTestResultInput = {
id: number
}
type TestResult = TestResultBase & {
@flybayer
flybayer / blitz-image-upload-rfc.md
Last active March 16, 2021 16:59 — forked from cstrnt/blitz-image-upload-rfc.md
[RFC] Add easy image uploads to Blitz

Problem

As of right now it's not trivial to upload images in Blitz. People either use external services like Cloudinary to handle this stuff. Creating your own solution includes knowledge in the fields of form parsing and some really low level libraries like busboy.

Solution

The goal is to create a hook which allows easy image uploads. There will also be a api route which takes care of the parsing part and then allows saving the file to the disk or uploading it a S3 etc. I'm the creator of imghop and I plan on using the same / similar api for this functionality. Example:

import crypto from "crypto"
import {assert} from "../utils"
export interface EncryptedString {
data: string
iv: string
}
export class Crypto {
static decrypt(text: string): string {
import { Controller, Get, Req, Res } from '@nestjs/common';
import { Request, Response } from 'express';
import { passportAuth } from "@blitzjs/auth"
const passportHandler = passportAuth({
successRedirectUrl: "/",
errorRedirectUrl: "/",
strategies: [
{
strategy: new PassportStrategy(), // Provide initialized passport strategy here