1export default async function(req: Request): Promise<Response> {
2 const response = await fetch("http://worldtimeapi.org/api/timezone/America/New_York")
3 const timeData = await response.json()
1import { OpenAI } from "https://esm.town/v/std/openai";
2export default async function(req: Request): Promise<Response> {
3 const openai = new OpenAI();
4 const stream = await openai.chat.completions.create({
37// });
38
39function parseResultSet<T>(row: ResultSet): T[] {
40 return row.rows.map((r) => Object.fromEntries(r.map((c, i) => [row.columns[i], c]))) as T[];
41}
51};
52
53function diffCircles(array1: Circle[], array2: Circle[]): Circle[] {
54 const changes: Circle[] = [];
55
74
75 const drag = (() => {
76 function dragstarted() {
77 d3.select(this).attr("stroke", "black");
78 }
79
80 function dragged(event, d) {
81 d3.select(this).raise().attr("cx", d.x = event.x).attr("cy", d.y = event.y);
82 }
83
84 function dragended() {
85 const x = d3.select(this).attr("cx");
86 const y = d3.select(this).attr("cy");
105 .call(drag)
106 .on("click", clicked);
107 function clicked(event, d) {
108 if (event.defaultPrevented) return; // dragged
109
1export default async function(req: Request): Promise<Response> {
2 if (req.method !== "POST") {
3 return new Response("Method not allowed", { status: 405 });
1export default async function(req: Request) {
2 const body = (await fetch("https://live.staticflickr.com/65535/53782948438_9b85e57a6c_o_d.png")).body
3 return new Response(body, {headers: {"Content-Type": "image/png"}});
13
14const clientCode = () => {
15 document.getElementById("input").addEventListener("submit", async function(event) {
16 event.preventDefault();
17
45 + `&assistantId=${input.getAttribute("data-assistant-id")}`,
46 );
47 eventSource.onmessage = function(event) {
48 console.log(event);
49 responseDiv.innerText += JSON.parse(event.data);
50 };
51
52 eventSource.onerror = function() {
53 eventSource.close();
54 };
9
10const clientCode = () => {
11 document.getElementById("input").addEventListener("submit", function(event) {
12 event.preventDefault();
13
33 + `&assistantId=${input.getAttribute("data-assistant-id")}`,
34 );
35 eventSource.onmessage = function(event) {
36 console.log(event);
37 responseDiv.innerText += JSON.parse(event.data);
38 };
39
40 eventSource.onerror = function() {
41 eventSource.close();
42 };
51
52 // Load and render GeoJSON data
53 d3.json("/nyc.geojson").then(function(data) {
54 svg.selectAll("path")
55 .data(data.features)
67 .attr("r", 5)
68 .attr("class", "link")
69 .on("click", function(event, d) {
70 showCamera(d.id);
71 })
72 .on("mouseover", function(event, d) {
73 d3.select(this).transition()
74 .duration(200)
77 d3.select(this).raise();
78 })
79 .on("mouseout", function(event, d) {
80 d3.select(this).transition()
81 .duration(200)
237
238 const source = new EventSource("/camera-text-stream/${c.req.param("id")}");
239 source.onopen = function(e) {
240 loadingInterval = setInterval(() => {
241 loadingBox.textContent = brailleChars[brailleChars.length - charIndex - 1] + ' streaming ' + brailleChars[charIndex];
243 }, 100);
244 }
245 source.onmessage = function(e) {
246 document.querySelector('pre').innerHTML = JSON.parse(e.data);
247 }
248 source.onerror = function(e) {
249 if (loadingInterval) clearInterval(loadingInterval);
250 loadingBox.textContent = 'Error';
1import { imageToAscii } from "https://esm.town/v/maxm/imageToAscii";
2
3export default async function(req: Request): Promise<Response> {
4 const { string, stringColor } = await imageToAscii(
5 "https://webcams.nyctmc.org/api/cameras/9fa5b0dd-e955-449e-97e1-9c53ad9c23a8/image",
26// Converted from: https://github.com/victorqribeiro/imgToAscii/blob/ca7e181b9bb9770798ed3a0d3dfeb344c60953f2/src/imgToAscii.js
27import { createCanvas, loadImage } from "https://deno.land/x/canvas@v1.4.1/mod.ts";
28export async function imageToAscii(src: string, maxWidth?: number) {
29 let string = "";
30 let stringColor = "";