This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vite.config.ts | |
// src/sw.ts => /sw.js build on dev | |
// add to index.html: <script vite-ignore type="module">navigator.serviceWorker.register("/sw.js")</script> | |
import { defineConfig, Plugin } from "vite"; | |
import path from "node:path"; | |
import { fileURLToPath } from "node:url"; | |
const dirname = path.dirname(fileURLToPath(import.meta.url)); | |
function sw({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener("install", (event) => { | |
event.waitUntil(skipWaiting()); | |
console.log("Service worker install"); | |
}); | |
addEventListener("activate", (event) => { | |
event.waitUntil(self.clients.claim()); | |
console.log("Service worker activate"); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE DeriveGeneric #-} -- FromJSON と Show の自動導出に必要 | |
module Main (main) where | |
import qualified Network.HTTP.Req as Req | |
import qualified Data.Aeson as Aeson | |
import Control.Monad.IO.Class (liftIO) | |
import GHC.Generics (Generic) -- DeriveGeneric に必要 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Usage | |
* $ deno run imagen.ts --prompt "Santa Claus driving a Cadillac" | |
* $ deno run imagen.ts --file prompt.txt | |
* $ deno run imagen.ts --file prompt.txt --out out.png | |
*/ | |
import { experimental_generateImage as generateImage, generateText } from "ai"; | |
import { openai } from "@ai-sdk/openai"; | |
import { printImageFromBase64 } from "@mizchi/imgcat"; | |
import { parseArgs } from "node:util"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://orm.drizzle.team/docs/guides/vector-similarity-search | |
import { PGlite } from "npm:@electric-sql/pglite"; | |
import { vector as pgVector } from "@electric-sql/pglite/vector"; | |
import { index, integer, pgTable, vector, text } from "drizzle-orm/pg-core"; | |
import { drizzle, type PgliteDatabase } from "drizzle-orm/pglite"; | |
import { openai } from "@ai-sdk/openai"; | |
import { embed } from "ai"; | |
import { cosineDistance, sql, desc, gt } from "drizzle-orm"; | |
// openai embedding |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* $ npx tsx asset-cov.ts https://www.cnn.co.jp/fringe/35230901.html https://www.cnn.co.jp --filter '.css' | |
--- Final Coverage Report --- | |
--- CSS Files --- | |
File: https://www.cnn.co.jp/static/css/atlanta/responsive.css | |
Total size: 13000 bytes | |
Estimated used size (across pages): 3943 bytes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const iterations = 1000000; // 試行回数 | |
const urlString = "https://example.com/path/to/resource?query=param#fragment"; | |
const domainToCheck = "https://example.com"; | |
console.log(`Benchmarking with ${iterations} iterations...\n`); | |
// --- new URL() benchmark --- | |
console.log(`1. Parsing URL with new URL("${urlString}")`); | |
const startNewUrl = performance.now(); | |
for (let i = 0; i < iterations; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { drizzle } from "npm:@mizchi/drizzle-orm/dist/node-sqlite/index.js"; | |
import { | |
integer, | |
sqliteTable, | |
text, | |
} from "npm:@mizchi/drizzle-orm/dist/sqlite-core/index.js"; | |
import { eq } from "npm:@mizchi/drizzle-orm/dist/index.js"; | |
// Define the schema | |
const users = sqliteTable("users", { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { drizzle } from "drizzle-orm/node-sqlite"; | |
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core"; | |
import { eq } from "drizzle-orm"; | |
// Define the schema | |
const users = sqliteTable("users", { | |
id: integer("id").primaryKey(), | |
name: text("name").notNull(), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from "node:fs/promises"; | |
import { createReadStream } from "node:fs"; | |
import zlib from "node:zlib"; | |
import { pipeline } from "node:stream/promises"; | |
import { PGlite } from "@electric-sql/pglite"; | |
async function writePg(filePath: string, pglite: PGlite) { | |
await fs.writeFile(filePath, (await pglite.dumpDataDir("gzip")).stream()); | |
} | |
async function readPg(filePath: string) { |
NewerOlder