Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan Florence ryanflorence

View GitHub Profile
View index.tsx
import type { LoaderFunction, ActionFunction } from "remix";
import { useLoaderData, useFetcher } from "remix";
import invariant from "tiny-invariant";
import cuid from "cuid";
import React from "react";
import type { Task, User } from "@prisma/client";
import { requireAuthSession } from "~/util/magic-auth";
import { ensureUserAccount } from "~/util/account";
import { placeCaretAtEnd } from "~/components/range";
import { getBacklog } from "~/models/backlog";
View server.mjs
import { createServer } from "http";
createServer(async (req, res) => {
if (req.url === "/app.js") {
res.setHeader("Content-Type", "application/javascript; charset=UTF-8");
res.setHeader("Cache-Control", "max-age=10");
res.write(`console.log("lol")`);
res.end();
return;
}
View session-stuff.ts
// root.tsx
import { getUserSession, requireUser, logout } from "~/session";
export function loader({ request }) {
// use case: know if the user is logged in, no redirect to /login
let userSession = await getUserSession(request);
let isAuthenticated = userSession.has("userId");
return { isAuthenticated };
}
@ryanflorence
ryanflorence / Await.ts
Created Nov 12, 2021
Infer the return type of a promise.
View Await.ts
type Await<T extends (...args: any) => any> = T extends (
...args: any
) => Promise<infer U>
? U
: T extends (...args: any) => infer U
? U
: any;
async function load() {
View remix-magic-auth.tsx
import crypto from "crypto";
import { renderToStaticMarkup } from "react-dom/server";
import createMailgun from "mailgun-js";
import type { ActionFunction, LoaderFunction, Session } from "remix";
import { createCookieSessionStorage, json, redirect } from "remix";
/*******************************************************************************
* Before we can do anything, we need to make sure the environment has
* everything we need. If anything is missing, we just prevent the app from
* starting up.
View wakeboarding.md

Slow Speed, Short Rope

  • Surface 180s (Jet ski)
    • Push with back foot to release fins
    • upper body shouldn't really move
  • Surface 360s both TS/HS (jet ski)
    • lean against the line
    • sqaut to get good advance
    • pull with two hands
  • traveling
View machine.js
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
View session-storage.js
import { createCookieSessionStorage } from "remix";
let { getSession, commitSession, destroySession } = createCookieSessionStorage({
cookie: {
name: "__session",
secrets: ["r3m1xr0ck5"]
}
});
export { getSession, commitSession, destroySession };
View machine.js
const pageMachine = Machine({
id: 'pageTransition',
initial: 'idle',
context: {
location: '/',
nextLocation: null,
data: {},
forms: new Map(),
error: null
@ryanflorence
ryanflorence / fasdfas
Created Apr 23, 2021
Created from Remix Form!