Skip to content

Instantly share code, notes, and snippets.

View timc1's full-sized avatar

Tim timc1

View GitHub Profile
This file has been truncated, but you can view the full file.
A
A'isha
A-jay
Aa
Aab
Aaban
Aaberg
Aabid
Aabidah
import { loadCommunity } from "@lib/loadCommunity.server";
import { ImageResponse } from "@vercel/og";
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest, { params }: { params: { slug: string; size: string } }) {
const community = await loadCommunity(params.slug);
if (!community || !community.icon_url) {
return NextResponse.json(
{ message: "Not found" },
{
"theme_color": "#055b49",
"background_color": "#055b49",
"display": "standalone",
"scope": "/",
"orientation": "any",
"start_url": "/?utm_medium=PWA&utm_source=launcher",
"name": "NutriFlex",
"short_name": "NutriFlex",
"icons": [
@timc1
timc1 / item.tsx
Last active May 25, 2022 13:36
very fast rendering of large lists, without windowing/virtualization
import { useIsomorphicEffect } from "@hooks/useIsomorphicEffect";
import React from "react";
const cache: Map<string, { height: number }> = new Map();
/**
* Very fast rendering of large lists, without windowing/virtualization
*
* Wrap any list item with `<Item><MyListItem /></Item` and we
* will ensure that only what appears within the viewport is what
@timc1
timc1 / cache.ts
Last active October 28, 2020 01:23
simple s3 cache for time sensitive bucket access
type Cache = {
[k: string]: string;
};
function cache() {
const _cache: Cache = {};
const cache = {
get: (key: string) => {
const cachedUrl = _cache[key];
/**
* @author qiao / https://github.com/qiao
* @author mrdoob / http://mrdoob.com
* @author alteredq / http://alteredqualia.com/
* @author WestLangley / http://github.com/WestLangley
* @author erich666 / http://erichaines.com
*/
// This set of controls performs orbiting, dollying (zooming), and panning.
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
{
"type":"doc",
"content":[
{
"type":"heading",
"attrs":{
"level":1
},
"content":[
{
@timc1
timc1 / getDelayFromNetworkSpeed.ts
Last active March 15, 2022 08:13
Control the speed at which your loading state shows up depending on the user's internet speed.
const defaultDelay = 500;
export default function getDelay(): number {
if (typeof window !== "undefined") {
if (window.navigator && window.navigator.connection) {
const connection = window.navigator.connection.effectiveType;
switch (connection) {
case "4g":
return defaultDelay;
case "3g":
@timc1
timc1 / useTheme2.tsx
Created April 18, 2020 20:10
🌑☀️core app system/light/dark mode theming + varying themes for nested components
import * as React from "react";
type ThemeConfig = "system" | "light" | "dark";
type ThemeName = "light" | "dark";
// Custom themes are keyed by a unique id.
type KeyedThemes = {
[k: string]: {
config: ThemeConfig;
themeName: ThemeName;
};
@timc1
timc1 / useTheme.tsx
Created April 16, 2020 01:21
🌑☀️mode theming hook
import * as React from "react";
type Theme = "system" | "light" | "dark";
const STORAGE_KEY = "theme";
const VALID_THEMES: Theme[] = ["system", "light", "dark"];
const DARK_MODE_MEDIA_QUERY = "(prefers-color-scheme: dark)";
function getAppTheme(): Theme {
if (typeof window !== "undefined") {