Skip to content

Instantly share code, notes, and snippets.

View aayushchugh's full-sized avatar
👨‍💻
Writing Code

Ayush Chugh aayushchugh

👨‍💻
Writing Code
View GitHub Profile
const timezones = [
{
label: "Pacific/Midway (GMT-11:00)",
tzCode: "Pacific/Midway",
name: "(GMT-11:00) Midway",
utc: "-11:00",
abbreviation: "SST",
},
{
label: "Pacific/Niue (GMT-11:00)",
@aayushchugh
aayushchugh / .prettierrc
Created March 20, 2026 14:06
My prettier config
{
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "all",
"printWidth": 100,
"arrowParens": "always",
"endOfLine": "lf"
}
@aayushchugh
aayushchugh / email-rate-limiter.service.ts
Created November 19, 2025 10:34
Implementing rate limits for 3rd party notification services
import { logger } from "@avenue/shared";
export class EmailRateLimiterService {
private tokens: number;
private readonly maxTokens: number;
private readonly refillRate: number;
private lastRefillTime: number;
private highPriorityWaiters: Array<() => void> = [];
private lowPriorityWaiters: Array<() => void> = [];
private processingTimer: NodeJS.Timeout | null = null;
@aayushchugh
aayushchugh / logger.ts
Created October 13, 2025 13:46
Logger to dump logs in cloudwatch
import winston from "winston";
import "winston-daily-rotate-file";
import WinstonCloudWatch from "winston-cloudwatch";
import { env } from "../config/env";
const isProduction = env.NODE_ENV === "production";
const environment = env.NODE_ENV || (isProduction ? "production" : "development");
const isCloudwatchEnabled = env.NODE_ENV === "production" || env.NODE_ENV === "stage";
type LogModule =
@aayushchugh
aayushchugh / tap-to-pay.tsx
Created August 24, 2025 17:58
Tap to pay in stripe
import {
useStripeTerminal,
type PaymentIntent,
type StripeError,
CommonError
} from '@stripe/stripe-terminal-react-native';
import { showError, showSuccess, showInfo } from '@/utils/toast';
import { useRouter } from 'expo-router';
import axios from 'axios';
import url from '@/constants/url';
@aayushchugh
aayushchugh / getCurrencySignFromCode.ts
Created June 25, 2025 18:35
Get currency sign/symbol from currency code
/**
* Most ISO 4217 codes start with the same two letters as their ISO 3166 country code (e.g.
* USD → US, INR → IN, AUD → AU). You can use that pattern if you don’t need perfect coverage:
*/
export function getLocaleFromCurrency(currency: string): string {
// e.g. "INR" → "IN", "USD" → "US", "AUD" → "AU"
const region = currency.slice(0, 2).toUpperCase();
// default to English in that region
return `en-${region}`;
}
@aayushchugh
aayushchugh / next-static-website-docker.md
Last active June 9, 2026 16:21
Config files to host static NextJs website using Docker and Nginx

If you want to host your static nextjs application using docker and nginx, follow the following steps:

  1. Create Dockerfile in root of your project and paste following contents
# Stage 1: Build the Next.js app
FROM node:lts AS build-deps
WORKDIR /usr/src/app

COPY package.json yarn.lock ./
@aayushchugh
aayushchugh / countryData.md
Created June 22, 2024 14:12
Country Name, Nationality, Calling Code list

Here is a list of country data, nationality and their calling codes

[
  {
    "callingCode": "376",
    "code": "AD",
    "code3": "AND",
    "emoji": "🇦🇩",
    "name": "Andorra",
@aayushchugh
aayushchugh / prisma_error.md
Created June 5, 2023 13:13
Authentication failed against database server at localhost, the provided database credentials for johndoe are not valid. in prisma

So I was facing this error while connecting postgreSQL with prisma

Authentication failed against database server at localhost, the provided database credentials for johndoe are not valid.

I spent 2 days solving this and these were the errors in my code

1. Problem: Multiple .env files

There were 2 .env files, 1st in the folder of my server and 2nd in the parent folder (this was a monorepo) with

@aayushchugh
aayushchugh / nginx-default
Last active May 12, 2023 12:26
Nginx default file
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#