Skip to content

Instantly share code, notes, and snippets.

View feliche93's full-sized avatar

Felix Vemmer feliche93

View GitHub Profile
@feliche93
feliche93 / client.ts
Created August 28, 2023 09:10
FastAPI to Typescript Fetch with openapi-fetch
import createClient from "openapi-fetch";
import { paths } from "./v1";
export const { GET, POST } = createClient<paths>({ baseUrl: "/fast-api" });
@feliche93
feliche93 / app.py
Last active August 28, 2023 08:38
FastAPI App for Webscraping on Modal.com
"""
This module defines the FastAPI application and its endpoints.
It includes the endpoint for scraping a website and potentially an endpoint for finding contacts.
The application is wrapped with a stub function for deployment.
"""
from typing import Any
from common import ENV, image, secret, stub
from fastapi import FastAPI
@feliche93
feliche93 / route.ts
Created August 28, 2023 08:15
Browserless.io Next.js Edge Route, scraping Website Content
import { SScrapingResult, SWebsiteInfoInput, SWebsiteInfoOutput } from '@lib/zod-models';
import { NextResponse } from 'next/server';
import { z } from 'zod';
export const runtime = 'edge'
export async function POST(request: Request) {
const data = await request.json();
const startTime = Date.now();
@feliche93
feliche93 / discord_midjourney_automation.py
Created July 3, 2023 08:44
Discord Midjourney Image Automation
import asyncio
import os
from getpass import getpass
from pathlib import Path
from typing import Dict, List, Optional
import boto3
import requests
from dotenv import load_dotenv
from playwright.async_api import Page, async_playwright
@feliche93
feliche93 / account-button.tsx
Created June 26, 2023 09:19
Account Button to cancel or resume lemon squeezy subscription
'use client'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
@feliche93
feliche93 / lemon-squeezy-server-actions.ts
Created June 26, 2023 09:16
Server Actions to manage lemon squeezy subscriptions
"use server"
import { revalidatePath } from "next/cache";
import { SLemonSqueezyRequest, TLemonSqueezyRequest } from "./zod-lemon-squeezy";
const lemonSqueezyBaseUrl = 'https://api.lemonsqueezy.com/v1';
const lemonSqueezyApiKey = process.env.LEMON_SQUEEZY_API_KEY;
if (!lemonSqueezyApiKey) throw new Error("No LEMON_SQUEEZY_API_KEY environment variable set");
@feliche93
feliche93 / sync-products-route.ts
Created June 26, 2023 09:08
Route handlers for synching products, product variants and stores
import { NextResponse } from 'next/server';
import { z } from 'zod';
import camelcaseKeys from 'camelcase-keys'
import { db } from '@lib/db';
import { products } from '@schema';
export const runtime = 'edge' // 'nodejs' is the default
const camelize = <T extends readonly unknown[] | Record<string, unknown>>(
@feliche93
feliche93 / route.ts
Created June 26, 2023 09:04
Route Handler for Lemon Squeezy Subscription Webhook
import crypto from 'crypto';
import { NextResponse } from 'next/server';
import { SLemonSqueezyWebhookRequest } from './models';
import { db } from '@lib/db';
import { subscriptions } from '@schema';
import { eq } from 'drizzle-orm';
import camelcaseKeys from 'camelcase-keys'
import { CamelCasedPropertiesDeep } from 'type-fest' // need CamelCasedPropertiesDeep because of https://github.com/sindresorhus/camelcase-keys/issues/77#issuecomment-1339844470
import { ZodEffects, z } from 'zod';
import PostHogClient from '@lib/posthog';
@feliche93
feliche93 / lemon-squeezy-schema.ts
Created June 26, 2023 09:02
Lemon Squeezy Table Schemas for Drizzle
// declaring enum in database for subscription status
export const subscriptionStatusEnum = pgEnum('subscription_status', [
'on_trial',
'active',
'paused',
'past_due',
'unpaid',
'cancelled',
'expired',
]);
@feliche93
feliche93 / zod-lemon-squeezy-subscription.ts
Created June 26, 2023 09:00
Models to parse Lemon Squeezy Webhook Request
import { z } from 'zod';
import camelcaseKeys from 'camelcase-keys'
const camelize = <T extends readonly unknown[] | Record<string, unknown>>(
val: T,
) => camelcaseKeys(val)
const Urls = z.object({
update_payment_method: z.string(),
}).transform(camelize);