glideImportDemomain.tsx2 matches
1// 1. Start by importing the Glide helper library.
2//
3// Soon, this functionality will be part of the official
4// @glideapps/tables npm package.
5import * as Glide from "https://esm.town/v/dvdsgl/glide?v=661";
18// For example, you could call an API in a loop, using yield for each
19// batch of rows to import.
20async function* getRows() {
21// Yield rows to import them:
22yield { name: "David", favoriteTool: "Glide" };
21export const layer = (info: GlideInfo) => Layer.succeed(Glide, Glide.of(info));
2223const getGlide: Effect.Effect<GlideInfo, GlideError> = Effect.gen(function*() {
24const provided = yield* Effect.serviceOption(Glide);
2537});
3839function removeUnsupportedColumnTypes(row: any): any {
40const pr = { ...row };
41for (const [k, v] of Object.entries(pr)) {
4950// Handles calling fetch, checking for API errors
51function fetchGlide<A>(
52method: "GET" | "POST" | "PUT",
53url: string,
54body: unknown,
55): Effect.Effect<A, GlideError> {
56return Effect.gen(function*() {
57const { token } = yield* getGlide;
58const result = yield* Effect.tryPromise(() =>
90rows: Stash | any[],
91): Effect.Effect<PutResult, GlideError> =>
92Effect.gen(function*() {
93// Some tables have a prefix, e.g. "native-table-" but this API
94// does not accept it.
118serial: string | number,
119): Effect.Effect<Stash, GlideError> =>
120Effect.gen(function*() {
121const id = typeof stash === "string" ? stash : stash.$stashID;
122136};
137138async function* bufferAsyncIterable<T>(
139asyncIterable: AsyncIterable<T | T[]>,
140max = 1_000,
152}
153154export function importTableEffect<Row>(props: Import<Row>) {
155const { table, getRows } = props;
156157return Effect.gen(function*() {
158yield* Effect.logDebug(`ingest start`);
159170let serial = 0;
171yield* Stream.runForEach(stream, (rows) =>
172Effect.gen(function*() {
173totalRows += rows.length;
174yield* Effect.logDebug(`ingest ${totalRows} total rows`);
181182// Runs an injestion job.
183export async function importTable<Row>(
184props: Import<Row> & { debug?: boolean },
185) {
azureCheetahmain.tsx14 matches
16import { renderToString } from "npm:react-dom/server";
1718export default function(
19{ tempValsParentFolderId }: { tempValsParentFolderId: string },
20) {
38the simplest way to achieve the goal, though you can add some inline comments to explain your
39reasoning (not for every line, but for major groups of lines). Don't use any environment variables
40unless strictly necessary, for example use APIs that don't require a key, prefer internal function
41imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
42functions where possible. Unless specified, don't add error handling,
43make sure that errors bubble up to the caller.
44Avoid external images or base64 images, use emojis, unicode symtols, or icon fonts/libraries instead, unless that's
51\`\`\`
52There should be no comments like "more content here", it should be complete and directly runnable.
53The val should create a "export default async function main" which is the main function that gets
54executed on every HTTP request.
55`.replace("\n", " ");
5657// Your response should start with \`\`\`ts and end with \`\`\`.
58// The val should create a "export default async function main() {" which
59// is the main function that gets executed, without any arguments. Don't return a Response object,
60// just return a plain Javascript object, array, or string.
6198const writer = writable.getWriter();
99const textEncoder = new TextEncoder();
100function write(text) {
101writer.write(textEncoder.encode(text));
102}
174</div>
175<script>
176function updateValName(valName) {
177const valUrl = valName ? \`https://val.town/v/${username}/\${valName}\` : "";
178const previewUrl = valName ? \`https://${username}-\${valName}.web.val.run\` : "";
182document.getElementById('open-link').href = previewUrl;
183}
184function saveVal() {
185if (window.codeMirrorEditor) {
186document.getElementById("save-icon").classList.remove("hidden");
202return false;
203})
204function openTab(tab) {
205const tabButtonCode = document.getElementById("tab-button-code");
206const tabButtonPreview = document.getElementById("tab-button-preview");
222}
223}
224function toggleTab() {
225openTab(document.getElementById("tab-panel-code").style.visibility === "visible" ? "preview" : "code");
226}
281(() => {
282const scrollingElement = document.getElementById("conversation-container");
283const callback = function (mutationsList, observer) {
284scrollingElement.scrollTo({ left: 0, top: scrollingElement.scrollHeight, behavior: "instant" });
285};
390window.setCodeMirrorContent({ doc: '', old: ''});
391let fullStr = "";
392window.addToken = function(str) {
393fullStr += str;
394const code = fullStr.replaceAll("\`\`\`ts\\n", "").replaceAll("\`\`\`", "").replace(/^ts\\n/, '');
429},
430);
431(async function() {
432try {
433await sleep(300);
16import { renderToString } from "npm:react-dom/server";
1718export default function(
19{ tempValsParentFolderId }: { tempValsParentFolderId: string },
20) {
38the simplest way to achieve the goal, though you can add some inline comments to explain your
39reasoning (not for every line, but for major groups of lines). Don't use any environment variables
40unless strictly necessary, for example use APIs that don't require a key, prefer internal function
41imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
42functions where possible. Unless specified, don't add error handling,
43make sure that errors bubble up to the caller.
44Avoid external images or base64 images, use emojis, unicode symtols, or icon fonts/libraries instead, unless that's
51\`\`\`
52There should be no comments like "more content here", it should be complete and directly runnable.
53The val should create a "export default async function main" which is the main function that gets
54executed on every HTTP request.
55`.replace("\n", " ");
5657// Your response should start with \`\`\`ts and end with \`\`\`.
58// The val should create a "export default async function main() {" which
59// is the main function that gets executed, without any arguments. Don't return a Response object,
60// just return a plain Javascript object, array, or string.
6198const writer = writable.getWriter();
99const textEncoder = new TextEncoder();
100function write(text) {
101writer.write(textEncoder.encode(text));
102}
174</div>
175<script>
176function updateValName(valName) {
177const valUrl = valName ? \`https://val.town/v/${username}/\${valName}\` : "";
178const previewUrl = valName ? \`https://${username}-\${valName}.web.val.run\` : "";
182document.getElementById('open-link').href = previewUrl;
183}
184function saveVal() {
185if (window.codeMirrorEditor) {
186document.getElementById("save-icon").classList.remove("hidden");
202return false;
203})
204function openTab(tab) {
205const tabButtonCode = document.getElementById("tab-button-code");
206const tabButtonPreview = document.getElementById("tab-button-preview");
222}
223}
224function toggleTab() {
225openTab(document.getElementById("tab-panel-code").style.visibility === "visible" ? "preview" : "code");
226}
281(() => {
282const scrollingElement = document.getElementById("conversation-container");
283const callback = function (mutationsList, observer) {
284scrollingElement.scrollTo({ left: 0, top: scrollingElement.scrollHeight, behavior: "instant" });
285};
390window.setCodeMirrorContent({ doc: '', old: ''});
391let fullStr = "";
392window.addToken = function(str) {
393fullStr += str;
394const code = fullStr.replaceAll("\`\`\`ts\\n", "").replaceAll("\`\`\`", "").replace(/^ts\\n/, '');
429},
430);
431(async function() {
432try {
433await sleep(300);
22The first timestamp should be 0.`;
2324async function processAudio(audio_uri) {
25const substrate = new Substrate({ apiKey: Deno.env.get("SUBSTRATE_API_KEY") });
26const opts = { cache_age: 60 * 60 * 24 * 7 };
9192// Render site
93export default async function(req: Request): Promise<Response> {
94const url = new URL(req.url);
95const audio_uri = url.searchParams.get("url");
400let currentChapterIndex = 0;
401402function updateText() {
403const currentTime = audioPlayer.currentTime;
404let segmentToDisplay = null;
515const updateInterval = 1000 / 40;
516517function updateLoop(timestamp) {
518if (timestamp - lastUpdateTime > updateInterval) {
519updateText();
httpValErrorCatchermain.tsx13 matches
6// Checks for minimum response size and presence of <html> tag.
78export default async function main(req: Request): Promise<Response> {
9const url = new URL(req.url);
10const valName = url.searchParams.get("val");
17// Dynamically import the specified val
18const module = await import(`https://esm.town/v/${valName}`);
19const valFunction = module.default;
2021if (typeof valFunction !== "function") {
22throw new Error("Imported val is not a function");
23}
2425// Execute the imported val function
26const response = await valFunction(req);
27const originalHtml = await response.text();
2842}
4344function injectErrorHandlingScript(html: string): string {
45const script = `
46<script>
47window.onerror = function(message, source, lineno, colno, error) {
48window.parent.postMessage({ messageType: "valBrowserRuntimeError", errorString: "window.onerror: " + message }, "*");
49};
50window.addEventListener('unhandledrejection', function(event) {
51window.parent.postMessage({ messageType: "valBrowserRuntimeError", errorString: "unhandledrejection: " + event.reason }, "*");
52});
53console.error = function(...args) {
54window.parent.postMessage({ messageType: "valBrowserRuntimeError", errorString: "console.error: " + args.join(' ') }, "*");
55};
56window.addEventListener('load', function() {
57setTimeout(function() {
58window.parent.postMessage({ messageType: "success" }, "*");
59}, 3000);
65}
6667function createErrorResponse(errorString: string): Response {
68const errorHtml = `
69<html>
crypto_prices_infomain.tsx1 match
55};
5657export default async function(interval) {
58const cryptoPrices = await getCryptoPrices();
59const formatted = formatCryptoPrices(cryptoPrices);
smallboatsapimain.tsx1 match
42console.log(jsonTable);
4344export default async function(req: Request): Promise<Response> {
45return new Response(JSON.stringify(jsonTable), {
46headers: { "Content-Type": "application/json" },
sqliteExplorerAppREADME.md1 match
33- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
34- [x] make result tables scrollable
35- [x] add export to CSV, and JSON (CSV and JSON helper functions written in [this val](https://www.val.town/v/nbbaier/sqliteExportHelpers). Thanks to @pomdtr for merging the initial version!)
36- [x] add listener for cmd+enter to submit query