Skip to content

Instantly share code, notes, and snippets.

View giuseppeg's full-sized avatar
🌊
All is well.

Giuseppe giuseppeg

🌊
All is well.
View GitHub Profile
import { z } from "zod";
import { zodToTs, printNode } from "zod-to-ts";
// Replace with your `openai` thing
import { openai } from "../openai.server";
import endent from "endent";
function createJSONCompletion<T extends z.ZodType>({
prompt,
schema_name,
@jacob-ebey
jacob-ebey / upstash-session-storage.ts
Last active July 15, 2023 18:52
Remix Upstash Session Storage
import { type Agent } from "https";
import {
createSessionStorage,
type RequestInit,
type SessionData,
type SessionIdStorageStrategy,
} from "@remix-run/node";
export interface UpstashSessionStorageOptions {
cookie?: SessionIdStorageStrategy["cookie"];
@steveruizok
steveruizok / cache.ts
Last active March 31, 2023 14:43
weak map gist
export class Cache<T extends object, K> {
items = new WeakMap<T, K>()
get<P extends T>(item: P, cb: (item: P) => K) {
if (!this.items.has(item)) {
this.items.set(item, cb(item))
}
return this.items.get(item)!
}
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.
@sergiodxa
sergiodxa / remix-auth.ts
Created July 21, 2021 23:25
Remix authentication library usage example
// create a session storage instance
let sessionStorage = createCookieSessionStorage();
// create authenticator instance
let authenticator = new Authenticator<User>(
sessionStorage
);
// configure the authenticator to use the Auth0 strategy for sign-in
authenticator.use(
@jaredpalmer
jaredpalmer / MarkdownPage.tsx
Created February 17, 2021 13:52
Get headers from MDX in Next.js
import {MDXProvider} from '@mdx-js/react';
import {MDXComponents} from 'components/MDX/MDXComponents';
import {Toc} from 'components/Toc/Toc';
import * as React from 'react';
export interface MarkdownProps<Frontmatter> {
meta: Frontmatter;
children?: React.ReactNode;
}
# test directories
__tests__
^(?!@serverless/enterprise-plugin/).*test.*$ # fix for serverless-enterprise
tests
powered-test
*.test.js
*.tap.js
*.test.ts
*tests.html

See current development here.

This document proposes a new resource batch file format, together with a concept of preloading resource batches on the Web. This proposal is derived from Web Bundles by Jeffrey Yasskin and dynamic bundle serving by Yoav Weiss, with significant input from Pete Snyder, who raised concerns about Web Bundles.

Resource Batch Preloading

When loading subresources on the Web, developers currently have an unfortunate choice between serving resources individually, or using bundlers, both of which have disadvantages which hurt loading performance. This document proposes a new mechanism, "resource batch preloading", which allows subresources to be loaded

@nicolo-ribaudo
nicolo-ribaudo / function.cjs
Created October 6, 2020 20:20
Synchronize async functions
"use strict";
const synchronize = require("./synchronize.cjs");
synchronize.export({
async getMyObj(value) {
await new Promise((resolve) => setTimeout(resolve, 2000));
return { foo: value * 3 };
}
});
if (!Element.prototype.getInnerHTML) {
Element.prototype.getInnerHTML = function(opts) {
var html = this.innerHTML;
if (!opts || !opts.includeShadowRoots) return html;
var m = new (self.WeakMap || Map)();
for (var c of (opts.closedRoots || [])) m.set(c.host, c);
var p = [];
function walk(node) {
var c, shadow = node.shadowRoot || m.get(node);
if (shadow) p.push(node.innerHTML, `<template shadowroot="${shadow.mode}">${shadow.innerHTML}</template>`);