Goals: Add links that are reasonable and good explanations of how stuff works. No hype and no vendor content if possible. Practical first-hand accounts of models in prod eagerly sought.

import crypto from "node:crypto"; | |
import { ChatPromptTemplate } from "@langchain/core/prompts"; | |
import { ChatOpenAI } from "@langchain/openai"; | |
import { eventTrigger } from "@trigger.dev/sdk"; | |
import { capitalCase } from "change-case"; | |
import * as d3 from "d3-dsv"; | |
import { CSVLoader } from "langchain/document_loaders/fs/csv"; | |
import { TokenTextSplitter } from "langchain/text_splitter"; | |
import { z } from "zod"; | |
import { client, supabase } from "../client"; |
import { NextResponse } from 'next/server' | |
import type { NextRequest } from 'next/server' | |
import { CheckUserDocument } from '@/graphql/generated/client' | |
import { CheckUserQuery } from '@/graphql/generated/client' | |
/* Redirect away from these routes if not authenticated */ | |
const protectedRoutes = ['/profile', '/search'] | |
/* Redirect away from these routes if authenticated */ | |
const publicRoutes = ['/login', '/register'] |
// Note: this gist is a part of this OSS project that I'm currently working on: https://github.com/steven-tey/dub | |
export default async function getTitleFromUrl (url: string) { | |
const controller = new AbortController(); | |
const timeoutId = setTimeout(() => controller.abort(), 2000); // timeout if it takes longer than 2 seconds | |
const title = await fetch(url, { signal: controller.signal }) | |
.then((res) => { | |
clearTimeout(timeoutId); | |
return res.text(); | |
}) |
/** | |
* One liner to convert a base64 string to a binary Uint8Array | |
* | |
* Example: | |
* const dataURL = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2w....'; | |
* console.log(convertDataURIToBinary(dataURL)); | |
*/ | |
const convertDataURIToBinary = dataURI => | |
Uint8Array.from(window.atob(dataURI.replace(/^data[^,]+,/,'')), v => v.charCodeAt(0)); |
const cazooApiUrl = "https://www.cazoo.co.uk/api/search?sort=createdAt-desc&runningCosts=ulezChargeExempt&fuelType=Petrol%2CElectric%2CPlug_in_Hybrid%2CHybrid&gearbox=Automatic&ownershipType=purchase&maxMonthlyPrice=280"; | |
const discordWebhookUrl = "https://discord.com/api/webhooks/ENTER_YOUR_WEBHOOK" | |
/* | |
For this to work, you need to setup Workers KV https://developers.cloudflare.com/workers/runtime-apis/kv | |
Here, my KV namespace is called CAZOO | |
For the worker to actually get triggered, you'll also need to set up a cron job from the Workers UI in Cloudflare | |
*/ | |
async function handleRequest() { |
// Source: https://twitter.com/calebporzio/status/1151876736931549185 | |
<div class="flex"> | |
<aside class="h-screen sticky top-0"> | |
// Fixed Sidebar | |
</aside> | |
<main> | |
// Content | |
</main> |
import { Component } from 'react' | |
import Head from 'next/head' | |
const CLOUD_NAME = '<name here>' | |
export default class ImageUploader extends Component { | |
constructor(props) { | |
super(props) | |
this.uploader = null |
city.names <- c("A", "B", "C", "D", "E", "F", "G", "H") | |
observed.turnout = c(18, 30, 14, 52, 24, 29, 48, 49) | |
observed.diffmeans <- mean(observed.turnout[c(2,4,6,8)]) - | |
mean(observed.turnout[c(1,3,5,7)]) | |
print(observed.diffmeans) | |
foo <- as.data.frame(city.names, observed.turnout) |
I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.
I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.
Chrome 51 has some pretty wild behaviour related to console.log
in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.