Skip to content

Instantly share code, notes, and snippets.

View kwhinnery's full-sized avatar

Kevin Whinnery kwhinnery

View GitHub Profile
@kwhinnery
kwhinnery / hono_decorators.ts
Created January 24, 2024 18:13
Example code from today's decorators presentation! Uses the older Stage 2 decorators API - look for the Stage 3 decorators API to release in Deno 1.40.
// deno-lint-ignore-file no-explicit-any
import { Hono } from "https://deno.land/x/hono@v3.12.0/mod.ts";
import { Context } from "https://deno.land/x/hono@v3.12.0/context.ts";
import * as dejs from "https://deno.land/x/dejs@0.10.3/mod.ts";
// Initialize class routes by instantiating a version of them
export function register(...args: any) {
args.forEach((C: any) => {
console.log("Mounting routes for", C.name);
new C();
@kwhinnery
kwhinnery / server.tsx
Created December 13, 2023 23:17
A Hono application, built for Deno, that uses OpenAI to generate images.
/** @jsx jsx */
import OpenAI from "https://deno.land/x/openai@v4.20.1/mod.ts";
import { Hono } from "https://deno.land/x/hono@v3.11.6/mod.ts";
import {
getCookie,
setCookie,
} from "https://deno.land/x/hono@v3.11.6/helper.ts";
import { jsx } from "https://deno.land/x/hono@v3.11.6/jsx/index.ts";
// Create OpenAI API client and Hono app
{"uuid":"91af22b0-9548-11ee-bd8a-f77d23459a43","page":{"id":216600679,"data":{"appState":"[\"~#iR\",[\"^ \",\"n\",\"appTemplate\",\"v\",[\"^ \",\"isFetching\",false,\"plugins\",[\"~#iOM\",[\"$main\",[\"^0\",[\"^ \",\"n\",\"pluginTemplate\",\"v\",[\"^ \",\"id\",\"$main\",\"uuid\",null,\"type\",\"frame\",\"subtype\",\"Frame\",\"namespace\",null,\"resourceName\",null,\"resourceDisplayName\",null,\"template\",[\"^3\",[\"type\",\"main\",\"sticky\",null,\"paddingType\",\"normal\",\"enableFullBleed\",false,\"isHiddenOnDesktop\",false,\"isHiddenOnMobile\",false]],\"style\",[\"^3\",[]],\"position2\",null,\"mobilePosition2\",null,\"mobileAppPosition\",null,\"tabIndex\",null,\"container\",\"\",\"createdAt\",\"~m1701984946485\",\"updatedAt\",\"~m1701984946485\",\"folder\",\"\",\"screen\",null]]],\"codeEditor\",[\"^0\",[\"^ \",\"n\",\"pluginTemplate\",\"v\",[\"^ \",\"id\",\"codeEditor\",\"^4\",\"39a68fb8-220c-4d42-be4b-e9a532d355bb\",\"^5\",\"widget\",\"^6\",\"CustomComponentWidget\",\"^7\",null,\"^8\",null,\"^9\",null,\"
@kwhinnery
kwhinnery / server.ts
Created August 3, 2023 19:35
A simple link shortener built with Deno. Run with `deno run --allow-net --unstable server.ts`
const kv = await Deno.openKv();
Deno.serve(async (request: Request) => {
// Create short links
if (request.method == "POST") {
const body = await request.text();
const { slug, url } = JSON.parse(body);
const result = await kv.set(["links", slug], url);
return new Response(JSON.stringify(result));
@kwhinnery
kwhinnery / db.ts
Last active June 14, 2023 20:26
The beginnings of a link shortening service in Deno, using Deno KV and Oak. Live coded on 6/14 here - https://www.youtube.com/watch?v=XaZTGGnP6EU
const kv = await Deno.openKv();
export interface Link {
slug: string;
destination: string;
}
export async function getLink(
slug: string,
): Promise<Link | null> {
@kwhinnery
kwhinnery / server.tsx
Created June 2, 2023 16:12
A single file application in Deno, using JSX and TypeScript
/** @jsx h */
import { serve } from "https://deno.land/std@0.190.0/http/mod.ts";
import html, { h } from "https://deno.land/x/htm@0.2.0/mod.ts";
function Greeting({ name }) {
return <h1>Hello, {name}!</h1>;
}
function handler(_req: Request): Response {
return html({
{"uuid":"6d5c93ce-c7fe-11ed-9b8b-53fc17ea022d","page":{"id":140024616,"data":{"appState":"[\"~#iR\",[\"^ \",\"n\",\"appTemplate\",\"v\",[\"^ \",\"isFetching\",false,\"plugins\",[\"~#iOM\",[\"query1\",[\"^0\",[\"^ \",\"n\",\"pluginTemplate\",\"v\",[\"^ \",\"id\",\"query1\",\"type\",\"datasource\",\"subtype\",\"RESTQuery\",\"namespace\",null,\"resourceName\",\"c6476334-bcd2-4543-9b83-dc7f4bf51db5\",\"resourceDisplayName\",\"Sid's D&D API\",\"template\",[\"^3\",[\"queryRefreshTime\",\"\",\"paginationLimit\",\"\",\"body\",\"\",\"lastReceivedFromResourceAt\",null,\"queryDisabledMessage\",\"\",\"servedFromCache\",false,\"offlineUserQueryInputs\",\"\",\"successMessage\",\"\",\"queryDisabled\",\"\",\"playgroundQuerySaveId\",\"latest\",\"resourceNameOverride\",\"\",\"runWhenModelUpdates\",true,\"paginationPaginationField\",\"\",\"headers\",\"\",\"showFailureToaster\",true,\"paginationEnabled\",false,\"query\",\"monsters?challenge_rating={{numberInput1.value}}\",\"playgroundQueryUuid\",\"\",\"playgroundQueryId\",null,\
@kwhinnery
kwhinnery / characters.json
Created February 16, 2023 01:40
Example Retool Apps for Kevin's TTRPG talk at DeveloperWeek 2023
{"uuid":"87701b90-92b2-11ed-b072-13fe1ea2c3e2","page":{"id":128353720,"data":{"appState":"[\"~#iR\",[\"^ \",\"n\",\"appTemplate\",\"v\",[\"^ \",\"isFetching\",false,\"plugins\",[\"~#iOM\",[\"selectedCharacter\",[\"^0\",[\"^ \",\"n\",\"pluginTemplate\",\"v\",[\"^ \",\"id\",\"selectedCharacter\",\"type\",\"state\",\"subtype\",\"State\",\"namespace\",null,\"resourceName\",null,\"resourceDisplayName\",null,\"template\",[\"^3\",[\"_persistedValueGetter\",null,\"_persistedValueSetter\",null,\"persistValue\",false,\"persistedValueKey\",\"\",\"value\",\"null\"]],\"style\",null,\"position2\",null,\"mobilePosition2\",null,\"mobileAppPosition\",null,\"tabIndex\",null,\"container\",\"\",\"createdAt\",\"~m1673893610009\",\"updatedAt\",\"~m1673896563518\",\"folder\",\"state\",\"screen\",null]]],\"listCharacters\",[\"^0\",[\"^ \",\"n\",\"pluginTemplate\",\"v\",[\"^ \",\"id\",\"listCharacters\",\"^4\",\"datasource\",\"^5\",\"SqlQueryUnified\",\"^6\",null,\"^7\",\"579e96f7-980f-44e8-b2f4-688cd2da3660\",\"^8\",\"retool_db\",\"
@kwhinnery
kwhinnery / star-wars.json
Created December 19, 2022 22:10
Nine Star Wars Movies from the 12 Days of Retool
{"uuid":"23b73fd8-7fa8-11ed-a488-4bc5ba7c4a27","page":{"id":114516001,"data":{"appState":"[\"~#iR\",[\"^ \",\"n\",\"appTemplate\",\"v\",[\"^ \",\"isFetching\",false,\"plugins\",[\"~#iOM\",[\"onLoad\",[\"^0\",[\"^ \",\"n\",\"pluginTemplate\",\"v\",[\"^ \",\"id\",\"onLoad\",\"type\",\"datasource\",\"subtype\",\"JavascriptQuery\",\"namespace\",null,\"resourceName\",\"JavascriptQuery\",\"resourceDisplayName\",null,\"template\",[\"^3\",[\"queryRefreshTime\",\"\",\"lastReceivedFromResourceAt\",null,\"queryDisabledMessage\",\"\",\"servedFromCache\",false,\"successMessage\",\"\",\"queryDisabled\",\"\",\"playgroundQuerySaveId\",\"latest\",\"resourceNameOverride\",\"\",\"runWhenModelUpdates\",false,\"showFailureToaster\",true,\"query\",\"let userId = localStorage?.values?.starWarsMovieOrderId;\\n\\nif (!userId) {\\n // If this is a new user, set up an ID and allow the default rankings\\n userId = uuid.v4();\\n localStorage.setValue('starWarsMovieOrderId', userId);\\n}\\n\\nloadPreference.trigger();\\ncommunityPrefer
{"uuid":"b97f2584-7b03-11ed-8dd9-1b226bc2f288","page":{"id":113209081,"data":{"appState":"[\"~#iR\",[\"^ \",\"n\",\"appTemplate\",\"v\",[\"^ \",\"isFetching\",false,\"plugins\",[\"~#iOM\",[\"$main\",[\"^0\",[\"^ \",\"n\",\"pluginTemplate\",\"v\",[\"^ \",\"id\",\"$main\",\"type\",\"frame\",\"subtype\",\"Frame\",\"namespace\",null,\"resourceName\",null,\"resourceDisplayName\",null,\"template\",[\"^3\",[\"type\",\"main\",\"sticky\",false]],\"style\",[\"^3\",[]],\"position2\",null,\"mobilePosition2\",null,\"mobileAppPosition\",null,\"tabIndex\",null,\"container\",\"\",\"createdAt\",\"~m1670949145008\",\"updatedAt\",\"~m1670949145008\",\"folder\",\"\",\"screen\",null]]],\"sidebarFrame1\",[\"^0\",[\"^ \",\"n\",\"pluginTemplate\",\"v\",[\"^ \",\"id\",\"sidebarFrame1\",\"^4\",\"frame\",\"^5\",\"SidebarFrameWidget\",\"^6\",null,\"^7\",null,\"^8\",null,\"^9\",[\"^3\",[\"loading\",false,\"showFooter\",false,\"showHeader\",true,\"hidden\",false,\"isInEditMode\",false,\"isHiddenOnDesktop\",false,\"isHiddenOnMobile\",true]