Skip to content

Instantly share code, notes, and snippets.

View zackdotcomputer's full-sized avatar
🔨
Building

Zack Sheppard zackdotcomputer

🔨
Building
View GitHub Profile
@zackdotcomputer
zackdotcomputer / App.tsx
Created March 21, 2022 12:55
Fix Clerk Unmount on Reauth
import { AuthProvider, useAuth } from "@redwoodjs/auth";
import { ClerkProvider, useClerk, useUser as useClerkUser } from "@clerk/clerk-react";
import { FatalErrorBoundary, RedwoodProvider } from "@redwoodjs/web";
import { RedwoodApolloProvider } from "@redwoodjs/web/apollo";
import FatalErrorPage from "src/pages/FatalErrorPage";
import Routes from "src/Routes";
import "./index.css";
import { navigate } from "@redwoodjs/router";
@zackdotcomputer
zackdotcomputer / FirebaseAuth.tsx
Created February 27, 2021 18:19
Next.js compatible Firebase Auth Button
/**
* This is a rewrite of the firebase/firebaseui-web-react auth button
* so that it supports Next.js's requirement that no css be imported
* in the node_modules directory. Instead, you should use this component
* and make sure that you add this import to your page file:
* > import "<path to>/node_modules/firebaseui/dist/firebaseui.css";
*
* This rewrite was done by Zack Sheppard (@zackdotcomputer) in Feb 2021.
* It is relicensed under Google's Apache 2 License below.
*/
@zackdotcomputer
zackdotcomputer / LinkTo.tsx
Last active August 27, 2022 15:43
Workaround for next/link vs <a> href accessibility lint issue
// Created by Zack Sheppard (@zackdotcomputer) on 1/19/2021
// Freely available under MIT License
// Workaround for https://github.com/vercel/next.js/issues/5533
import Link, { LinkProps } from "next/link";
import { AnchorHTMLAttributes, PropsWithChildren } from "react";
type PropTypes = LinkProps & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href">;
/// A unified component for the next/link <Link> and a standard <a> anchor.
@zackdotcomputer
zackdotcomputer / Decodable+Graceful.swift
Created September 28, 2020 13:19
Graceful Decoding for Swift Decodable
//
// Decodable+Graceful.swift
// Graceful Decodable
//
// Created by Zack Sheppard on 9/10/20.
// Copyright © 2020 Zack Sheppard. All rights reserved.
// Available under the MIT License
// Available at https://gist.github.com/zackdotcomputer/81b8545e3ce81128a299996814823963
//
@zackdotcomputer
zackdotcomputer / ShrinkingTableCell.swift
Last active September 7, 2020 21:45
A table view cell that shrinks to avoid the top of the table
//
// ShrinkingTableCell.swift
// ShrinkingTableCell
//
// Created by Zack Sheppard on 9/2/20.
// Copyright © 2020 Zack Sheppard. All rights reserved.
// Available under the MIT License
// Available at https://gist.github.com/zackdotcomputer/d365bfa5cd7e4a38d45c078b09459da3
//
@zackdotcomputer
zackdotcomputer / String+IntRange.swift
Last active September 7, 2020 21:46
Range<Int> substring finder for Swift Strings - Unsafe but Simple
//
// String+CountableRange.swift
//
// Created by Zack Sheppard on 8/30/20.
// Copyright © 2020 Zack Sheppard. All rights reserved.
// Available under the MIT License
//
import Foundation
/// This extension is available at
@zackdotcomputer
zackdotcomputer / KeyboardAware.swift
Last active September 7, 2020 21:46
Make UIViewControllers automatically aware of the keyboard
//
// UIViewController+KeyboardAware.swift
//
// Created by Zack Sheppard.
// Copyright © 2020 Zack Sheppard. All rights reserved.
// Available under the MIT License
//
import UIKit
@zackdotcomputer
zackdotcomputer / Optional+Extension.swift
Last active September 7, 2020 21:46
More Monadical Optionals in Swift
// Copyright © 2020 Zack Sheppard. All rights reserved.
// Available under the MIT License
/// A few Sequence/Monad-like functions added to Optional
extension Optional {
/// Transform this optional into another type
@inlinable public func map<T>(_ transform: (Wrapped) throws -> T) rethrows -> T? {
if let inside = self {
return try transform(inside)
} else {
@zackdotcomputer
zackdotcomputer / index.tsx
Created May 7, 2020 16:49
Fixed index.tsx for reduced-context-bug - Wait until mounting
import React, { createContext, useContext, useEffect, useState } from "react";
import { useWindowSize } from "react-use";
const DisplayContext = createContext<"normal" | "compact">("normal");
export default function Parent() {
const { width } = useWindowSize();
const [windowSizeDisplayContext, setWindowSizeDisplayContext] = useState<
"normal" | "compact"
@zackdotcomputer
zackdotcomputer / index.tsx
Last active May 7, 2020 16:48
Fixed index.tsx for reduced-context-bug - Omitting Changed Nodes
import React, { createContext, useContext } from "react";
import { useWindowSize } from "react-use";
const DisplayContext = createContext<"normal" | "compact">("normal");
export default function Parent() {
const { width } = useWindowSize();
let windowSizeDisplayContext = undefined;
if (width !== Infinity) {