Skip to content

Instantly share code, notes, and snippets.

View reggi's full-sized avatar
🌺
Learning

Thomas Reggi reggi

🌺
Learning
View GitHub Profile
class Guard<T> {
constructor(public value: T) {}
isNotArray(): Guard<T extends any[] ? never : T> {
return Array.isArray(this.value) ? new Guard<never>(undefined as never) : this as unknown as Guard<T extends any[] ? never : T>;
}
isNotUndefined(): Guard<Exclude<T, undefined>> {
return this.value === undefined ? new Guard<never>(undefined as never) : this as unknown as Guard<Exclude<T, undefined>>;
}
isNotBoolean(): Guard<Exclude<T, boolean>> {
return typeof this.value === 'boolean' ? new Guard<never>(undefined as never) : this as unknown as Guard<Exclude<T, boolean>>;
export const reservedPathPatterns = [
new URLPattern({ pathname: '/favicon.ico' }),
new URLPattern({ pathname: '/robots.txt' }),
new URLPattern({ pathname: '/sitemap.xml' }),
new URLPattern({ pathname: '/ads.txt' }),
new URLPattern({ pathname: '/security.txt' }),
new URLPattern({ pathname: '/.well-known/*' }),
new URLPattern({ pathname: '/apple-touch-icon.png' }),
new URLPattern({ pathname: '/apple-touch-icon-:size1(\\d+)x:size2.png' }),
<template id="wc-simplemde-template">
<style>
@import 'https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css';
@import 'https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css';
:host {
--mainViewMenuHeight: 0
}
.wc-simplemde-container {
width: 50%;
/** @jsx h */
/** @jsxFrag Fragment */
import { VNode, h, Fragment } from "https://esm.sh/preact@10.13.2";
import { renderToString } from "https://esm.sh/preact-render-to-string@6.0.3?deps=preact@10.13.2";
import { serve } from "https://deno.land/std@0.184.0/http/server.ts";
class Next {}
type Route = (req: Request) => Promise<Next | Response>
@reggi
reggi / register.sh
Last active January 22, 2023 21:53
SELF="${0}"
function green () {
START="\033[0;32m"
END="\033[0m"
echo -e "${START}${1}${END}"
}
USAGE=""
declare -gA USAGE_REGISTRY
#!/bin/bash
# shellcheck disable=SC2034
USAGE="<word>"
# shellcheck disable=SC2034
DESC="converts hyphens to underscore"
main () {
echo "$1" | tr '-' '_'
}
class Route {
urlPattern: URLPattern
constructor (
public method: string,
public pathname: string,
public handler: (req: Request) => Promise<Response> | Response
) {
this.urlPattern = new URLPattern({ pathname })
}
}
import { serve } from "https://deno.land/std@0.161.0/http/server.ts";
import * as path from 'https://deno.land/std@0.163.0/path/mod.ts'
import { parse } from "https://deno.land/std@0.161.0/encoding/yaml.ts";
const cwd = Deno.cwd()
const results = `export const chungus = {
love: true,
meow: (v: string) => v
}`
import {clientImport} from '../main.ts'
const e = await clientImport(import.meta.url, "../examples/web_components/content_warning.ts")
console.log(e)
import { JSX, ComponentChild, VNode } from "https://esm.sh/v96/preact@10.11.2"
import render from 'preact-render-to-string'
// you need a way to ignore the type error for an async component
const asyncComponent = (component: (props: any) => Promise<JSX.Element>): (props: any) => JSX.Element => {
return component as any
}
const Alice = asyncComponent(async (props: { children: ComponentChild}) => {
const x = await Promise.resolve('Alice')