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
@steven-tey
steven-tey / youtube-channel.tsx
Last active April 11, 2024 14:34
YoutubeChannel RSC
import { BlurImage, YouTube } from "@dub/ui";
import { nFormatter } from "@dub/utils";
import { Eye, UserCheck, Video } from "lucide-react";
import { Suspense } from "react";
export function YoutubeChannel({ id }: { id: string }) {
return (
<Suspense fallback={<div className="not-prose grid gap-4"></div>}>
<YoutubeChannelRSC id={id} />
</Suspense>
@steven-tey
steven-tey / dub-cla
Created March 12, 2024 19:53
Dub.co Individual Contributor License Agreement
### Dub.co Individual Contributor License Agreement
Thank you for your interest in contributing to open source software projects (“Projects”) made available by Dub Technologies, Inc. or its affiliates (Dub). This Individual Contributor License Agreement (“Agreement”) sets out the terms governing any source code, object code, bug fixes, configuration changes, tools, specifications, documentation, data, materials, feedback, information or other works of authorship that you submit or have submitted, in any form and in any manner, to Dub in respect of any of the Projects (collectively “Contributions”). If you have any questions respecting this Agreement, please contact support@dub.co.
You agree that the following terms apply to all of your past, present and future Contributions. Except for the licenses granted in this Agreement, you retain all of your right, title and interest in and to your Contributions.
**Copyright License.** You hereby grant, and agree to grant, to Dub a non-exclusive, perpetual, irrevoc
@steven-tey
steven-tey / valid-chatgpt-ip.ts
Created March 27, 2023 03:05
Typescript code to verify if an incoming request's IP address is from OpenAI's CIDR block
function ipToInt(ip: string) {
return ip.split(".").reduce((acc, octet) => (acc << 8) + parseInt(octet), 0);
}
function isIpInCIDR(ip: string, cidr: string) {
const [cidrIp, prefixLength] = cidr.split("/");
const mask = -1 << (32 - parseInt(prefixLength));
const ipInt = ipToInt(ip);
const cidrIpInt = ipToInt(cidrIp);
@steven-tey
steven-tey / title-from-url.ts
Last active July 9, 2023 19:48
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();
})
@steven-tey
steven-tey / BlurImage.js
Last active September 23, 2022 02:45
BlurImage Component that Self-Updates Twitter Profile Pics with the Twitter API
// components/BlurImage.js
import Image from 'next/image';
import { useState, useEffect } from 'react';
import cn from 'clsx';
export default function BlurImage(props) {
const [isLoading, setLoading] = useState(true);
const [src, setSrc] = useState(props.src);
useEffect(() => setSrc(props.src), [props.src]); // update the `src` value when the `prop.src` value changes
@steven-tey
steven-tey / vercel.json
Created December 7, 2020 05:46
Vercel.json file for NLP Moviebot
{
"version": 2,
"builds": [
{
"src": "./index.py",
"use": "@vercel/python"
}
],
"routes": [
{
@steven-tey
steven-tey / moviebot.js
Created December 7, 2020 05:39
Javascript/jQuery Section for the NLP Moviebot
<script>
var question = 1;
var query = '';
function formatRuntime(mins) {
if (mins == null) {
return 'N/A'
} else {
let h = Math.floor(mins / 60);
let m = mins % 60;
@steven-tey
steven-tey / moviebot.html
Created December 7, 2020 05:38
HTML Code for the NLP Moviebot
<body>
<center>
<h1>
<img
src="{{ url_for('static',filename='assets/avatar.svg') }}"
alt="Moviebot"
style="width:40px;height:40px; align:center;"
/> Moviebot
</h1>
</center>
@steven-tey
steven-tey / model_zappa_settings.json
Created December 7, 2020 05:32
Zappa Settings file for NLP moviebot model
{
"dev": {
"app_function": "app.app",
"profile_name": null,
"project_name": "moviebot",
"runtime": "python3.6",
"s3_bucket": "sugges"
},
"production": {
"app_function": "app.app",
@steven-tey
steven-tey / model_get_recommendations.py
Created December 7, 2020 05:31
Main recommender driver function for model.py
def make_recommendation(query, metadata=metadata):
new_row = metadata.iloc[-1,:].copy()
new_row.iloc[-1] = query
metadata = metadata.append(new_row)
count = CountVectorizer(stop_words='english')
count_matrix = count.fit_transform(metadata['soup'])
cosine_sim2 = cosine_similarity(count_matrix, count_matrix)
sim_scores = list(enumerate(cosine_sim2[-1,:]))
sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True)
ranked_titles = []