Skip to content

Instantly share code, notes, and snippets.

View Sanchitbajaj02's full-sized avatar
:octocat:
Working on something

Sanchit Bajaj Sanchitbajaj02

:octocat:
Working on something
View GitHub Profile
@Sanchitbajaj02
Sanchitbajaj02 / App.jsx
Created November 27, 2024 17:32
Dynamic data creation of table using server api
import { useState, useEffect } from "react";
const URL = "";
export default function App() {
const [products, setProducts] = useState([]);
const [productColumns, setProductColumns] = useState([]);
function getColumnNames(products) {
if (!products || products.length === 0) return null;
return Object.keys(products[0]);
@Sanchitbajaj02
Sanchitbajaj02 / page.tsx
Created November 10, 2024 06:15
Working logic of pagination to render data in cards for the news api
import { useState } from "react";
import Link from "next/link";
import { Card, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
@Sanchitbajaj02
Sanchitbajaj02 / mail-calender.js
Created September 10, 2024 02:59
Configure calendars over the email using this code
const {google} = require('googleapis');
const nodemailer = require('nodemailer');
const calendar = google.calendar({version: 'v3', auth});
// Set up the transporter for sending email
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
@Sanchitbajaj02
Sanchitbajaj02 / index.js
Created September 12, 2023 05:31
The function returns the number in currency format of a particular region
function formatNumberIndianFormat(amount: number): string {
let result: string = new Intl.NumberFormat('en-IN', {
style: 'currency',
currency: 'INR',
}).format(amount)
return result
}
@Sanchitbajaj02
Sanchitbajaj02 / index.js
Last active December 3, 2024 06:53
Regex for email and name
const emailRegex01 = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
const emailRegex02 = /^[a-zA-Z0-9_.+]+(?<!^[0-9]*)@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;
const emailRegex03 = /^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$/;
const emailRegex05 = /^(?![0-9])[a-zA-Z0-9_.+]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]{2,4}$/;
// Adheres closely to RFC 5322 standard
const emailRegex05 = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
const PASSWORD_REGEX = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/;
@Sanchitbajaj02
Sanchitbajaj02 / ErrorBoundary.js
Created March 12, 2023 06:07
This component handle the boundary errors occurs in React.js
import React from "react"
class ErrorBoundary extends React.Component {
state = {
hasError: false
}
static getDerivedStateFromError(error) {
return { hasError: true }
}
@Sanchitbajaj02
Sanchitbajaj02 / index.ts
Created March 7, 2023 10:55
API cache control to put requests cache in nodejs + typescript
// treat this as a middleware function
const setCache = (req: Request, res: Response, next: NextFunction) => {
// 5 minutes
const period = 60 * 5;
if (req.method === "GET") {
res.set("Cache-Control", `public, max-age=${period}`);
} else {
res.set("Cache-Control", `no-store`);
}

React Native: Independent Dark Mode Setup

In this gist I am going to explain how to make your react-native application independent to the dark/night mode in android.

Dark mode is natively available since sdk 30 (Android 10) and to change this, we need to downgrade the sdk.

  • In android\app\src\main\res\values\styles.xml add the below code
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
 false
@Sanchitbajaj02
Sanchitbajaj02 / index.js
Created December 3, 2021 07:32
A sample javascript code which will show that javascript has a quirky behavior
const student = {
age: 44,
name: {
firstname: 'John',
lastname: 'Doe',
}
};
student.age = 19;
console.log(student);
name: Automate Pull Request Generation
on:
push:
branches:
- master
jobs:
createPullRequest:
runs-on: ubuntu-latest