Skip to content

Instantly share code, notes, and snippets.

@myogeshchavan97
myogeshchavan97 / App.jsx
Created April 2, 2024 11:14
Protected Routes Using createBrowserRouter
import React, { useState } from 'react';
import {
Navigate,
RouterProvider,
createBrowserRouter,
} from 'react-router-dom';
import Cart from './components/Cart';
import Home from './components/Home';
import Login from './components/Login';
import Orders from './components/Orders';
@myogeshchavan97
myogeshchavan97 / is_valid_email_es6.js
Created November 23, 2019 18:53
Email Validation Using ES6 Arrow Function Syntax
const validateEmail = email => /^[^@ ]+@[^@ ]+\.[^@ \.]+$/.test(email);
const isValidEmail = value => validateEmail(value) || 'Please enter a valid email address.';
let isValid = isValidEmail('abc@gmail.com');
console.log(isValid); // true
isValid = isValidEmail('abc@@gmail.com');
console.log(isValid); // Please enter a valid email address
@myogeshchavan97
myogeshchavan97 / trap_focus.js
Last active November 26, 2022 08:46
Code for trapping focus inside modal
// add all the elements inside modal which you want to make focusable
const focusableElements =
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
const modal = document.querySelector('#exampleModal'); // select the modal by it's id
const firstFocusableElement = modal.querySelectorAll(focusableElements)[0]; // get first element to be focused inside modal
const focusableContent = modal.querySelectorAll(focusableElements);
const lastFocusableElement = focusableContent[focusableContent.length - 1]; // get last element to be focused inside modal
@myogeshchavan97
myogeshchavan97 / styles.css
Created October 26, 2022 17:33
CSS Style
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
font-size: 20px;
width: 60%;
margin: 10px auto;
}
.errorMsg {
max-width: 350px;
@myogeshchavan97
myogeshchavan97 / topics.js
Created May 7, 2022 06:06
List of topics
const topics = [
{
id: 1,
title: "Basic JavaScript",
slug: "basic-javascript",
subTopics: [
{
id: 1,
title: "JavaScript Operators",
slug: "javascript-operators"
// Section 1
const serverless = require('serverless-http');
const express = require('express');
const axios = require('axios');
const path = require('path');
const router = express.Router();
// Section 2
const app = express();
app.use(express.static(path.join(__dirname, '..', 'public')));
@myogeshchavan97
myogeshchavan97 / products.json
Created February 3, 2022 15:54
Products data
[
{
"name": "Margherita",
"category": "Pizza",
"image": "https://res.cloudinary.com/dyatqxvue/image/upload/v1622453419/margherita_5cdac6ceb6.jpg"
},
{
"name": "Double Cheese Margherita",
"category": "Pizza",
"image": "https://res.cloudinary.com/dyatqxvue/image/upload/v1622453443/double_cheese_margherita_9e5ff8f006.jpg"
import React from "react";
import ReactDOM from "react-dom";
const AddItemForm = props => (
<form onSubmit={props.handleAddItem}>
<input
type="text"
name="text"
placeholder="Enter some value"
autoComplete="off"
@myogeshchavan97
myogeshchavan97 / styles.scss
Last active October 19, 2021 23:40
CSS file
$body-color: #949ca5;
$default-padding: 2rem;
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
@myogeshchavan97
myogeshchavan97 / toppings.json
Created August 6, 2021 17:55
Toppings JSON
[
{
"name": "Capsicum",
"_id": "608c43a5f9b60c077d566e74",
"Toppings": "Capsicum",
"published_at": "2021-04-30T17:51:37.192Z",
"createdAt": "2021-04-30T17:51:33.225Z",
"updatedAt": "2021-05-02T09:16:59.480Z",
"__v": 0,
"price": 1.2,