Skip to content

Instantly share code, notes, and snippets.

@mmikhan
mmikhan / schema.ts
Created March 12, 2025 18:27
Zod mail configuration schema that takes a default empty value for an email field but also can be an empty string
export const mailConfigurationSchema = z.object({
apiKey: z.string().default(""),
fromEmail: z
.string()
.email()
.optional()
.or(z.literal(""))
.default(""),
toName: z.string().default(""),
toEmail: z
@mmikhan
mmikhan / paypal.ts
Last active February 22, 2025 13:53
PayPal TypeScript SDK oAuth fetch token implementation
import { type User } from "@/server/auth/types";
import { type SelectProduct } from "@/server/db/schema/products-schema";
import {
ApiError,
CheckoutPaymentIntent,
Client,
ClientCredentialsAuthManager,
Environment,
LogLevel,
OrderApplicationContextShippingPreference,
@mmikhan
mmikhan / stripe-plan-upgrade-downgrade-dialog.tsx
Created February 21, 2025 19:29
Stripe plan upgrade downgrade dialog with Hook form implementation
"use client";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
@mmikhan
mmikhan / schema.ts
Created February 17, 2025 19:22
An example of Zod schema together with a React client component to submit an array of object through the input form
export const WEBHOOK_CONFIG_MODES = [
{ value: "auto", label: "Auto" },
{ value: "manual", label: "Manual" },
] as const;
export type WebhookConfigMode = (typeof WEBHOOK_CONFIG_MODES)[number];
export const WEBHOOK_CONFIG_MODE_VALUES = WEBHOOK_CONFIG_MODES.map(
(mode) => mode.value,
) as [string, ...string[]];
@mmikhan
mmikhan / stripe-checkout-session-completed.json
Created February 15, 2025 19:45
Stripe checkout session completed event web hook object
{
"api_version": "2025-01-27.acacia",
"created": 1739648336,
"data": {
"object": {
"adaptive_pricing": null,
"after_expiration": null,
"allow_promotion_codes": null,
"amount_subtotal": 1000,
"amount_total": 1000,
@mmikhan
mmikhan / auth-social-provider-form.tsx
Created February 13, 2025 20:55
Better Auth social providers with Secret Key component
"use client";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import {
@mmikhan
mmikhan / uploader.tsx
Created December 28, 2024 14:38
Upload Thing reusable client component
"use client";
import { useState } from "react";
import { generateReactHelpers } from "@uploadthing/react";
import type { OurFileRouter } from "@/app/api/uploadthing/core";
export const { uploadFiles } = generateReactHelpers<OurFileRouter>();
interface FormData {
name: string;
@mmikhan
mmikhan / action.ts
Created December 10, 2024 16:55
A simpel React form with server component (RSC) and Action State
'use server'
export async function signUpAction() {
const { data, error } = await authClient.signUp.email({
email: "[email protected]",
password: "password",
name: "John Doe",
});
return { data, error };
@mmikhan
mmikhan / wp-forum-scrapper.py
Created June 4, 2023 21:45
Scrapes discussions from WordPress forum and export the URLs to CSV files
"""
This script scrapes discussions from the Yoast SEO plugin's public forum on
WordPress (https://wordpress.org/support/plugin/wordpress-seo/). The script
fetches discussion titles and URLs from all available pages.
The script also features lazy loading by adding a delay between requests. This
helps ensure responsible web scraping by not overwhelming the server.
The fetched URLs are then saved to multiple CSV files, each containing a
specified number of URLs (default is 500). The CSV files are saved in the 'dist/'
@mmikhan
mmikhan / workday_random_numbers.py
Last active June 4, 2023 21:20
Workday Random Numbers Generator
#!/usr/bin/env python3
"""
Workday Random Numbers Generator
This script generates random floating-point numbers between 8 and 10,
rounded to 2 decimal places, only for workdays in a specified month and year.
Since the script usually runs from the first week of the following month, the
default month and year are set to the previous month and year. The script also
highlights weekends in red. The output is printed to the console and copied to
your clipboard.