Skip to content

Instantly share code, notes, and snippets.

Avatar
🌻

Thomas Reggi reggi

🌻
View GitHub Profile
@reggi
reggi / register.sh
Last active January 22, 2023 21:53
View register.sh
SELF="${0}"
function green () {
START="\033[0;32m"
END="\033[0m"
echo -e "${START}${1}${END}"
}
USAGE=""
declare -gA USAGE_REGISTRY
View hyphen_to_underscore.fn.sh
#!/bin/bash
# shellcheck disable=SC2034
USAGE="<word>"
# shellcheck disable=SC2034
DESC="converts hyphens to underscore"
main () {
echo "$1" | tr '-' '_'
}
View route.ts
class Route {
urlPattern: URLPattern
constructor (
public method: string,
public pathname: string,
public handler: (req: Request) => Promise<Response> | Response
) {
this.urlPattern = new URLPattern({ pathname })
}
}
View deno-as-to-lang-server.ts
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
}`
View example.ts
import {clientImport} from '../main.ts'
const e = await clientImport(import.meta.url, "../examples/web_components/content_warning.ts")
console.log(e)
View async-server-components-preact.tsx
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')
View type-for-htmx-triggers.ts
export type ElementEvents =
"animationcancel" |
"animationend" |
"animationiteration" |
"animationstart" |
"afterscriptexecute" |
"auxclick" |
"beforescriptexecute" |
"blur" |
"click" |
View deno-fresh-composable.tsx
import { useContext } from 'preact/hooks';
import { createContext, Fragment, JSX } from 'preact';
import { HandlerContext, Handlers, PageProps } from "$fresh/server.ts";
const RequestContext = createContext(new Request('http://localhost:8000/'));
const useRequest = () => useContext(RequestContext);
export const passRequestHandler: Handlers<Request> = {
GET(request, ctx) {
View deno-fresh-htmx.ts
import { Plugin } from "$fresh/server.ts";
const sources = [
"https://raw.githubusercontent.com/bigskysoftware/htmx/dev/src/htmx.js",
"https://raw.githubusercontent.com/bigskysoftware/htmx/dev/src/ext/head-support.js"
]
export default function htmx(): Plugin {
const main = `data:application/javascript,${sources.map(s => `import "${s}";`).join('')} export default () => {}`
return {
@reggi
reggi / content-warning-web-component.markdown
Created September 1, 2022 21:11
Content Warning Web Component