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 / graphql_controller.rb
Created July 29, 2024 23:00
Retrieving `dclid` cookie in newsletter subscription and tracking a lead event with `dub`
# app/controllers/graphql_controller.rb
class GraphqlController < ApplicationController
def execute
# Reading the `dclid` cookie
dclid = cookies[:dclid]
# Handle the GraphQL query
variables = ensure_hash(params[:variables])
context = {
@steven-tey
steven-tey / youtube-channel.tsx
Last active July 9, 2024 03:41
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 [email protected].
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 29, 2024 20:57
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",