Skip to content

Instantly share code, notes, and snippets.

View ameetmadan's full-sized avatar
🏠
Working from home

Ameet Madan ameetmadan

🏠
Working from home
View GitHub Profile
@ameetmadan
ameetmadan / luhn.py
Created March 10, 2025 22:20
Luhn algorithm for credit card number validation
def luhn_algorithm(card_number):
"""
Validates a card number using the Luhn algorithm.
Args:
card_number: A string or integer representing the card number to validate.
Returns:
Boolean: True if the card number is valid according to the Luhn algorithm, False otherwise.
"""
@ameetmadan
ameetmadan / nginx.conf
Created February 24, 2025 20:03
NGINX with SSL
# HTTP Server - Redirects to HTTPS
server {
listen 80;
listen [::]:80;
server_name <subdomain>.<domain>.com;
# Redirect all HTTP requests to HTTPS
location / {
return 301 https://$host$request_uri;
}
import json
from typing import List, Set
import time
from datetime import datetime
def load_json_file(file_path: str) -> dict:
"""Load and parse a JSON file."""
with open(file_path, 'r', encoding='utf-8') as f:
return json.load(f)
import json
def load_user_data(json_data, key):
"""Extract usernames from the JSON data"""
users = []
for item in json_data[key]:
username = item["string_list_data"][0]["value"]
users.append(username)
return set(users)
import requests
import webbrowser # Import webbrowser to open links
import time
# GitHub username
USERNAME = ""
# Replace 'None' with your GitHub Personal Access Token
GITHUB_TOKEN= None
import requests
import random
# GitHub Configuration
GITHUB_TOKEN = "YOUR_GITHUB"
REPO_OWNER = ""
REPO_NAME = ""
API_URL = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}"
HEADERS = {"Authorization": f"token {GITHUB_TOKEN}"}
@ameetmadan
ameetmadan / pagination.ts
Created January 21, 2024 12:01
Next.js generic paginated response for API routes
import { NextApiResponse } from "next";
export interface PaginationResult<T> {
success: boolean;
data: T[];
pagination: {
page: number;
limit: number;
totalPages: number;
totalCount: number;
@ameetmadan
ameetmadan / ch-cantons.ts
Created October 3, 2023 21:25
Swiss cantons TS array
export const cantons = [
{title: "Aargau", code: "AG"},
{title: "Appenzell Ausserrhoden", code: "AR"},
{title: "Appenzell Innerrhoden", code: "AI"},
{title: "Basel-Landschaft", code: "BL"},
{title: "Basel-Stadt", code: "BS"},
{title: "Bern", code: "BE"},
{title: "Fribourg", code: "FR"},
{title: "Genève", code: "GE"},
{title: "Glarus", code: "GL"},
@ameetmadan
ameetmadan / countries.ts
Created October 3, 2023 21:24
TS country array
export const countries = [
"Afghanistan",
"Åland-Inseln",
"Albanien",
"Algerien",
"Amerikanisch-Samoa",
"Andorra",
"Angola",
"Anguilla",
"Antarktis",
@ameetmadan
ameetmadan / date-diff.ts
Created April 17, 2023 07:44
Clean display of dates in the past
import DateDiff from "date-diff";
export function getFormattedDateDifference(dateAdded: string) {
const diff = new DateDiff(new Date(), new Date(dateAdded))
if (diff.minutes() < 60) {
if (Math.round(diff.minutes()) === 1) {
return `${Math.round(diff.minutes())} minute ago`
}
return `${Math.round(diff.minutes())} minutes ago`
}
if (diff.hours() < 24) {