Skip to content

Instantly share code, notes, and snippets.

View steven-tey's full-sized avatar
👷
building infra for the next trillion links on the web @dubinc

Steven Tey steven-tey

👷
building infra for the next trillion links on the web @dubinc
View GitHub Profile
@pontusab
pontusab / import.ts
Last active March 14, 2024 13:30
Import background job
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";
@veekaybee
veekaybee / normcore-llm.md
Last active March 31, 2025 06:09
Normcore LLM Reads

Anti-hype LLM reading list

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.

Foundational Concepts

Screenshot 2023-12-18 at 10 40 27 PM

Pre-Transformer Models

@paulpopus
paulpopus / middleware.ts
Created August 11, 2023 07:26
Nextjs Middleware for Payload authentication to redirect users based on authentication
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']
@steven-tey
steven-tey / title-from-url.ts
Last active February 20, 2025 12:37
Get Title from URL
// 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();
})
@av01d
av01d / convertDataURItoBinary.js
Created January 20, 2022 13:15
Convert base64 string to Uint8Array (one liner)
/**
* 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));
@MehediH
MehediH / cazoo.js
Created November 21, 2021 20:09
cazoo cloudflare worker
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() {
@BjornDCode
BjornDCode / gist:5cb836a6b23638d6d02f5cb6ed59a04a
Created February 3, 2020 11:58
Tailwind - Fixed sidebar, scrollable content
// Source: https://twitter.com/calebporzio/status/1151876736931549185
<div class="flex">
<aside class="h-screen sticky top-0">
// Fixed Sidebar
</aside>
<main>
// Content
</main>
@wallawe
wallawe / image_upload_cloudinary.js
Last active September 7, 2023 03:20
Cloudinary v2 image uploader component in React (using Next.js)
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
anonymous
anonymous / r code to debug
Created August 24, 2016 13:28
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)
@Rich-Harris
Rich-Harris / service-workers.md
Last active April 7, 2025 10:50
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

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.

Use Canary for development instead of Chrome stable

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.