Skip to content

Instantly share code, notes, and snippets.

@vhsu
vhsu / supabasenewusertrigger.md
Created January 20, 2025 22:19
Using Triggers on New User Signup in Supabase

Using Triggers on New User Signup in Supabase

Supabase allows you to create database triggers that execute automatically when a new user signs up. This guide demonstrates how to set up a trigger to add initial data (e.g., credits) for new users.


Prerequisites

  1. A Supabase project with authentication enabled.
  2. Familiarity with SQL and Supabase's auth.users table.
@vhsu
vhsu / imageresize.md
Last active January 16, 2025 21:40
Quickly Resize Images for Email Using Microsoft PowerToys

How to Quickly Resize Images for Email Using Microsoft PowerToys

Introduction

Microsoft PowerToys is a free utility that lets you resize images directly from Windows Explorer with just a right-click. It's perfect for preparing large images to be sent via email without needing to open a separate app.

This guide shows you how to install PowerToys, enable the Image Resizer feature, and use it to resize images quickly.


Step 1: Install Microsoft PowerToys

@vhsu
vhsu / imagesitemap.py
Created November 28, 2024 15:42
Image sitemap generate form html
"""
Generate Image Sitemap for a Single HTML Page
This script reads an HTML file, extracts all the image URLs from the <img> tags, and generates an XML sitemap compliant with Google's image sitemap protocol. The generated sitemap can help improve the visibility of images in search engines.
Usage:
- Ensure you have the 'beautifulsoup4' package installed: `pip install beautifulsoup4`
- Set the `html_file` variable to the path of your HTML file.
- Set the `page_url` variable to the URL of the page where the images are located.
- Run the script to generate 'sitemap.xml' containing the image sitemap.
@vhsu
vhsu / page.google-product-feed.liquid
Last active March 20, 2025 23:19 — forked from cameroncowden/page.google-product-feed.liquid
Shopify Google Product Feed xml generator
{% comment %}
Instructions:
- Create a blank page called 'Google Base Product Feed'and save it
- Open that page for editing and select 'page.google-feed' from the page template selector
- Add a brief site description to the meta-shop-description snippet
- The feed url should now be available at http://www.yoursite.com/pages/google-base-product-feed
- validate your field at http://validator.w3.org/feed/
- when ready, submit your feed at http://base.google.com
@vhsu
vhsu / mnist.py
Created October 11, 2024 00:39
Mnist example with Pytorch fully generated with chatgpt 4o-preview
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
from torchvision import datasets, transforms
from torch.utils.data import DataLoader
# Step 1: Load and Preprocess the MNIST Dataset
# Define transformations for the training and testing data
transform = transforms.Compose([
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyMr5e9IsCxg3q+sApsIAZ0/",
"include_colab_link": true
},
"kernelspec": {
@vhsu
vhsu / imgremovedups.py
Created August 13, 2024 13:15
Script to Remove Duplicate Images from a Folder This script identifies and removes duplicate images within a specified folder. It uses perceptual hashing to generate a unique fingerprint for each image, allowing it to detect duplicates even if the files have different names or formats.
"""
Script to Remove Duplicate Images from a Folder
This script identifies and removes duplicate images within a specified folder.
It uses perceptual hashing to generate a unique fingerprint for each image,
allowing it to detect duplicates even if the files have different names or formats.
What the Code Does:
-------------------
1. Scans the specified folder for image files (supports common formats such as
@vhsu
vhsu / Add_border.py
Created May 18, 2024 22:23
Add a blank white border to an image in python using PIL
from PIL import Image
def add_border(input_image_path, output_image_path, border_size=100):
# Open an existing image
img = Image.open(input_image_path)
# Get the size of the original image
width, height = img.size
# Make the new image size as the original size plus the border
@vhsu
vhsu / Take_out_elements.py
Created November 28, 2023 15:57
Take elements out of a list in python and get its value by index
def take_out_elements(list_object, indices):
"""Removes elements from list in specified indices"""
removed_elements = []
indices = sorted(indices, reverse=True)
for idx in indices:
if idx < len(list_object):
removed_elements.append(list_object.pop(idx))
return removed_elements