├── week-6 ├── 3-use-ref │ ├── src │ │ ├── App.css │ │ ├── index.css │ │ ├── main.jsx │ │ ├── App.jsx │ │ └── components │ │ │ ├── Assignment1.jsx │ │ │ └── Assignment2.jsx │ ├── vite.config.js │ ├── .gitignore │ ├── index.html │ ├── README.md │ ├── .eslintrc.cjs │ ├── package.json │ └── public │ │ └── vite.svg ├── 1-use-memo │ ├── src │ │ ├── App.css │ │ ├── index.css │ │ ├── main.jsx │ │ ├── App.jsx │ │ └── components │ │ │ ├── Assignment1.jsx │ │ │ ├── Assignment3.jsx │ │ │ └── Assignment2.jsx │ ├── vite.config.js │ ├── .gitignore │ ├── index.html │ ├── README.md │ ├── .eslintrc.cjs │ ├── package.json │ └── public │ │ └── vite.svg └── 2-use-callback │ ├── src │ ├── App.css │ ├── index.css │ ├── main.jsx │ ├── App.jsx │ └── components │ │ ├── Assignment1.jsx │ │ └── Assignment2.jsx │ ├── vite.config.js │ ├── .gitignore │ ├── index.html │ ├── README.md │ ├── .eslintrc.cjs │ ├── package.json │ └── public │ └── vite.svg ├── week-2 ├── async-js │ ├── medium │ │ ├── file-cleaner.md │ │ └── clock.md │ ├── easy │ │ ├── counter2.md │ │ ├── counter.md │ │ ├── read_from_file.md │ │ └── write_from_file.md │ └── hard │ │ ├── promisify-setTimeout.js │ │ ├── sleep-compeltely.js │ │ ├── promise-chain.js │ │ └── promise-all.js └── nodejs │ ├── files │ └── a.txt │ └── problems │ └── fileServer.js ├── week-3 ├── mongo │ ├── .gitignore │ ├── index.js │ ├── middleware │ │ ├── user.js │ │ └── admin.js │ ├── package.json │ ├── db │ │ └── index.js │ └── routes │ │ ├── admin.js │ │ └── user.js ├── mongo-with-jwt-auth │ ├── .gitignore │ ├── config.js │ ├── index.js │ ├── package.json │ ├── middleware │ │ ├── admin.js │ │ └── user.js │ └── db │ │ └── index.js ├── middlewares │ ├── reqCount.js │ ├── errCount.js │ ├── user_jwt.js │ └── reqLimit.js └── jwt │ └── index.js ├── week-4 └── full_stack_todo │ ├── frontend │ ├── src │ │ ├── App.css │ │ ├── index.css │ │ ├── main.jsx │ │ ├── App.jsx │ │ └── components │ │ │ ├── Todos.jsx │ │ │ └── CreateTodo.jsx │ ├── vite.config.js │ ├── .gitignore │ ├── index.html │ ├── README.md │ ├── .eslintrc.cjs │ ├── package.json │ └── public │ │ └── vite.svg │ ├── .gitignore │ ├── README.md │ └── backend │ ├── types.js │ ├── package.json │ ├── db.js │ └── index.js ├── week-13 ├── blog-stack │ ├── backend │ │ ├── .env │ │ ├── README.md │ │ ├── .gitignore │ │ ├── prisma │ │ │ ├── migrations │ │ │ │ ├── migration_lock.toml │ │ │ │ └── 20240308123022_init_schema │ │ │ │ │ └── migration.sql │ │ │ └── schema.prisma │ │ ├── tsconfig.json │ │ ├── wrangler.toml │ │ ├── src │ │ │ ├── index.ts │ │ │ └── routes │ │ │ │ └── user.ts │ │ └── package.json │ ├── validateCommon │ │ ├── .gitignore │ │ ├── .npmignore │ │ ├── node_modules │ │ │ ├── zod │ │ │ │ ├── lib │ │ │ │ │ ├── benchmarks │ │ │ │ │ │ ├── index.d.ts │ │ │ │ │ │ ├── object.d.ts │ │ │ │ │ │ ├── string.d.ts │ │ │ │ │ │ ├── union.d.ts │ │ │ │ │ │ ├── primitives.d.ts │ │ │ │ │ │ ├── realworld.d.ts │ │ │ │ │ │ ├── discriminatedUnion.d.ts │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ ├── string.js │ │ │ │ │ │ ├── realworld.js │ │ │ │ │ │ ├── union.js │ │ │ │ │ │ ├── object.js │ │ │ │ │ │ └── discriminatedUnion.js │ │ │ │ │ ├── helpers │ │ │ │ │ │ ├── enumUtil.js │ │ │ │ │ │ ├── partialUtil.js │ │ │ │ │ │ ├── typeAliases.js │ │ │ │ │ │ ├── typeAliases.d.ts │ │ │ │ │ │ ├── errorUtil.d.ts │ │ │ │ │ │ ├── errorUtil.js │ │ │ │ │ │ ├── enumUtil.d.ts │ │ │ │ │ │ └── partialUtil.d.ts │ │ │ │ │ ├── index.d.ts │ │ │ │ │ ├── locales │ │ │ │ │ │ └── en.d.ts │ │ │ │ │ ├── external.d.ts │ │ │ │ │ ├── errors.d.ts │ │ │ │ │ ├── __tests__ │ │ │ │ │ │ ├── Mocker.d.ts │ │ │ │ │ │ └── Mocker.js │ │ │ │ │ ├── errors.js │ │ │ │ │ ├── external.js │ │ │ │ │ └── index.js │ │ │ │ ├── index.d.ts │ │ │ │ └── LICENSE │ │ │ └── .package-lock.json │ │ ├── package.json │ │ ├── package-lock.json │ │ └── src │ │ │ └── index.ts │ └── frontend │ │ ├── src │ │ ├── vite-env.d.ts │ │ ├── index.css │ │ ├── config.ts │ │ ├── main.tsx │ │ ├── pages │ │ │ ├── Signin.tsx │ │ │ ├── Signup.tsx │ │ │ ├── Blog.tsx │ │ │ ├── Blogs.tsx │ │ │ └── Publish.tsx │ │ ├── App.tsx │ │ ├── App.css │ │ ├── components │ │ │ ├── Quote.tsx │ │ │ ├── Spinner.tsx │ │ │ ├── Appbar.tsx │ │ │ ├── BlogSkeleton.tsx │ │ │ ├── FullBlog.tsx │ │ │ └── BlogCard.tsx │ │ └── hooks │ │ │ └── index.ts │ │ ├── postcss.config.js │ │ ├── vite.config.ts │ │ ├── tailwind.config.js │ │ ├── tsconfig.node.json │ │ ├── .gitignore │ │ ├── index.html │ │ ├── .eslintrc.cjs │ │ ├── tsconfig.json │ │ ├── package.json │ │ ├── README.md │ │ └── public │ │ └── vite.svg └── README.md ├── week-9 └── typescript │ ├── .gitignore │ ├── src │ └── Calculator.ts │ └── package.json ├── week-7 ├── paytm-fullstack │ ├── backend │ │ ├── .gitignore │ │ ├── config.js │ │ ├── routes │ │ │ ├── index.js │ │ │ └── account.js │ │ ├── index.js │ │ ├── package.json │ │ ├── middleware.js │ │ └── db.js │ └── frontend │ │ ├── .gitignore │ │ ├── src │ │ ├── index.css │ │ ├── assets │ │ │ └── paytm.png │ │ ├── components │ │ │ ├── Heading.jsx │ │ │ ├── SubHeading.jsx │ │ │ ├── Button.jsx │ │ │ ├── BottomWarning.jsx │ │ │ ├── InputBox.jsx │ │ │ ├── Balance.jsx │ │ │ ├── Loader.jsx │ │ │ └── Appbar.jsx │ │ ├── main.jsx │ │ ├── App.css │ │ ├── pages │ │ │ └── Dashboard.jsx │ │ └── App.jsx │ │ ├── postcss.config.js │ │ ├── tailwind.config.js │ │ ├── vite.config.js │ │ ├── index.html │ │ ├── README.md │ │ ├── .eslintrc.cjs │ │ ├── package.json │ │ └── public │ │ └── vite.svg ├── assignments │ └── all │ │ ├── src │ │ ├── index.css │ │ ├── main.jsx │ │ ├── App.jsx │ │ ├── App.css │ │ └── components │ │ │ └── Assignment1 │ │ │ └── index.jsx │ │ ├── postcss.config.js │ │ ├── vite.config.js │ │ ├── tailwind.config.js │ │ ├── .gitignore │ │ ├── index.html │ │ ├── README.md │ │ ├── .eslintrc.cjs │ │ ├── package.json │ │ └── public │ │ └── vite.svg └── README.md ├── week-16 ├── Auth │ ├── frontend │ │ ├── src │ │ │ ├── vite-env.d.ts │ │ │ ├── config.ts │ │ │ ├── main.tsx │ │ │ ├── App.tsx │ │ │ ├── components │ │ │ │ ├── User.tsx │ │ │ │ ├── Signup.tsx │ │ │ │ └── Signin.tsx │ │ │ ├── App.css │ │ │ └── index.css │ │ ├── vite.config.ts │ │ ├── tsconfig.node.json │ │ ├── .gitignore │ │ ├── index.html │ │ ├── .eslintrc.cjs │ │ ├── tsconfig.json │ │ ├── package.json │ │ ├── README.md │ │ └── public │ │ │ └── vite.svg │ └── backend │ │ ├── .gitignore │ │ ├── package.json │ │ └── src │ │ ├── index.ts │ │ └── index.html └── Cookies.md ├── week-5 ├── BusinessCard.png └── ReadME.md ├── week-0 ├── zerodha-app │ ├── img │ │ └── landing.png │ ├── Readme.md │ └── index.html └── basics │ └── introduction.txt ├── README.md └── week-1 ├── problems ├── easy │ ├── findLargestElement.js │ ├── anagram.js │ └── expenditure-analysis.js ├── medium │ ├── palindrome.js │ ├── countVowels.js │ └── times.js └── hard │ └── todo-list.js └── basics ├── numbers.js ├── json.js ├── math.js ├── class.js ├── object.js ├── date.js └── strings.js /week-6/3-use-ref/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-6/1-use-memo/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-6/1-use-memo/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-6/2-use-callback/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-6/3-use-ref/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-2/async-js/medium/file-cleaner.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-6/2-use-callback/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-2/nodejs/files/a.txt: -------------------------------------------------------------------------------- 1 | hello from a.txt -------------------------------------------------------------------------------- /week-3/mongo/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-13/blog-stack/backend/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL="" -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/.gitignore: -------------------------------------------------------------------------------- 1 | dist -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/.npmignore: -------------------------------------------------------------------------------- 1 | src -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-13/README.md: -------------------------------------------------------------------------------- 1 | # Full stack medium blog application 2 | -------------------------------------------------------------------------------- /week-3/mongo-with-jwt-auth/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /week-9/typescript/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/** 2 | *.env -------------------------------------------------------------------------------- /week-7/paytm-fullstack/backend/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | configs 3 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/index.d.ts: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/src/config.ts: -------------------------------------------------------------------------------- 1 | export const BACKEND_URL = "http://localhost:3000"; 2 | -------------------------------------------------------------------------------- /week-16/Auth/backend/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | package-lock.json 4 | yarn-lock.json 5 | -------------------------------------------------------------------------------- /week-3/mongo-with-jwt-auth/config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | JWT_SECRET: "Sai_server", 3 | }; 4 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/backend/config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | JWT_SECRET: "sai-secret", 3 | }; 4 | -------------------------------------------------------------------------------- /week-5/BusinessCard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saivaraprasad48/100xDevs/HEAD/week-5/BusinessCard.png -------------------------------------------------------------------------------- /week-7/assignments/all/src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from "./lib"; 2 | export as namespace Zod; 3 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /week-0/zerodha-app/img/landing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saivaraprasad48/100xDevs/HEAD/week-0/zerodha-app/img/landing.png -------------------------------------------------------------------------------- /week-13/blog-stack/backend/README.md: -------------------------------------------------------------------------------- 1 | ``` 2 | npm install 3 | npm run dev 4 | ``` 5 | 6 | ``` 7 | npm run deploy 8 | ``` 9 | -------------------------------------------------------------------------------- /week-7/assignments/all/postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/helpers/enumUtil.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/helpers/partialUtil.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/helpers/typeAliases.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/assets/paytm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saivaraprasad48/100xDevs/HEAD/week-7/paytm-fullstack/frontend/src/assets/paytm.png -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/index.d.ts: -------------------------------------------------------------------------------- 1 | import * as z from "./external"; 2 | export * from "./external"; 3 | export { z }; 4 | export default z; 5 | -------------------------------------------------------------------------------- /week-13/blog-stack/backend/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .dev.vars 4 | 5 | # Change them to your taste: 6 | package-lock.json 7 | yarn.lock 8 | pnpm-lock.yaml 9 | bun.lockb -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/locales/en.d.ts: -------------------------------------------------------------------------------- 1 | import { ZodErrorMap } from "../ZodError"; 2 | declare const errorMap: ZodErrorMap; 3 | export default errorMap; 4 | -------------------------------------------------------------------------------- /week-9/typescript/src/Calculator.ts: -------------------------------------------------------------------------------- 1 | // Exports and Imports 2 | 3 | export default class Calculator { 4 | add(x: number, y: number): number { 5 | return x + y; 6 | } 7 | } -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/config.ts: -------------------------------------------------------------------------------- 1 | const HOST = "http://127.0.0.1:8787"; 2 | // const HKIRAT = "https://week-13-offline.kirattechnologies.workers.dev" 3 | export const BACKEND_URL = HOST -------------------------------------------------------------------------------- /week-13/blog-stack/backend/prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "postgresql" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 📈100xdevs Cohort 2.0 @hkirat👨‍💻 2 | 3 | ### 🚩This is a 100xDevs repo which includes several tech stuff that I learn daily from my favorite mentor harkirat singh who is a remote developer :) 4 | 5 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/object.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/string.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/union.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/components/Heading.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react/prop-types */ 2 | export function Heading({ label }) { 3 | return
{label}
; 4 | } 5 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/primitives.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/realworld.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /week-6/1-use-memo/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | }) 8 | -------------------------------------------------------------------------------- /week-6/3-use-ref/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | }) 8 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | }) 8 | -------------------------------------------------------------------------------- /week-6/2-use-callback/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | }) 8 | -------------------------------------------------------------------------------- /week-7/assignments/all/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | }) 8 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | }) 8 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/helpers/typeAliases.d.ts: -------------------------------------------------------------------------------- 1 | export declare type Primitive = string | number | symbol | bigint | boolean | null | undefined; 2 | export declare type Scalars = Primitive | Primitive[]; 3 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | }) 8 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/components/SubHeading.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react/prop-types */ 2 | export function SubHeading({ label }) { 3 | return
{label}
; 4 | } 5 | -------------------------------------------------------------------------------- /week-7/assignments/all/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | export default { 3 | content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | }; 9 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | export default { 3 | content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | }; 9 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | export default { 3 | content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | }; 9 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/external.d.ts: -------------------------------------------------------------------------------- 1 | export * from "./errors"; 2 | export * from "./helpers/parseUtil"; 3 | export * from "./helpers/typeAliases"; 4 | export * from "./helpers/util"; 5 | export * from "./types"; 6 | export * from "./ZodError"; 7 | -------------------------------------------------------------------------------- /week-0/zerodha-app/Readme.md: -------------------------------------------------------------------------------- 1 | ### WEBPAGE 2 | 3 | This is the basic Zerodha template with the basics of HTML and CSS :) 4 | 5 | 6 | ![image](https://github.com/Saivaraprasad48/100xDevs/assets/93783719/68f43854-5d9e-46fa-bad5-9528c6682dde) 7 | 8 | 9 | That's all so far :) 10 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/README.md: -------------------------------------------------------------------------------- 1 | ## Todo app 2 | 3 | This project contains a simple todo application 4 | 5 | - Anyone can create a todo 6 | - Anyone can see their existing todos 7 | - Anyone can mark a todo as done 8 | 9 | // initialize the node project 10 | // put a package.json 11 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/errors.d.ts: -------------------------------------------------------------------------------- 1 | import defaultErrorMap from "./locales/en"; 2 | import type { ZodErrorMap } from "./ZodError"; 3 | export { defaultErrorMap }; 4 | export declare function setErrorMap(map: ZodErrorMap): void; 5 | export declare function getErrorMap(): ZodErrorMap; 6 | -------------------------------------------------------------------------------- /week-6/1-use-memo/src/main.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App.jsx' 4 | import './index.css' 5 | 6 | ReactDOM.createRoot(document.getElementById('root')).render( 7 | 8 | 9 | , 10 | ) 11 | -------------------------------------------------------------------------------- /week-6/3-use-ref/src/main.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App.jsx' 4 | import './index.css' 5 | 6 | ReactDOM.createRoot(document.getElementById('root')).render( 7 | 8 | 9 | , 10 | ) 11 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/src/main.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App.tsx' 4 | import './index.css' 5 | 6 | ReactDOM.createRoot(document.getElementById('root')!).render( 7 | 8 | 9 | , 10 | ) 11 | -------------------------------------------------------------------------------- /week-6/2-use-callback/src/main.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App.jsx' 4 | import './index.css' 5 | 6 | ReactDOM.createRoot(document.getElementById('root')).render( 7 | 8 | 9 | , 10 | ) 11 | -------------------------------------------------------------------------------- /week-7/assignments/all/src/main.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App.jsx' 4 | import './index.css' 5 | 6 | ReactDOM.createRoot(document.getElementById('root')).render( 7 | 8 | 9 | , 10 | ) 11 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/main.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App.tsx' 4 | import './index.css' 5 | 6 | ReactDOM.createRoot(document.getElementById('root')!).render( 7 | 8 | 9 | , 10 | ) 11 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "skipLibCheck": true, 5 | "module": "ESNext", 6 | "moduleResolution": "bundler", 7 | "allowSyntheticDefaultImports": true, 8 | "strict": true 9 | }, 10 | "include": ["vite.config.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/src/main.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App.jsx' 4 | import './index.css' 5 | 6 | ReactDOM.createRoot(document.getElementById('root')).render( 7 | 8 | 9 | , 10 | ) 11 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "skipLibCheck": true, 5 | "module": "ESNext", 6 | "moduleResolution": "bundler", 7 | "allowSyntheticDefaultImports": true, 8 | "strict": true 9 | }, 10 | "include": ["vite.config.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/backend/routes/index.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const userRouter = require("./user"); 3 | const accountRouter = require("./account"); 4 | 5 | const router = express.Router(); 6 | 7 | router.use("/user", userRouter); 8 | router.use("/account", accountRouter); 9 | 10 | module.exports = router; 11 | -------------------------------------------------------------------------------- /week-6/3-use-ref/src/App.jsx: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import { Assignment1 } from "./components/Assignment1"; 3 | import { Assignment2 } from "./components/Assignment2"; 4 | 5 | function App() { 6 | return ( 7 | <> 8 | {/* */} 9 | 10 | 11 | ); 12 | } 13 | 14 | export default App; 15 | -------------------------------------------------------------------------------- /week-7/assignments/all/src/App.jsx: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | // import Assignment1 from "./components/Assignment1"; 3 | import Assignment2 from "./components/Assignment2"; 4 | 5 | function App() { 6 | return ( 7 | <> 8 | {/* */} 9 | 10 | 11 | ); 12 | } 13 | 14 | export default App; 15 | -------------------------------------------------------------------------------- /week-6/2-use-callback/src/App.jsx: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import { Assignment1 } from "./components/Assignment1"; 3 | import { Assignment2 } from "./components/Assignment2"; 4 | 5 | function App() { 6 | return ( 7 | <> 8 | {/* */} 9 | 10 | 11 | ); 12 | } 13 | 14 | export default App; 15 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/backend/types.js: -------------------------------------------------------------------------------- 1 | const zod = require("zod"); 2 | 3 | const createTodo = zod.object({ 4 | title: zod.string(), 5 | description: zod.string(), 6 | }); 7 | 8 | const updateTodo = zod.object({ 9 | id: zod.string(), 10 | }); 11 | 12 | module.exports = { 13 | createTodo: createTodo, 14 | updateTodo: updateTodo, 15 | }; 16 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vite"; 2 | import react from "@vitejs/plugin-react"; 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | server: { 8 | port: 3000, 9 | strictPort: false, 10 | watch: { 11 | usePolling: true, 12 | }, 13 | }, 14 | }); 15 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/backend/index.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const cors = require("cors"); 3 | const rootRouter = require("./routes/index"); 4 | 5 | const app = express(); 6 | 7 | app.use(cors()); 8 | app.use(express.json()); 9 | 10 | app.use("/api/v1", rootRouter); 11 | 12 | app.listen(5000, () => { 13 | console.log("Server started at PORT 5000"); 14 | }); 15 | -------------------------------------------------------------------------------- /week-13/blog-stack/backend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "module": "ESNext", 5 | "moduleResolution": "Bundler", 6 | "strict": true, 7 | "lib": [ 8 | "ESNext" 9 | ], 10 | "types": [ 11 | "@cloudflare/workers-types" 12 | ], 13 | "jsx": "react-jsx", 14 | "jsxImportSource": "hono/jsx" 15 | }, 16 | } -------------------------------------------------------------------------------- /week-6/1-use-memo/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /week-6/3-use-ref/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@sai48/medium-validate2", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "dist/index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "zod": "^3.22.4" 14 | } 15 | } -------------------------------------------------------------------------------- /week-16/Auth/frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /week-6/2-use-callback/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /week-7/assignments/all/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/helpers/errorUtil.d.ts: -------------------------------------------------------------------------------- 1 | export declare namespace errorUtil { 2 | type ErrMessage = string | { 3 | message?: string; 4 | }; 5 | const errToObj: (message?: ErrMessage | undefined) => { 6 | message?: string | undefined; 7 | }; 8 | const toString: (message?: ErrMessage | undefined) => string | undefined; 9 | } 10 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /week-2/async-js/easy/counter2.md: -------------------------------------------------------------------------------- 1 | ## Counter without setInterval 2 | 3 | Without using setInterval, try to code a counter in Javascript. There is a hint at the bottom of the file if you get stuck. 4 | 5 | function counter(seconds) { 6 | console.log(seconds); 7 | if (seconds > 0) { 8 | setTimeout(function() { 9 | counter(seconds - 1); 10 | }, 1000); 11 | } 12 | } 13 | 14 | counter(10); 15 | 16 | (Hint: setTimeout) 17 | -------------------------------------------------------------------------------- /week-2/async-js/hard/promisify-setTimeout.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function that returns a promise that resolves after n seconds have passed, where n is passed as an argument to the function. 3 | */ 4 | 5 | function wait(n) { 6 | return new Promise((resolve) => { 7 | setTimeout(() => { 8 | resolve(`Promise resolved after ${n} seconds`); 9 | }, n * 1000); 10 | }); 11 | } 12 | 13 | module.exports = wait; 14 | -------------------------------------------------------------------------------- /week-2/async-js/easy/counter.md: -------------------------------------------------------------------------------- 1 | ## Create a counter in JavaScript 2 | 3 | We have already covered this in the second lesson, but as an easy recap try to code a counter in Javascript 4 | It should go up as time goes by in intervals of 1 second 5 | 6 | let a = 0; 7 | const val = setInterval(()=> { 8 | a += 1; 9 | 10 | if (a >= 10){ 11 | clearInterval(val) 12 | console.log("stoppped) 13 | } 14 | console.log(val) 15 | }, 1000); 16 | -------------------------------------------------------------------------------- /week-6/1-use-memo/src/App.jsx: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import { Assignment1 } from "./components/Assignment1"; 3 | import { Assignment2 } from "./components/Assignment2"; 4 | import { Assignment3 } from "./components/Assignment3"; 5 | 6 | function App() { 7 | return ( 8 | <> 9 | {/* */} 10 | {/* */} 11 | 12 | 13 | ); 14 | } 15 | 16 | export default App; 17 | -------------------------------------------------------------------------------- /week-6/1-use-memo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /week-6/3-use-ref/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /week-6/2-use-callback/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /week-7/assignments/all/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React + TS 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React + TS 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/main.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom/client"; 3 | import App from "./App.jsx"; 4 | import "./index.css"; 5 | import { ToastContainer } from "react-toastify"; 6 | import "react-toastify/dist/ReactToastify.css"; 7 | 8 | ReactDOM.createRoot(document.getElementById("root")).render( 9 | 10 | 11 | 12 | 13 | ); 14 | -------------------------------------------------------------------------------- /week-13/blog-stack/backend/wrangler.toml: -------------------------------------------------------------------------------- 1 | name = "backend" 2 | compatibility_date = "2023-12-01" 3 | 4 | [vars] 5 | DATABASE_URL= "" 6 | JWT_SECRET= "" 7 | 8 | # [[kv_namespaces]] 9 | # binding = "MY_KV_NAMESPACE" 10 | # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 11 | 12 | # [[r2_buckets]] 13 | # binding = "MY_BUCKET" 14 | # bucket_name = "my-bucket" 15 | 16 | # [[d1_databases]] 17 | # binding = "DB" 18 | # database_name = "my-database" 19 | # database_id = "" 20 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Mini Paytm 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/components/Button.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react/prop-types */ 2 | export function Button({ label, onClick }) { 3 | return ( 4 | 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /week-13/blog-stack/backend/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Hono } from 'hono' 2 | import { userRouter } from './routes/user'; 3 | import { blogRouter } from './routes/blog'; 4 | import { cors } from 'hono/cors' 5 | 6 | const app = new Hono<{ 7 | Bindings: { 8 | DATABASE_URL: string; 9 | JWT_SECRET: string; 10 | } 11 | }>(); 12 | app.use('/*', cors()) 13 | app.route("/api/v1/user", userRouter); 14 | app.route("/api/v1/blog", blogRouter); 15 | 16 | export default app 17 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/components/BottomWarning.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react/prop-types */ 2 | import { Link } from "react-router-dom"; 3 | 4 | export function BottomWarning({ label, buttonText, to }) { 5 | return ( 6 |
7 |
{label}
8 | 9 | {buttonText} 10 | 11 |
12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /week-3/mongo-with-jwt-auth/index.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const bodyParser = require("body-parser"); 3 | const app = express(); 4 | const adminRouter = require("./routes/admin"); 5 | const userRouter = require("./routes/user"); 6 | 7 | app.use(bodyParser.json()); 8 | app.use("/admin", adminRouter); 9 | app.use("/user", userRouter); 10 | 11 | const PORT = 3000; 12 | app.listen(PORT, () => { 13 | console.log(`Server is running on port ${PORT}`); 14 | }); 15 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/components/InputBox.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react/prop-types */ 2 | export function InputBox({ label, placeholder, onChange }) { 3 | return ( 4 |
5 |
{label}
6 | 11 |
12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/pages/Signin.tsx: -------------------------------------------------------------------------------- 1 | import { Auth } from "../components/Auth" 2 | import { Quote } from "../components/Quote" 3 | 4 | export const Signin = () => { 5 | return
6 |
7 |
8 | 9 |
10 |
11 | 12 |
13 |
14 |
15 | } -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/pages/Signup.tsx: -------------------------------------------------------------------------------- 1 | import { Auth } from "../components/Auth" 2 | import { Quote } from "../components/Quote" 3 | 4 | export const Signup = () => { 5 | return
6 |
7 |
8 | 9 |
10 |
11 | 12 |
13 |
14 |
15 | } -------------------------------------------------------------------------------- /week-9/typescript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typescript", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "dev": "npx tsc index.ts && node index.js" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "@types/express": "^4.17.21", 15 | "@types/react": "^18.2.60", 16 | "react": "^18.2.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /week-6/1-use-memo/README.md: -------------------------------------------------------------------------------- 1 | # React + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | -------------------------------------------------------------------------------- /week-6/3-use-ref/README.md: -------------------------------------------------------------------------------- 1 | # React + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | -------------------------------------------------------------------------------- /week-6/2-use-callback/README.md: -------------------------------------------------------------------------------- 1 | # React + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | -------------------------------------------------------------------------------- /week-7/assignments/all/README.md: -------------------------------------------------------------------------------- 1 | # React + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "todo-backend", 3 | "version": "1.0.0", 4 | "description": "This is simple simple todo application", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "cors": "^2.8.5", 13 | "dotenv": "^16.4.2", 14 | "express": "^4.18.2", 15 | "mongoose": "^8.1.1", 16 | "zod": "^3.22.4" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/README.md: -------------------------------------------------------------------------------- 1 | # React + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/README.md: -------------------------------------------------------------------------------- 1 | # React + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | -------------------------------------------------------------------------------- /week-3/mongo/index.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const bodyParser = require("body-parser"); 3 | const app = express(); 4 | const adminRouter = require("./routes/admin"); 5 | const userRouter = require("./routes/user"); 6 | 7 | // Middleware for parsing request bodies 8 | app.use(bodyParser.json()); 9 | app.use("/admin", adminRouter); 10 | app.use("/user", userRouter); 11 | 12 | const PORT = 3000; 13 | 14 | app.listen(PORT, () => { 15 | console.log(`Server is running on port ${PORT}`); 16 | }); 17 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/helpers/errorUtil.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.errorUtil = void 0; 4 | var errorUtil; 5 | (function (errorUtil) { 6 | errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {}; 7 | errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message; 8 | })(errorUtil = exports.errorUtil || (exports.errorUtil = {})); 9 | -------------------------------------------------------------------------------- /week-3/mongo/middleware/user.js: -------------------------------------------------------------------------------- 1 | const { User } = require("../db"); 2 | 3 | function userMiddleware(req, res, next) { 4 | const username = req.headers.username; 5 | const password = req.headers.password; 6 | 7 | User.findOne({ 8 | username: username, 9 | password: password, 10 | }).then(function (value) { 11 | if (value) { 12 | next(); 13 | } else { 14 | res.status(403).json({ 15 | msg: "User doesnt exist", 16 | }); 17 | } 18 | }); 19 | } 20 | 21 | module.exports = userMiddleware; 22 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:@typescript-eslint/recommended', 7 | 'plugin:react-hooks/recommended', 8 | ], 9 | ignorePatterns: ['dist', '.eslintrc.cjs'], 10 | parser: '@typescript-eslint/parser', 11 | plugins: ['react-refresh'], 12 | rules: { 13 | 'react-refresh/only-export-components': [ 14 | 'warn', 15 | { allowConstantExport: true }, 16 | ], 17 | }, 18 | } 19 | -------------------------------------------------------------------------------- /week-3/mongo/middleware/admin.js: -------------------------------------------------------------------------------- 1 | const { Admin } = require("../db"); 2 | 3 | function adminMiddleware(req, res, next) { 4 | const username = req.headers.username; 5 | const password = req.headers.password; 6 | 7 | Admin.findOne({ 8 | username: username, 9 | password: password, 10 | }).then(function (value) { 11 | if (value) { 12 | next(); 13 | } else { 14 | res.status(403).json({ 15 | msg: "Admin doesnt exist", 16 | }); 17 | } 18 | }); 19 | } 20 | 21 | module.exports = adminMiddleware; 22 | -------------------------------------------------------------------------------- /week-3/mongo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "03-mongo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "@babel/plugin-transform-modules-commonjs": "^7.23.3", 14 | "express": "^4.18.2", 15 | "jest": "^29.7.0", 16 | "mongoose": "^8.0.3", 17 | "supertest": "^6.3.3", 18 | "ts-node": "^10.9.2" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:@typescript-eslint/recommended', 7 | 'plugin:react-hooks/recommended', 8 | ], 9 | ignorePatterns: ['dist', '.eslintrc.cjs'], 10 | parser: '@typescript-eslint/parser', 11 | plugins: ['react-refresh'], 12 | rules: { 13 | 'react-refresh/only-export-components': [ 14 | 'warn', 15 | { allowConstantExport: true }, 16 | ], 17 | }, 18 | } 19 | -------------------------------------------------------------------------------- /week-1/problems/easy/findLargestElement.js: -------------------------------------------------------------------------------- 1 | /* 2 |   Write a function `findLargestElement` that takes an array of numbers and returns the largest element. 3 |   Example: 4 |   - Input: [3, 7, 2, 9, 1] 5 |   - Output: 9 6 | */ 7 | 8 | function findLargestElement(numbers) { 9 | max_num = 0; 10 | for (let i = 0; i < numbers.length; i++) { 11 | if (numbers[i] > max_num) { 12 | max_num = numbers[i]; 13 | } 14 | } 15 | return max_num; 16 | } 17 | console.log(findLargestElement([3, 7, 2, 9, 1])); 18 | 19 | module.exports = findLargestElement; 20 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/components/Balance.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react/prop-types */ 2 | import Loader from "../components/Loader"; 3 | const { BalanceLoader } = Loader; 4 | export const Balance = ({ value, isLoading }) => { 5 | return ( 6 |
7 |
Your balance
8 | {isLoading ? ( 9 | 10 | ) : ( 11 |
Rs {value}/-
12 | )} 13 |
14 | ); 15 | }; 16 | -------------------------------------------------------------------------------- /week-13/blog-stack/backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "dev": "wrangler dev src/index.ts", 4 | "deploy": "wrangler deploy --minify src/index.ts" 5 | }, 6 | "dependencies": { 7 | "@prisma/client": "^5.10.2", 8 | "@prisma/extension-accelerate": "^1.0.0", 9 | "@sai48/medium-validate": "^1.0.0", 10 | "@sai48/medium-validate2": "^1.0.0", 11 | "hono": "^4.0.9", 12 | "prisma": "^5.10.2" 13 | }, 14 | "devDependencies": { 15 | "@cloudflare/workers-types": "^4.20240208.0", 16 | "wrangler": "^3.31.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/.package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validatecommon", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "node_modules/zod": { 8 | "version": "3.22.4", 9 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz", 10 | "integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==", 11 | "funding": { 12 | "url": "https://github.com/sponsors/colinhacks" 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/__tests__/Mocker.d.ts: -------------------------------------------------------------------------------- 1 | export declare class Mocker { 2 | pick: (...args: any[]) => any; 3 | get string(): string; 4 | get number(): number; 5 | get bigint(): bigint; 6 | get boolean(): boolean; 7 | get date(): Date; 8 | get symbol(): symbol; 9 | get null(): null; 10 | get undefined(): undefined; 11 | get stringOptional(): any; 12 | get stringNullable(): any; 13 | get numberOptional(): any; 14 | get numberNullable(): any; 15 | get booleanOptional(): any; 16 | get booleanNullable(): any; 17 | } 18 | -------------------------------------------------------------------------------- /week-3/mongo-with-jwt-auth/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "03-mongo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "@babel/plugin-transform-modules-commonjs": "^7.23.3", 14 | "bcrypt": "^5.1.1", 15 | "express": "^4.18.2", 16 | "jest": "^29.7.0", 17 | "jsonwebtoken": "^9.0.2", 18 | "mongoose": "^8.0.3", 19 | "supertest": "^6.3.3", 20 | "ts-node": "^10.9.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /week-16/Auth/backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "week-16-auth", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "npx tsc -b", 8 | "start": "node dist/index.js" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "@types/cookie-parser": "^1.4.7", 15 | "@types/cors": "^2.8.17", 16 | "@types/express": "^4.17.21", 17 | "@types/jsonwebtoken": "^9.0.6", 18 | "cookie-parser": "^1.4.6", 19 | "cors": "^2.8.5", 20 | "express": "^4.18.3", 21 | "jsonwebtoken": "^9.0.2" 22 | } 23 | } -------------------------------------------------------------------------------- /week-16/Auth/frontend/src/App.tsx: -------------------------------------------------------------------------------- 1 | import './App.css' 2 | 3 | import { BrowserRouter, Route, Routes } from "react-router-dom"; 4 | import { Signup } from './components/Signup'; 5 | import { Signin } from './components/Signin'; 6 | import { User } from './components/User'; 7 | 8 | function App() { 9 | return ( 10 | 11 | 12 | } /> 13 | } /> 14 | } /> 15 | 16 | 17 | ) 18 | } 19 | 20 | export default App 21 | -------------------------------------------------------------------------------- /week-1/basics/numbers.js: -------------------------------------------------------------------------------- 1 | function explainParseInt(value) { 2 | console.log("Original Value:", value); 3 | let result = parseInt(value); 4 | console.log("After parseInt:", result); 5 | } 6 | 7 | // Example Usage for parseInt 8 | explainParseInt("42"); 9 | explainParseInt("42px"); 10 | explainParseInt("3.14"); 11 | 12 | function explainParseFloat(value) { 13 | console.log("Original Value:", value); 14 | let result = parseFloat(value); 15 | console.log("After parseFloat:", result); 16 | } 17 | 18 | // Example Usage for parseFloat 19 | explainParseFloat("3.14"); 20 | explainParseFloat("42"); 21 | explainParseFloat("42px"); 22 | -------------------------------------------------------------------------------- /week-6/1-use-memo/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:react/recommended', 7 | 'plugin:react/jsx-runtime', 8 | 'plugin:react-hooks/recommended', 9 | ], 10 | ignorePatterns: ['dist', '.eslintrc.cjs'], 11 | parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, 12 | settings: { react: { version: '18.2' } }, 13 | plugins: ['react-refresh'], 14 | rules: { 15 | 'react-refresh/only-export-components': [ 16 | 'warn', 17 | { allowConstantExport: true }, 18 | ], 19 | }, 20 | } 21 | -------------------------------------------------------------------------------- /week-6/3-use-ref/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:react/recommended', 7 | 'plugin:react/jsx-runtime', 8 | 'plugin:react-hooks/recommended', 9 | ], 10 | ignorePatterns: ['dist', '.eslintrc.cjs'], 11 | parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, 12 | settings: { react: { version: '18.2' } }, 13 | plugins: ['react-refresh'], 14 | rules: { 15 | 'react-refresh/only-export-components': [ 16 | 'warn', 17 | { allowConstantExport: true }, 18 | ], 19 | }, 20 | } 21 | -------------------------------------------------------------------------------- /week-6/2-use-callback/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:react/recommended', 7 | 'plugin:react/jsx-runtime', 8 | 'plugin:react-hooks/recommended', 9 | ], 10 | ignorePatterns: ['dist', '.eslintrc.cjs'], 11 | parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, 12 | settings: { react: { version: '18.2' } }, 13 | plugins: ['react-refresh'], 14 | rules: { 15 | 'react-refresh/only-export-components': [ 16 | 'warn', 17 | { allowConstantExport: true }, 18 | ], 19 | }, 20 | } 21 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backend", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "nodemon index.js" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "bcrpyt": "^2.0.0", 15 | "bcrypt": "^5.1.1", 16 | "cors": "^2.8.5", 17 | "dotenv": "^16.4.5", 18 | "express": "^4.18.2", 19 | "jsonwebtoken": "^9.0.2", 20 | "mongoose": "^8.1.3", 21 | "nodemon": "^3.0.3", 22 | "zod": "^3.22.4" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /week-1/basics/json.js: -------------------------------------------------------------------------------- 1 | function jsonMethods(jsonString) { 2 | console.log("Original JSON String:", jsonString); 3 | 4 | // Parsing JSON string to JavaScript object 5 | let parsedObject = JSON.parse(jsonString); 6 | console.log("After JSON.parse():", parsedObject); 7 | 8 | // Stringifying JavaScript object to JSON string 9 | let jsonStringified = JSON.stringify(parsedObject); 10 | console.log("After JSON.stringify():", jsonStringified); 11 | } 12 | 13 | // Example Usage for JSON Methods 14 | const sampleJSONString = 15 | '{"key": "value", "number": 42, "nested": {"nestedKey": "nestedValue"}}'; 16 | 17 | jsonMethods(sampleJSONString); 18 | -------------------------------------------------------------------------------- /week-13/blog-stack/backend/prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | generator client { 2 | provider = "prisma-client-js" 3 | } 4 | 5 | datasource db { 6 | provider = "postgresql" 7 | url = env("DATABASE_URL") 8 | } 9 | 10 | model User { 11 | id Int @id @default(autoincrement()) 12 | name String? 13 | username String @unique 14 | password String 15 | blogs Blog[] 16 | } 17 | 18 | model Blog { 19 | id Int @id @default(autoincrement()) 20 | authorId Int 21 | content String 22 | title String 23 | published Boolean @default(false) 24 | author User @relation(fields: [authorId], references: [id]) 25 | } 26 | -------------------------------------------------------------------------------- /week-1/problems/medium/palindrome.js: -------------------------------------------------------------------------------- 1 | /* 2 | Implement a function `isPalindrome` which takes a string as argument and returns true/false as its result. 3 | Note: the input string is case-insensitive which means 'Nan' is a palindrom as 'N' and 'n' are considered case-insensitive. 4 | */ 5 | 6 | function isPalindrome(str) { 7 | newStr = ""; 8 | for (let i = str.length - 1; i >= 0; i--) { 9 | newStr += str[i].toLowerCase(); 10 | } 11 | console.log(newStr); 12 | if (str.toLowerCase() == newStr) { 13 | return true; 14 | } else { 15 | return false; 16 | } 17 | } 18 | 19 | console.log(isPalindrome("Nan")); 20 | 21 | module.exports = isPalindrome; 22 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/backend/db.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | require("dotenv").config(); 3 | 4 | mongoose 5 | .connect(process.env.MONGO_URL, { 6 | useNewUrlParser: true, 7 | useUnifiedTopology: true, 8 | }) 9 | .then(() => console.log("Connected to MongoDB")) 10 | .catch((err) => console.error("Error connecting to MongoDB:", err)); 11 | 12 | const todosSchema = mongoose.Schema({ 13 | title: String, 14 | description: String, 15 | completed: { 16 | type: Boolean, 17 | default: false, 18 | }, 19 | }); 20 | 21 | const todo = mongoose.model("todos", todosSchema); 22 | 23 | module.exports = { 24 | todo: todo, 25 | }; 26 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/backend/middleware.js: -------------------------------------------------------------------------------- 1 | const { JWT_SECRET } = require("./config"); 2 | const jwt = require("jsonwebtoken"); 3 | 4 | const authMiddleware = (req, res, next) => { 5 | const authHeader = req.headers.authorization; 6 | if (!authHeader || !authHeader.startsWith("Bearer ")) { 7 | return res.status(403).json({}); 8 | } 9 | 10 | const token = authHeader.split(" ")[1]; 11 | 12 | try { 13 | const decoded = jwt.verify(token, JWT_SECRET); 14 | 15 | req.userId = decoded.userId; 16 | 17 | next(); 18 | } catch (err) { 19 | return res.status(403).json({}); 20 | } 21 | }; 22 | 23 | module.exports = { 24 | authMiddleware, 25 | }; 26 | -------------------------------------------------------------------------------- /week-7/assignments/all/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:react/recommended', 7 | 'plugin:react/jsx-runtime', 8 | 'plugin:react-hooks/recommended', 9 | ], 10 | ignorePatterns: ['dist', '.eslintrc.cjs'], 11 | parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, 12 | settings: { react: { version: '18.2' } }, 13 | plugins: ['react-refresh'], 14 | rules: { 15 | 'react/jsx-no-target-blank': 'off', 16 | 'react-refresh/only-export-components': [ 17 | 'warn', 18 | { allowConstantExport: true }, 19 | ], 20 | }, 21 | } 22 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/helpers/enumUtil.d.ts: -------------------------------------------------------------------------------- 1 | export declare namespace enumUtil { 2 | type UnionToIntersectionFn = (T extends unknown ? (k: () => T) => void : never) extends (k: infer Intersection) => void ? Intersection : never; 3 | type GetUnionLast = UnionToIntersectionFn extends () => infer Last ? Last : never; 4 | type UnionToTuple = [T] extends [never] ? Tuple : UnionToTuple>, [GetUnionLast, ...Tuple]>; 5 | type CastToStringTuple = T extends [string, ...string[]] ? T : never; 6 | export type UnionToTupleString = CastToStringTuple>; 7 | export {}; 8 | } 9 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:react/recommended', 7 | 'plugin:react/jsx-runtime', 8 | 'plugin:react-hooks/recommended', 9 | ], 10 | ignorePatterns: ['dist', '.eslintrc.cjs'], 11 | parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, 12 | settings: { react: { version: '18.2' } }, 13 | plugins: ['react-refresh'], 14 | rules: { 15 | 'react/jsx-no-target-blank': 'off', 16 | 'react-refresh/only-export-components': [ 17 | 'warn', 18 | { allowConstantExport: true }, 19 | ], 20 | }, 21 | } 22 | -------------------------------------------------------------------------------- /week-1/problems/medium/countVowels.js: -------------------------------------------------------------------------------- 1 | /* 2 | Implement a function `countVowels` that takes a string as an argument and returns the number of vowels in the string. 3 | Note: Consider both uppercase and lowercase vowels ('a', 'e', 'i', 'o', 'u'). 4 | 5 | Once you've implemented the logic, test your code by running 6 | */ 7 | 8 | function countVowels(str) { 9 | count = 0; 10 | let volwel = ["a", "e", "i", "o", "u"]; 11 | for (let i = 0; i < str.length; i++) { 12 | if (volwel.includes(str[i])) { 13 | count += 1; 14 | } 15 | } 16 | return count; 17 | } 18 | 19 | console.log(countVowels("sai")); 20 | console.log(countVowels("working as expected")); 21 | 22 | module.exports = countVowels; 23 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | "eslint:recommended", 6 | "plugin:react/recommended", 7 | "plugin:react/jsx-runtime", 8 | "plugin:react-hooks/recommended", 9 | ], 10 | ignorePatterns: ["dist", ".eslintrc.cjs"], 11 | parserOptions: { ecmaVersion: "latest", sourceType: "module" }, 12 | settings: { react: { version: "18.2" } }, 13 | plugins: ["react-refresh"], 14 | rules: { 15 | "react/jsx-no-target-blank": "off", 16 | "react-refresh/only-export-components": [ 17 | "warn", 18 | { allowConstantExport: true }, 19 | ], 20 | "react/prop-types": "off", 21 | }, 22 | }; 23 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/errors.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | exports.getErrorMap = exports.setErrorMap = exports.defaultErrorMap = void 0; 7 | const en_1 = __importDefault(require("./locales/en")); 8 | exports.defaultErrorMap = en_1.default; 9 | let overrideErrorMap = en_1.default; 10 | function setErrorMap(map) { 11 | overrideErrorMap = map; 12 | } 13 | exports.setErrorMap = setErrorMap; 14 | function getErrorMap() { 15 | return overrideErrorMap; 16 | } 17 | exports.getErrorMap = getErrorMap; 18 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 6 | "module": "ESNext", 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "noEmit": true, 15 | "jsx": "react-jsx", 16 | 17 | /* Linting */ 18 | "strict": true, 19 | "noUnusedLocals": true, 20 | "noUnusedParameters": true, 21 | "noFallthroughCasesInSwitch": true 22 | }, 23 | "include": ["src"], 24 | "references": [{ "path": "./tsconfig.node.json" }] 25 | } 26 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 6 | "module": "ESNext", 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "noEmit": true, 15 | "jsx": "react-jsx", 16 | 17 | /* Linting */ 18 | "strict": true, 19 | "noUnusedLocals": true, 20 | "noUnusedParameters": true, 21 | "noFallthroughCasesInSwitch": true 22 | }, 23 | "include": ["src"], 24 | "references": [{ "path": "./tsconfig.node.json" }] 25 | } 26 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validatecommon", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "validatecommon", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "zod": "^3.22.4" 13 | } 14 | }, 15 | "node_modules/zod": { 16 | "version": "3.22.4", 17 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz", 18 | "integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==", 19 | "funding": { 20 | "url": "https://github.com/sponsors/colinhacks" 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /week-6/3-use-ref/src/components/Assignment1.jsx: -------------------------------------------------------------------------------- 1 | import { useRef } from "react"; 2 | import { useEffect } from "react"; 3 | 4 | // Create a component with a text input field and a button. When the component mounts or the button is clicked, automatically focus the text input field using useRef. 5 | 6 | export function Assignment1() { 7 | const inputRef = useRef(); 8 | 9 | useEffect(() => { 10 | inputRef.current.focus(); 11 | }, [inputRef]); 12 | 13 | const handleButtonClick = () => { 14 | inputRef.current.focus(); 15 | }; 16 | 17 | return ( 18 |
19 | 20 | 21 |
22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /week-3/mongo-with-jwt-auth/middleware/admin.js: -------------------------------------------------------------------------------- 1 | const { JWT_SECRET } = require("../config"); 2 | const jwt = require("jsonwebtoken"); 3 | 4 | function adminMiddleware(req, res, next) { 5 | const token = req.headers.authorization; 6 | const words = token.split(" "); 7 | const jwtToken = words[1]; 8 | 9 | try { 10 | const decodedValue = jwt.verify(jwtToken, JWT_SECRET); 11 | if (decodedValue.username) { 12 | req.username = decodedValue.username; 13 | next(); 14 | } else { 15 | res.status(403).json({ 16 | msg: "You are not authenticated", 17 | }); 18 | } 19 | } catch (e) { 20 | res.json({ 21 | msg: "Incorrect inputs", 22 | }); 23 | } 24 | } 25 | 26 | module.exports = adminMiddleware; 27 | -------------------------------------------------------------------------------- /week-5/ReadME.md: -------------------------------------------------------------------------------- 1 | You have to create a simple React App which has a reusable Card Component which has the following 2 | 3 | - Ability to pass in props to the Component 4 | - The Card must show a person's 5 | - Name 6 | - A short description 7 | - LinkedIn, Twitter and other Social Media Handle buttons 8 | - Interests Section 9 | - You can assume that this is kind of an e-business card and feel free to put in your creativity 10 | - Additional & Slightly advanced: 11 | - Create a page where you can add these kind of Cards by taking input from the user 12 | - Create a backend server where these cards get stored in a DB and can handle basic CRUD operations 13 | - Give the feature to perform CRUD operations from the frontend (Can be restricted to the admin only as well) 14 | -------------------------------------------------------------------------------- /week-6/1-use-memo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hooks-assignments", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "react": "^18.2.0", 14 | "react-dom": "^18.2.0" 15 | }, 16 | "devDependencies": { 17 | "@types/react": "^18.2.43", 18 | "@types/react-dom": "^18.2.17", 19 | "@vitejs/plugin-react": "^4.2.1", 20 | "eslint": "^8.55.0", 21 | "eslint-plugin-react": "^7.33.2", 22 | "eslint-plugin-react-hooks": "^4.6.0", 23 | "eslint-plugin-react-refresh": "^0.4.5", 24 | "vite": "^5.0.8" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /week-6/3-use-ref/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hooks-assignments", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "react": "^18.2.0", 14 | "react-dom": "^18.2.0" 15 | }, 16 | "devDependencies": { 17 | "@types/react": "^18.2.43", 18 | "@types/react-dom": "^18.2.17", 19 | "@vitejs/plugin-react": "^4.2.1", 20 | "eslint": "^8.55.0", 21 | "eslint-plugin-react": "^7.33.2", 22 | "eslint-plugin-react-hooks": "^4.6.0", 23 | "eslint-plugin-react-refresh": "^0.4.5", 24 | "vite": "^5.0.8" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/src/components/User.tsx: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import { useEffect, useState } from "react" 3 | import { BACKEND_URL } from "../config"; 4 | 5 | export const User = () => { 6 | const [userData, setUserData] = useState(); 7 | 8 | useEffect(() => { 9 | axios.get(`${BACKEND_URL}/user`, { 10 | withCredentials: true, 11 | }) 12 | .then(res => { 13 | setUserData(res.data); 14 | }) 15 | }, []); 16 | 17 | return
18 | You're id is {userData?.userId} 19 |

20 | 25 |
26 | } -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "react": "^18.2.0", 14 | "react-dom": "^18.2.0" 15 | }, 16 | "devDependencies": { 17 | "@types/react": "^18.2.55", 18 | "@types/react-dom": "^18.2.19", 19 | "@vitejs/plugin-react": "^4.2.1", 20 | "eslint": "^8.56.0", 21 | "eslint-plugin-react": "^7.33.2", 22 | "eslint-plugin-react-hooks": "^4.6.0", 23 | "eslint-plugin-react-refresh": "^0.4.5", 24 | "vite": "^5.1.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /week-6/2-use-callback/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hooks-assignments", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "react": "^18.2.0", 14 | "react-dom": "^18.2.0" 15 | }, 16 | "devDependencies": { 17 | "@types/react": "^18.2.43", 18 | "@types/react-dom": "^18.2.17", 19 | "@vitejs/plugin-react": "^4.2.1", 20 | "eslint": "^8.55.0", 21 | "eslint-plugin-react": "^7.33.2", 22 | "eslint-plugin-react-hooks": "^4.6.0", 23 | "eslint-plugin-react-refresh": "^0.4.5", 24 | "vite": "^5.0.8" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /week-3/mongo-with-jwt-auth/middleware/user.js: -------------------------------------------------------------------------------- 1 | const { JWT_SECRET } = require("../config"); 2 | const jwt = require("jsonwebtoken"); 3 | 4 | function userMiddleware(req, res, next) { 5 | const token = req.headers.authorization; 6 | console.log(req.headers); 7 | const words = token.split(" "); 8 | const jwtToken = words[1]; 9 | console.log(jwtToken); 10 | try { 11 | const decodedValue = jwt.verify(jwtToken, JWT_SECRET); 12 | if (decodedValue.username) { 13 | req.username = decodedValue.username; 14 | next(); 15 | } else { 16 | res.status(403).json({ 17 | msg: "You are not authenticated", 18 | }); 19 | } 20 | } catch (e) { 21 | res.json({ 22 | msg: "Incorrect inputs", 23 | }); 24 | } 25 | } 26 | 27 | module.exports = userMiddleware; 28 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/App.tsx: -------------------------------------------------------------------------------- 1 | import { BrowserRouter, Route, Routes } from 'react-router-dom' 2 | import { Signup } from './pages/Signup' 3 | import { Signin } from './pages/Signin' 4 | import { Blog } from './pages/Blog' 5 | import { Blogs } from "./pages/Blogs"; 6 | import { Publish } from './pages/Publish'; 7 | 8 | function App() { 9 | 10 | return ( 11 | <> 12 | 13 | 14 | } /> 15 | } /> 16 | } /> 17 | } /> 18 | } /> 19 | 20 | 21 | 22 | ) 23 | } 24 | 25 | export default App -------------------------------------------------------------------------------- /week-16/Auth/frontend/src/App.css: -------------------------------------------------------------------------------- 1 | #root { 2 | max-width: 1280px; 3 | margin: 0 auto; 4 | padding: 2rem; 5 | text-align: center; 6 | } 7 | 8 | .logo { 9 | height: 6em; 10 | padding: 1.5em; 11 | will-change: filter; 12 | transition: filter 300ms; 13 | } 14 | .logo:hover { 15 | filter: drop-shadow(0 0 2em #646cffaa); 16 | } 17 | .logo.react:hover { 18 | filter: drop-shadow(0 0 2em #61dafbaa); 19 | } 20 | 21 | @keyframes logo-spin { 22 | from { 23 | transform: rotate(0deg); 24 | } 25 | to { 26 | transform: rotate(360deg); 27 | } 28 | } 29 | 30 | @media (prefers-reduced-motion: no-preference) { 31 | a:nth-of-type(2) .logo { 32 | animation: logo-spin infinite 20s linear; 33 | } 34 | } 35 | 36 | .card { 37 | padding: 2em; 38 | } 39 | 40 | .read-the-docs { 41 | color: #888; 42 | } 43 | -------------------------------------------------------------------------------- /week-6/3-use-ref/src/components/Assignment2.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useCallback } from "react"; 2 | import { useRef } from "react"; 3 | 4 | // Create a component that tracks and displays the number of times it has been rendered. 5 | 6 | export function Assignment2() { 7 | const [count, setCount] = useState(0); 8 | 9 | const numberOfTimesReRendered = useRef(0); 10 | 11 | const handleReRender = () => { 12 | // Update state to force re-render 13 | setCount(count + 1); 14 | }; 15 | 16 | numberOfTimesReRendered.current = numberOfTimesReRendered.current + 1; 17 | 18 | return ( 19 |
20 |

21 | This component has rendered {numberOfTimesReRendered.current} times. 22 |

23 | 24 |
25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /week-7/assignments/all/src/App.css: -------------------------------------------------------------------------------- 1 | #root { 2 | max-width: 1280px; 3 | margin: 0 auto; 4 | padding: 2rem; 5 | text-align: center; 6 | } 7 | 8 | .logo { 9 | height: 6em; 10 | padding: 1.5em; 11 | will-change: filter; 12 | transition: filter 300ms; 13 | } 14 | .logo:hover { 15 | filter: drop-shadow(0 0 2em #646cffaa); 16 | } 17 | .logo.react:hover { 18 | filter: drop-shadow(0 0 2em #61dafbaa); 19 | } 20 | 21 | @keyframes logo-spin { 22 | from { 23 | transform: rotate(0deg); 24 | } 25 | to { 26 | transform: rotate(360deg); 27 | } 28 | } 29 | 30 | @media (prefers-reduced-motion: no-preference) { 31 | a:nth-of-type(2) .logo { 32 | animation: logo-spin infinite 20s linear; 33 | } 34 | } 35 | 36 | .card { 37 | padding: 2em; 38 | } 39 | 40 | .read-the-docs { 41 | color: #888; 42 | } 43 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/App.css: -------------------------------------------------------------------------------- 1 | #root { 2 | max-width: 1280px; 3 | margin: 0 auto; 4 | padding: 2rem; 5 | text-align: center; 6 | } 7 | 8 | .logo { 9 | height: 6em; 10 | padding: 1.5em; 11 | will-change: filter; 12 | transition: filter 300ms; 13 | } 14 | .logo:hover { 15 | filter: drop-shadow(0 0 2em #646cffaa); 16 | } 17 | .logo.react:hover { 18 | filter: drop-shadow(0 0 2em #61dafbaa); 19 | } 20 | 21 | @keyframes logo-spin { 22 | from { 23 | transform: rotate(0deg); 24 | } 25 | to { 26 | transform: rotate(360deg); 27 | } 28 | } 29 | 30 | @media (prefers-reduced-motion: no-preference) { 31 | a:nth-of-type(2) .logo { 32 | animation: logo-spin infinite 20s linear; 33 | } 34 | } 35 | 36 | .card { 37 | padding: 2em; 38 | } 39 | 40 | .read-the-docs { 41 | color: #888; 42 | } 43 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/App.css: -------------------------------------------------------------------------------- 1 | #root { 2 | max-width: 1280px; 3 | margin: 0 auto; 4 | padding: 2rem; 5 | text-align: center; 6 | } 7 | 8 | .logo { 9 | height: 6em; 10 | padding: 1.5em; 11 | will-change: filter; 12 | transition: filter 300ms; 13 | } 14 | .logo:hover { 15 | filter: drop-shadow(0 0 2em #646cffaa); 16 | } 17 | .logo.react:hover { 18 | filter: drop-shadow(0 0 2em #61dafbaa); 19 | } 20 | 21 | @keyframes logo-spin { 22 | from { 23 | transform: rotate(0deg); 24 | } 25 | to { 26 | transform: rotate(360deg); 27 | } 28 | } 29 | 30 | @media (prefers-reduced-motion: no-preference) { 31 | a:nth-of-type(2) .logo { 32 | animation: logo-spin infinite 20s linear; 33 | } 34 | } 35 | 36 | .card { 37 | padding: 2em; 38 | } 39 | 40 | .read-the-docs { 41 | color: #888; 42 | } 43 | -------------------------------------------------------------------------------- /week-3/middlewares/reqCount.js: -------------------------------------------------------------------------------- 1 | // You have been given an express server which has a few endpoints. 2 | // Your task is to create a global middleware (app.use) which will 3 | // maintain a count of the number of requests made to the server in the global 4 | // requestCount variable 5 | 6 | const express = require("express"); 7 | 8 | const app = express(); 9 | let requestCount = 0; 10 | 11 | app.use(function (req, res, next) { 12 | requestCount++; 13 | next(); 14 | }); 15 | 16 | app.get("/user", function (req, res) { 17 | res.status(200).json({ name: "john" }); 18 | }); 19 | 20 | app.post("/user", function (req, res) { 21 | res.status(200).json({ msg: "created dummy user" }); 22 | }); 23 | 24 | app.get("/requestCount", function (req, res) { 25 | res.status(200).json({ requestCount }); 26 | }); 27 | 28 | module.exports = app; 29 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/components/Quote.tsx: -------------------------------------------------------------------------------- 1 | 2 | export const Quote = () => { 3 | return
4 |
5 |
6 |
7 | "The customer support I received was exceptional. The support team went above and beyond to address my concerns" 8 |
9 |
10 | Sai Vara Prasad 11 |
12 |
13 | Software Engineer | India 14 |
15 |
16 |
17 | 18 |
19 | } -------------------------------------------------------------------------------- /week-13/blog-stack/backend/prisma/migrations/20240308123022_init_schema/migration.sql: -------------------------------------------------------------------------------- 1 | -- CreateTable 2 | CREATE TABLE "User" ( 3 | "id" SERIAL NOT NULL, 4 | "name" TEXT, 5 | "username" TEXT NOT NULL, 6 | "password" TEXT NOT NULL, 7 | 8 | CONSTRAINT "User_pkey" PRIMARY KEY ("id") 9 | ); 10 | 11 | -- CreateTable 12 | CREATE TABLE "Blog" ( 13 | "id" SERIAL NOT NULL, 14 | "authorId" INTEGER NOT NULL, 15 | "content" TEXT NOT NULL, 16 | "title" TEXT NOT NULL, 17 | "published" BOOLEAN NOT NULL DEFAULT false, 18 | 19 | CONSTRAINT "Blog_pkey" PRIMARY KEY ("id") 20 | ); 21 | 22 | -- CreateIndex 23 | CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); 24 | 25 | -- AddForeignKey 26 | ALTER TABLE "Blog" ADD CONSTRAINT "Blog_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 27 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/src/index.ts: -------------------------------------------------------------------------------- 1 | import z from "zod"; 2 | 3 | export const signupInput = z.object({ 4 | username: z.string().email(), 5 | password: z.string(), 6 | name: z.string().optional(), 7 | }); 8 | 9 | 10 | export const signinInput = z.object({ 11 | username: z.string().email(), 12 | password: z.string(), 13 | }); 14 | 15 | export const createPostInput = z.object({ 16 | title: z.string(), 17 | content: z.string(), 18 | }); 19 | 20 | 21 | export const updatePostInput = z.object({ 22 | title: z.string().optional(), 23 | content: z.string().optional(), 24 | }); 25 | 26 | 27 | export type CreatePostType = z.infer; 28 | export type SigninType = z.infer; 29 | export type SignupType = z.infer; 30 | export type UpdatePostType = z.infer; -------------------------------------------------------------------------------- /week-16/Auth/frontend/src/components/Signup.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from "react" 2 | import { BACKEND_URL } from "../config" 3 | import axios from "axios" 4 | 5 | export const Signup = () => { 6 | const [username, setUsername] = useState("") 7 | const [password, setPassword] = useState("") 8 | 9 | return
10 | { 11 | setUsername(e.target.value); 12 | }} type="text" placeholder="username" /> 13 | { 14 | setPassword(e.target.value); 15 | }} type="password" placeholder="password" /> 16 | 23 |
24 | } -------------------------------------------------------------------------------- /week-7/assignments/all/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "all", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "react": "^18.2.0", 14 | "react-dom": "^18.2.0" 15 | }, 16 | "devDependencies": { 17 | "@types/react": "^18.2.56", 18 | "@types/react-dom": "^18.2.19", 19 | "@vitejs/plugin-react": "^4.2.1", 20 | "autoprefixer": "^10.4.18", 21 | "eslint": "^8.56.0", 22 | "eslint-plugin-react": "^7.33.2", 23 | "eslint-plugin-react-hooks": "^4.6.0", 24 | "eslint-plugin-react-refresh": "^0.4.5", 25 | "postcss": "^8.4.35", 26 | "tailwindcss": "^3.4.1", 27 | "vite": "^5.1.4" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/pages/Blog.tsx: -------------------------------------------------------------------------------- 1 | import { Appbar } from "../components/Appbar"; 2 | import { FullBlog } from "../components/FullBlog"; 3 | import { Spinner } from "../components/Spinner"; 4 | import { useBlog } from "../hooks"; 5 | import {useParams} from "react-router-dom"; 6 | 7 | 8 | export const Blog = () => { 9 | const { id } = useParams(); 10 | const {loading, blog} = useBlog({ 11 | id: id || "" 12 | }); 13 | 14 | if (loading || !blog) { 15 | return
16 | 17 | 18 |
19 | 20 |
21 | 22 |
23 |
24 |
25 | } 26 | return
27 | 28 |
29 | } -------------------------------------------------------------------------------- /week-6/1-use-memo/src/components/Assignment1.jsx: -------------------------------------------------------------------------------- 1 | import { useMemo, useState } from "react"; 2 | 3 | // In this assignment, your task is to create a component that performs an expensive calculation (finding the factorial) based on a user input. 4 | // Use useMemo to ensure that the calculation is only recomputed when the input changes, not on every render. 5 | 6 | export function Assignment1() { 7 | const [input, setInput] = useState(0); 8 | const expensiveValue = useMemo(() => { 9 | let value = 1; 10 | for (let i = 1; i <= input; i++) { 11 | value = value * i; 12 | } 13 | return value; 14 | }, [input]); 15 | 16 | return ( 17 |
18 | setInput(Number(e.target.value))} 22 | /> 23 |

Calculated Value: {expensiveValue}

24 |
25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/helpers/partialUtil.d.ts: -------------------------------------------------------------------------------- 1 | import type { ZodArray, ZodNullable, ZodObject, ZodOptional, ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny } from "../index"; 2 | export declare namespace partialUtil { 3 | type DeepPartial = T extends ZodObject ? ZodObject<{ 4 | [k in keyof T["shape"]]: ZodOptional>; 5 | }, T["_def"]["unknownKeys"], T["_def"]["catchall"]> : T extends ZodArray ? ZodArray, Card> : T extends ZodOptional ? ZodOptional> : T extends ZodNullable ? ZodNullable> : T extends ZodTuple ? { 6 | [k in keyof Items]: Items[k] extends ZodTypeAny ? DeepPartial : never; 7 | } extends infer PI ? PI extends ZodTupleItems ? ZodTuple : never : never : T; 8 | } 9 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/src/components/Signin.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from "react" 2 | import { BACKEND_URL } from "../config" 3 | import axios from "axios" 4 | 5 | export const Signin = () => { 6 | const [username, setUsername] = useState("") 7 | const [password, setPassword] = useState("") 8 | 9 | return
10 | { 11 | setUsername(e.target.value); 12 | }} type="text" placeholder="username" /> 13 | { 14 | setPassword(e.target.value); 15 | }} type="password" placeholder="password" /> 16 | 25 |
26 | } -------------------------------------------------------------------------------- /week-1/basics/math.js: -------------------------------------------------------------------------------- 1 | function mathMethods(value) { 2 | console.log("Original Value:", value); 3 | 4 | let rounded = Math.round(value); 5 | console.log("After round():", rounded); 6 | 7 | let ceiling = Math.ceil(value); 8 | console.log("After ceil():", ceiling); 9 | 10 | let flooring = Math.floor(value); 11 | console.log("After floor():", flooring); 12 | 13 | let randomValue = Math.random(); 14 | console.log("After random():", randomValue); 15 | 16 | let maxValue = Math.max(5, 10, 15); 17 | console.log("After max():", maxValue); 18 | 19 | let minValue = Math.min(5, 10, 15); 20 | console.log("After min():", minValue); 21 | 22 | let powerOfTwo = Math.pow(value, 2); 23 | console.log("After pow():", powerOfTwo); 24 | 25 | let squareRoot = Math.sqrt(value); 26 | console.log("After sqrt():", squareRoot); 27 | } 28 | 29 | // Example Usage for Math Methods 30 | mathMethods(4.56); 31 | mathMethods(9); 32 | mathMethods(25); 33 | -------------------------------------------------------------------------------- /week-1/problems/easy/anagram.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function `isAnagram` which takes 2 parameters and returns true/false if those are anagrams or not. 3 | What's Anagram? 4 | - A word, phrase, or name formed by rearranging the letters of another, such as spar, formed from rasp. 5 | */ 6 | 7 | function isAnagram(str1, str2) { 8 | const formattedStr1 = str1.replace(/\s/g, "").toLowerCase(); 9 | const formattedStr2 = str2.replace(/\s/g, "").toLowerCase(); 10 | 11 | // Check if the length of the strings is the same 12 | if (formattedStr1.length !== formattedStr2.length) { 13 | return false; 14 | } 15 | 16 | // Convert strings to arrays, sort them, and compare if they are equal 17 | const sortedStr1 = formattedStr1.split("").sort().join(""); 18 | const sortedStr2 = formattedStr2.split("").sort().join(""); 19 | 20 | return sortedStr1 === sortedStr2; 21 | } 22 | 23 | console.log(isAnagram("spar", "rasp")); 24 | module.exports = isAnagram; 25 | -------------------------------------------------------------------------------- /week-1/problems/medium/times.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function that calculates the time (in seconds) it takes for the JS code to calculate sum from 1 to n, given n as the input. 3 | Try running it for 4 | 1. Sum from 1-100 5 | 2. Sum from 1-100000 6 | 3. Sum from 1-1000000000 7 | Hint - use Date class exposed in JS 8 | There is no automated test for this one, this is more for you to understand time goes up as computation goes up 9 | */ 10 | 11 | function calculateTime(n) { 12 | const startTime = new Date(); // Record the start time 13 | 14 | let sum = 0; 15 | for (let i = 1; i <= n; i++) { 16 | sum += i; 17 | } 18 | 19 | const endTime = new Date(); // Record the end time 20 | 21 | const elapsedTimeInSeconds = (endTime - startTime) / 1000; // Calculate elapsed time in seconds 22 | return elapsedTimeInSeconds; 23 | } 24 | 25 | console.log(calculateTime(100)); 26 | console.log(calculateTime(100000)); 27 | console.log(calculateTime(1000000000)); 28 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "tsc && vite build", 9 | "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "axios": "^1.6.8", 14 | "react": "^18.2.0", 15 | "react-dom": "^18.2.0", 16 | "react-router-dom": "^6.22.3" 17 | }, 18 | "devDependencies": { 19 | "@types/react": "^18.2.64", 20 | "@types/react-dom": "^18.2.21", 21 | "@typescript-eslint/eslint-plugin": "^7.1.1", 22 | "@typescript-eslint/parser": "^7.1.1", 23 | "@vitejs/plugin-react": "^4.2.1", 24 | "eslint": "^8.57.0", 25 | "eslint-plugin-react-hooks": "^4.6.0", 26 | "eslint-plugin-react-refresh": "^0.4.5", 27 | "typescript": "^5.2.2", 28 | "vite": "^5.1.6" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /week-3/middlewares/errCount.js: -------------------------------------------------------------------------------- 1 | // You have been given an express server which has a few endpoints. 2 | // Your task is to 3 | // 1. Ensure that if there is ever an exception, the end user sees a status code of 404 4 | // 2. Maintain the errorCount variable whose value should go up every time there is an exception in any endpoint 5 | 6 | const express = require("express"); 7 | 8 | const app = express(); 9 | let errorCount = 0; 10 | 11 | app.get("/user", function (req, res) { 12 | throw new Error("some error"); 13 | // 500 14 | res.status(200).json({ name: "john" }); 15 | }); 16 | 17 | app.post("/user", function (req, res) { 18 | res.status(200).json({ msg: "created dummy user" }); 19 | }); 20 | 21 | app.get("/errorCount", function (req, res) { 22 | res.status(200).json({ errorCount }); 23 | }); 24 | 25 | // error handling middleware 26 | app.use(function (err, req, res, next) { 27 | res.status(404).send({}); 28 | errorCount = errorCount + 1; 29 | }); 30 | 31 | module.exports = app; 32 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/external.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 3 | if (k2 === undefined) k2 = k; 4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); 5 | }) : (function(o, m, k, k2) { 6 | if (k2 === undefined) k2 = k; 7 | o[k2] = m[k]; 8 | })); 9 | var __exportStar = (this && this.__exportStar) || function(m, exports) { 10 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | __exportStar(require("./errors"), exports); 14 | __exportStar(require("./helpers/parseUtil"), exports); 15 | __exportStar(require("./helpers/typeAliases"), exports); 16 | __exportStar(require("./helpers/util"), exports); 17 | __exportStar(require("./types"), exports); 18 | __exportStar(require("./ZodError"), exports); 19 | -------------------------------------------------------------------------------- /week-2/async-js/hard/sleep-compeltely.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Write a function that halts the JS thread (make it busy wait) for a given number of milliseconds. 3 | * During this time the thread should not be able to do anything else. 4 | * the function should return a promise just like before 5 | */ 6 | 7 | function sleep(milliseconds) { 8 | return new Promise((resolve) => { 9 | const startTime = Date.now(); 10 | 11 | while (true) { 12 | const currentTime = Date.now(); 13 | if (currentTime - startTime >= milliseconds) { 14 | resolve(`Slept for ${milliseconds} milliseconds`); 15 | console.log(`Slept for ${milliseconds} milliseconds`); 16 | break; 17 | } 18 | // Perform some CPU-intensive operation to keep the thread busy 19 | // Example: A dummy loop that consumes CPU cycles 20 | let a = 0; 21 | for (let i = 0; i < 100; i++) { 22 | a += 1; 23 | console.log(a); 24 | } 25 | } 26 | }); 27 | } 28 | 29 | sleep(10000); 30 | 31 | module.exports = sleep; 32 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "axios": "^1.6.7", 14 | "ldrs": "^1.0.1", 15 | "prop-types": "^15.8.1", 16 | "react": "^18.2.0", 17 | "react-dom": "^18.2.0", 18 | "react-router-dom": "^6.22.1", 19 | "react-toastify": "^10.0.4" 20 | }, 21 | "devDependencies": { 22 | "@types/react": "^18.2.55", 23 | "@types/react-dom": "^18.2.19", 24 | "@vitejs/plugin-react": "^4.2.1", 25 | "autoprefixer": "^10.4.17", 26 | "eslint": "^8.56.0", 27 | "eslint-plugin-react": "^7.33.2", 28 | "eslint-plugin-react-hooks": "^4.6.0", 29 | "eslint-plugin-react-refresh": "^0.4.5", 30 | "postcss": "^8.4.35", 31 | "tailwindcss": "^3.4.1", 32 | "vite": "^5.1.0" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /week-3/mongo/db/index.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | mongoose 4 | .connect("Mongo_URL", 5 | { 6 | useNewUrlParser: true, 7 | } 8 | ) 9 | .then(() => { 10 | console.log("Connected to MongoDB"); 11 | }) 12 | .catch((e) => { 13 | console.log(e); 14 | }); 15 | 16 | // Define schemas 17 | const AdminSchema = new mongoose.Schema({ 18 | username: String, 19 | password: String, 20 | }); 21 | 22 | const UserSchema = new mongoose.Schema({ 23 | username: String, 24 | password: String, 25 | purchasedCourses: [ 26 | { 27 | type: mongoose.Schema.Types.ObjectId, 28 | ref: "Course", 29 | }, 30 | ], 31 | }); 32 | 33 | const CourseSchema = new mongoose.Schema({ 34 | title: String, 35 | description: String, 36 | imageLink: String, 37 | price: Number, 38 | }); 39 | 40 | const Admin = mongoose.model("Admin", AdminSchema); 41 | const User = mongoose.model("User", UserSchema); 42 | const Course = mongoose.model("Course", CourseSchema); 43 | 44 | module.exports = { 45 | Admin, 46 | User, 47 | Course, 48 | }; 49 | -------------------------------------------------------------------------------- /week-6/1-use-memo/src/components/Assignment3.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useMemo } from "react"; 2 | // You have been given a list of items you shopped from the grocery store 3 | // You need to calculate the total amount of money you spent 4 | 5 | export const Assignment3 = () => { 6 | const [items, setItems] = useState([ 7 | { name: "Chocolates", value: 10 }, 8 | { name: "Chips", value: 20 }, 9 | { name: "Onion", value: 30 }, 10 | { name: "Tomato", value: 30 }, 11 | // Add more items as needed 12 | ]); 13 | 14 | // Your code starts here 15 | const total = useMemo(() => { 16 | let totalValue = 0; 17 | for (let i = 0; i < items.length; i++) { 18 | totalValue += items[i].value; 19 | } 20 | return totalValue; 21 | }, [items]); 22 | // Your code ends here 23 | return ( 24 |
25 |
    26 | {items.map((item, index) => ( 27 |
  • 28 | {item.name} - Price: ${item.value} 29 |
  • 30 | ))} 31 |
32 |

Total Value: {total}

33 |
34 | ); 35 | }; 36 | -------------------------------------------------------------------------------- /week-3/mongo-with-jwt-auth/db/index.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | mongoose 4 | .connect( 5 | "MONGO_URL", 6 | { 7 | useNewUrlParser: true, 8 | } 9 | ) 10 | .then(() => { 11 | console.log("Connected to MongoDB"); 12 | }) 13 | .catch((e) => { 14 | console.log(e); 15 | }); 16 | 17 | // Define schemas 18 | const AdminSchema = new mongoose.Schema({ 19 | username: String, 20 | password: String, 21 | }); 22 | 23 | const UserSchema = new mongoose.Schema({ 24 | username: String, 25 | password: String, 26 | purchasedCourses: [ 27 | { 28 | type: mongoose.Schema.Types.ObjectId, 29 | ref: "Course", 30 | }, 31 | ], 32 | }); 33 | 34 | const CourseSchema = new mongoose.Schema({ 35 | title: String, 36 | description: String, 37 | imageLink: String, 38 | price: Number, 39 | }); 40 | 41 | const Admin = mongoose.model("Admin", AdminSchema); 42 | const User = mongoose.model("User", UserSchema); 43 | const Course = mongoose.model("Course", CourseSchema); 44 | 45 | module.exports = { 46 | Admin, 47 | User, 48 | Course, 49 | }; 50 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "tsc && vite build", 9 | "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "@sai48/medium-validate2": "^1.0.0", 14 | "@types/axios": "^0.14.0", 15 | "react": "^18.2.0", 16 | "react-dom": "^18.2.0", 17 | "react-router-dom": "^6.22.3" 18 | }, 19 | "devDependencies": { 20 | "@types/react": "^18.2.56", 21 | "@types/react-dom": "^18.2.19", 22 | "@typescript-eslint/eslint-plugin": "^7.0.2", 23 | "@typescript-eslint/parser": "^7.0.2", 24 | "@vitejs/plugin-react": "^4.2.1", 25 | "autoprefixer": "^10.4.18", 26 | "eslint": "^8.56.0", 27 | "eslint-plugin-react-hooks": "^4.6.0", 28 | "eslint-plugin-react-refresh": "^0.4.5", 29 | "postcss": "^8.4.35", 30 | "tailwindcss": "^3.4.1", 31 | "typescript": "^5.2.2", 32 | "vite": "^5.1.4" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /week-2/async-js/easy/read_from_file.md: -------------------------------------------------------------------------------- 1 | ## Reading the contents of a file 2 | 3 | Write code to read contents of a file and print it to the console. 4 | You can use the fs library to as a black box, the goal is to understand async tasks. 5 | Try to do an expensive operation below the file read and see how it affects the output. 6 | Make the expensive operation more and more expensive and see how it affects the output. 7 | 8 | const fs = require('fs'); 9 | 10 | // Read contents of a file 11 | fs.readFile('a.txt', 'utf8', (err, data) => { 12 | if (err) { 13 | console.error('Error reading the file:', err); 14 | return; 15 | } 16 | 17 | console.log('File Contents:', data); 18 | 19 | // Simulate an expensive operation (CPU-intensive task) 20 | // Example: Calculating Fibonacci series recursively 21 | const fibonacci = (num) => { 22 | if (num <= 1) { 23 | return num; 24 | } 25 | return fibonacci(num - 1) + fibonacci(num - 2); 26 | }; 27 | 28 | const expensiveOperationResult = fibonacci(35); // Adjust the number for higher expenses 29 | console.log('Result of expensive operation:', expensiveOperationResult); 30 | }); 31 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/src/App.jsx: -------------------------------------------------------------------------------- 1 | // import { useState } from "react"; 2 | import { useEffect, useState } from "react"; 3 | import CreateTodo from "./components/CreateTodo"; 4 | import Todos from "./components/Todos"; 5 | 6 | function App() { 7 | const [todos, setTodos] = useState([]); 8 | 9 | const handleUpdateTodoId = (id) => { 10 | // Here you can update the todo ID in the state 11 | // For simplicity, let's just log it 12 | console.log(`Todo with ID ${id} updated`); 13 | }; 14 | 15 | useEffect(() => { 16 | fetch("http://localhost:3000/todos") 17 | .then(async function (res) { 18 | if (!res.ok) { 19 | throw new Error("Failed to fetch todos"); 20 | } 21 | const json = await res.json(); 22 | setTodos(json); 23 | }) 24 | .catch((error) => { 25 | console.error("Error fetching todos:", error); 26 | }); 27 | }); 28 | 29 | return ( 30 |
31 | 32 | 33 |
34 | ); 35 | } 36 | 37 | export default App; 38 | -------------------------------------------------------------------------------- /week-2/async-js/easy/write_from_file.md: -------------------------------------------------------------------------------- 1 | ## Write to a file 2 | 3 | Using the fs library again, try to write to the contents of a file. 4 | You can use the fs library to as a black box, the goal is to understand async tasks. 5 | 6 | const fs = require("fs"); 7 | 8 | ---------------------------------------appendFile 9 | 10 | // Content to write to the file 11 | const content = "Hello, this is a test content to write to a file.\n"; 12 | 13 | // Write content to a file asynchronously 14 | fs.appendFile("a.txt", content, "utf8", (err) => { 15 | if (err) { 16 | console.error("Error writing to the file:", err); 17 | return; 18 | } 19 | console.log("Content has been written to output.txt"); 20 | }); 21 | 22 | -------------------------------writeFile 23 | 24 | // Content to write to the file 25 | const content = "Hello, this is a test content to write to a file.\n"; 26 | 27 | // Write content to a file asynchronously 28 | fs.writeFile("a.txt", content, "utf8", (err) => { 29 | if (err) { 30 | console.error("Error writing to the file:", err); 31 | return; 32 | } 33 | console.log("Content has been written to output.txt"); 34 | }); 35 | -------------------------------------------------------------------------------- /week-16/Cookies.md: -------------------------------------------------------------------------------- 1 | # What are cookies 2 | 3 | ### Cookies in web development are small pieces of data sent from a website and stored on the user's computer by the user's web browser while the user is browsing. They are designed to be a reliable mechanism for websites to remember things (very similar to local storage) 4 | 5 | ## Session Management 6 | 7 | ## Personalization 8 | 9 | ## Tracking & Security 10 | 11 | # Why not local storage? 12 | 13 | ### Cookies and LocalStorage both provide ways to store data on the client-side, but they serve different purposes and have different characteristics. 14 | 15 | ## Cookies are send with every request to the website (by the browser) (you don’t have to explicitly add a header to the fetch call) 16 | 17 | ## Cookies can have an expiry attached to them 18 | 19 | ## Cookies can be be restricted to only https and to certain domains 20 | 21 | # Properties of cookies 22 | 23 | ## Types of cookies 24 | 25 | ### Persistent - Stay even if u close the window 26 | 27 | ### Session - Go away after the window closes 28 | 29 | ### Secure - Sent only over secure, encrypted connections (HTTPS). 30 | -------------------------------------------------------------------------------- /week-3/jwt/index.js: -------------------------------------------------------------------------------- 1 | const jwt = require("jsonwebtoken"); 2 | const jwtPassword = "secret"; 3 | const zod = require("zod"); 4 | 5 | const emailSchema = zod.string().email(); 6 | const passwordSchema = zod.string().min(6); 7 | 8 | function signJwt(username, password) { 9 | const usernameResponse = emailSchema.safeParse(username); // validating using safeParse 10 | const passwordResponse = passwordSchema.safeParse(password); 11 | if (!usernameResponse.success || !passwordResponse.success) { 12 | return null; 13 | } 14 | 15 | const signature = jwt.sign( 16 | { 17 | username, 18 | }, 19 | jwtPassword 20 | ); 21 | 22 | return signature; 23 | } 24 | 25 | function verifyJwt(token) { 26 | let ans = true; 27 | try { 28 | jwt.verify(token, jwtPassword); 29 | } catch (e) { 30 | ans = false; 31 | } 32 | return ans; 33 | } 34 | 35 | function decodeJwt(token) { 36 | // true, false 37 | const decoded = jwt.decode(token); 38 | if (decoded) { 39 | return true; 40 | } else { 41 | return false; 42 | } 43 | } 44 | 45 | module.exports = { 46 | signJwt, 47 | verifyJwt, 48 | decodeJwt, 49 | jwtPassword, 50 | }; 51 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Colin McDonnell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /week-2/async-js/medium/clock.md: -------------------------------------------------------------------------------- 1 | Using `1-counter.md` or `2-counter.md` from the easy section, can you create a 2 | clock that shows you the current machine time? 3 | 4 | Can you make it so that it updates every second, and shows time in the following formats - 5 | 6 | - HH:MM::SS (Eg. 13:45:23) 7 | 8 | - HH:MM::SS AM/PM (Eg 01:45:23 PM) 9 | 10 | function updateClock() { 11 | const now = new Date(); 12 | 13 | // Format for 24-hour clock (HH:MM:SS) 14 | const hours24 = ('0' + now.getHours()).slice(-2); 15 | const minutes = ('0' + now.getMinutes()).slice(-2); 16 | const seconds = ('0' + now.getSeconds()).slice(-2); 17 | const time24 = hours24 + ':' + minutes + ':' + seconds; 18 | 19 | // Format for 12-hour clock (HH:MM:SS AM/PM) 20 | const ampm = now.getHours() >= 12 ? 'PM' : 'AM'; 21 | const hours12 = ('0' + ((now.getHours() % 12) || 12)).slice(-2); 22 | const time12 = hours12 + ':' + minutes + ':' + seconds + ' ' + ampm; 23 | 24 | // Log the time in both formats to the console 25 | console.log('24-hour format:', time24); 26 | console.log('12-hour format:', time12); 27 | } 28 | 29 | // Update the clock every second 30 | setInterval(updateClock, 1000); 31 | 32 | // Initial call to display the clock immediately 33 | updateClock(); 34 | -------------------------------------------------------------------------------- /week-1/basics/class.js: -------------------------------------------------------------------------------- 1 | class Animal { 2 | constructor(name, legCount) { 3 | this.name = name; 4 | this.legCount = legCount; 5 | } 6 | 7 | describe() { 8 | return `${this.name} has ${this.legCount} legs`; 9 | } 10 | 11 | sound(makeSound) { 12 | return `${this.name} makes the sound: ${makeSound}`; 13 | } 14 | 15 | move(moveType) { 16 | return `${this.name} moves by ${moveType}`; 17 | } 18 | } 19 | 20 | const dog = new Animal("Dog", 4); 21 | console.log(dog.describe()); 22 | console.log(dog.sound("barking")); 23 | console.log(dog.move("running")); 24 | 25 | const cat = new Animal("Cat", 4); 26 | console.log(cat.describe()); 27 | console.log(cat.sound("meowing")); 28 | console.log(cat.move("prowling")); 29 | 30 | const bird = new Animal("Bird", 2); 31 | console.log(bird.describe()); 32 | console.log(bird.sound("chirping")); 33 | console.log(bird.move("flying")); 34 | 35 | const elephant = new Animal("Elephant", 4); 36 | console.log(elephant.describe()); 37 | console.log(elephant.sound("trumpeting")); 38 | console.log(elephant.move("walking")); 39 | 40 | const snake = new Animal("Snake", 0); 41 | console.log(snake.describe()); 42 | console.log(snake.sound("hissing")); 43 | console.log(snake.move("slithering")); 44 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/src/components/Todos.jsx: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line 2 | const Todos = ({ todos, onUpdateTodoId }) => { 3 | if (!todos) { 4 | return
No todos available
; 5 | } 6 | 7 | const handleToggleComplete = async (id) => { 8 | try { 9 | const response = await fetch("http://localhost:3000/completed", { 10 | method: "PUT", 11 | headers: { 12 | "Content-Type": "application/json", 13 | }, 14 | body: JSON.stringify({ id }), 15 | }); 16 | 17 | if (!response.ok) { 18 | throw new Error("Failed to update todo"); 19 | } 20 | onUpdateTodoId(id); 21 | } catch (error) { 22 | console.error("Error updating todo:", error); 23 | } 24 | }; 25 | return ( 26 |
27 | {todos.map((e, i) => { 28 | return ( 29 |
30 |

{e.title}

31 |

{e.description}

32 | 35 |
36 | ); 37 | })} 38 |
39 | ); 40 | }; 41 | 42 | export default Todos; 43 | -------------------------------------------------------------------------------- /week-3/mongo/routes/admin.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const adminMiddleware = require("../middleware/admin"); 3 | const { Admin, Course } = require("../db"); 4 | const router = express.Router(); 5 | 6 | router.post("/signup", async (req, res) => { 7 | const username = req.body.username; 8 | const password = req.body.password; 9 | await Admin.create({ 10 | username: username, 11 | password: password, 12 | }); 13 | 14 | res.json({ 15 | message: "Admin created successfully", 16 | }); 17 | }); 18 | 19 | router.post("/courses", adminMiddleware, async (req, res) => { 20 | const title = req.body.title; 21 | const description = req.body.description; 22 | const imageLink = req.body.imageLink; 23 | const price = req.body.price; 24 | 25 | const newCourse = await Course.create({ 26 | title, 27 | description, 28 | imageLink, 29 | price, 30 | }); 31 | 32 | res.json({ 33 | message: "Course created successfully", 34 | courseId: newCourse._id, 35 | }); 36 | }); 37 | 38 | router.get("/courses", adminMiddleware, async (req, res) => { 39 | const response = await Course.find({}); 40 | 41 | res.json({ 42 | courses: response, 43 | }); 44 | }); 45 | 46 | module.exports = router; 47 | -------------------------------------------------------------------------------- /week-6/2-use-callback/src/components/Assignment1.jsx: -------------------------------------------------------------------------------- 1 | import { memo, useCallback, useState } from "react"; 2 | 3 | // Create a counter component with increment and decrement functions. Pass these functions to a child component which has buttons to perform the increment and decrement actions. Use useCallback to ensure that these functions are not recreated on every render. 4 | 5 | export function Assignment1() { 6 | const [count, setCount] = useState(0); 7 | 8 | // Your code starts here 9 | const handleIncrement = useCallback(() => { 10 | setCount(function (currentCount) { 11 | return currentCount + 1; 12 | }); 13 | }, []); 14 | 15 | const handleDecrement = useCallback(() => { 16 | setCount((count) => { 17 | return count - 1; 18 | }); 19 | }, []); 20 | // Your code ends here 21 | 22 | return ( 23 |
24 |

Count: {count}

25 | 29 |
30 | ); 31 | } 32 | 33 | const CounterButtons = memo(({ onIncrement, onDecrement }) => ( 34 |
35 | 36 | 37 |
38 | )); 39 | -------------------------------------------------------------------------------- /week-3/middlewares/user_jwt.js: -------------------------------------------------------------------------------- 1 | // You have to create a middleware for rate limiting a users request based on their username passed in the header 2 | 3 | const jwt = require("jsonwebtoken"); 4 | const jwtPassword = "secret"; 5 | const zod = require("zod"); 6 | 7 | const emailSchema = zod.string().email(); 8 | const passwordSchema = zod.string().min(6); 9 | 10 | function signJwt(username, password) { 11 | const usernameResponse = emailSchema.safeParse(username); 12 | const passwordResponse = passwordSchema.safeParse(password); 13 | if (!usernameResponse.success || !passwordResponse.success) { 14 | return null; 15 | } 16 | 17 | const signature = jwt.sign( 18 | { 19 | username, 20 | }, 21 | jwtPassword 22 | ); 23 | 24 | return signature; 25 | } 26 | 27 | function verifyJwt(token) { 28 | let ans = true; 29 | try { 30 | jwt.verify(token, jwtPassword); 31 | } catch (e) { 32 | ans = false; 33 | } 34 | return ans; 35 | } 36 | 37 | function decodeJwt(token) { 38 | // true, false 39 | const decoded = jwt.decode(token); 40 | if (decoded) { 41 | return true; 42 | } else { 43 | return false; 44 | } 45 | } 46 | 47 | module.exports = { 48 | signJwt, 49 | verifyJwt, 50 | decodeJwt, 51 | jwtPassword, 52 | }; 53 | -------------------------------------------------------------------------------- /week-6/2-use-callback/src/components/Assignment2.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useCallback } from "react"; 2 | 3 | // Create a component with a text input field and a button. The goal is to display an alert with the text entered when the button is clicked. Use useCallback to memoize the event handler function that triggers the alert, ensuring it's not recreated on every render. 4 | // Currently we only have inputText as a state variable and hence you might not see the benefits of 5 | // useCallback. We're also not passing it down to another component as a prop which is another reason for you to not see it's benefits immedietely. 6 | 7 | export function Assignment2() { 8 | const [inputText, setInputText] = useState(""); 9 | 10 | // Your code starts here 11 | const showAlert = useCallback(() => { 12 | alert(inputText); 13 | }, [inputText]); 14 | // Your code ends here 15 | 16 | return ( 17 |
18 | setInputText(e.target.value)} 22 | placeholder="Enter some text" 23 | /> 24 | 25 |
26 | ); 27 | } 28 | 29 | function Alert({ showAlert }) { 30 | return ; 31 | } 32 | -------------------------------------------------------------------------------- /week-16/Auth/backend/src/index.ts: -------------------------------------------------------------------------------- 1 | import express from "express"; 2 | import cookieParser from "cookie-parser"; 3 | import cors from "cors"; 4 | import jwt, { JwtPayload } from "jsonwebtoken"; 5 | import path from "path"; 6 | 7 | const JWT_SECRET = "test123"; 8 | 9 | const app = express(); 10 | app.use(cookieParser()); 11 | app.use(express.json()); 12 | app.use(cors({ 13 | credentials: true, 14 | origin: "http://localhost:5173" 15 | })); 16 | 17 | app.post("/signin", (req, res) => { 18 | const email = req.body.email; 19 | const password = req.body.password; 20 | // do db validations, fetch id of user from db 21 | const token = jwt.sign({ 22 | id: 1 23 | }, JWT_SECRET); 24 | res.cookie("token", token); 25 | res.send("Logged in!"); 26 | }); 27 | 28 | app.get("/user", (req, res) => { 29 | const token = req.cookies.token; 30 | const decoded = jwt.verify(token, JWT_SECRET) as JwtPayload; 31 | // Get email of the user from the database 32 | res.send({ 33 | userId: decoded.id 34 | }) 35 | }); 36 | 37 | 38 | app.post("/logout", (req, res) => { 39 | res.cookie("token", "ads"); 40 | res.json({ 41 | message: "Logged out!" 42 | }) 43 | }); 44 | 45 | 46 | app.get("/", (req, res) => { 47 | res.sendFile(path.join(__dirname, "../src/index.html")) 48 | }) 49 | 50 | app.listen(3000); -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/components/Spinner.tsx: -------------------------------------------------------------------------------- 1 | 2 | export const Spinner = () => { 3 | return
4 | 8 | Loading... 9 |
10 | } -------------------------------------------------------------------------------- /week-3/middlewares/reqLimit.js: -------------------------------------------------------------------------------- 1 | // You have been given an express server which has a few endpoints. 2 | // Your task is to create a global middleware (app.use) which will 3 | // rate limit the requests from a user to only 5 request per second 4 | // If a user sends more than 5 requests in a single second, the server 5 | // should block them with a 404. 6 | // User will be sending in their user id in the header as 'user-id' 7 | // You have been given a numberOfRequestsForUser object to start off with which 8 | // clears every one second 9 | 10 | const express = require("express"); 11 | const app = express(); 12 | 13 | let numberOfRequestsForUser = {}; 14 | setInterval(() => { 15 | numberOfRequestsForUser = {}; 16 | }, 1000); 17 | 18 | app.use(function (req, res, next) { 19 | const userId = req.headers["user-id"]; 20 | 21 | if (numberOfRequestsForUser[userId]) { 22 | numberOfRequestsForUser[userId] = numberOfRequestsForUser[userId] + 1; 23 | if (numberOfRequestsForUser[userId] > 5) { 24 | res.status(404).send("no entry"); 25 | } else { 26 | next(); 27 | } 28 | } else { 29 | numberOfRequestsForUser[userId] = 1; 30 | next(); 31 | } 32 | }); 33 | 34 | app.get("/user", function (req, res) { 35 | res.status(200).json({ name: "john" }); 36 | }); 37 | 38 | app.post("/user", function (req, res) { 39 | res.status(200).json({ msg: "created dummy user" }); 40 | }); 41 | 42 | module.exports = app; 43 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/README.md: -------------------------------------------------------------------------------- 1 | # React + TypeScript + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | 10 | ## Expanding the ESLint configuration 11 | 12 | If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: 13 | 14 | - Configure the top-level `parserOptions` property like this: 15 | 16 | ```js 17 | export default { 18 | // other rules... 19 | parserOptions: { 20 | ecmaVersion: 'latest', 21 | sourceType: 'module', 22 | project: ['./tsconfig.json', './tsconfig.node.json'], 23 | tsconfigRootDir: __dirname, 24 | }, 25 | } 26 | ``` 27 | 28 | - Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` 29 | - Optionally add `plugin:@typescript-eslint/stylistic-type-checked` 30 | - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list 31 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/README.md: -------------------------------------------------------------------------------- 1 | # React + TypeScript + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | 10 | ## Expanding the ESLint configuration 11 | 12 | If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: 13 | 14 | - Configure the top-level `parserOptions` property like this: 15 | 16 | ```js 17 | export default { 18 | // other rules... 19 | parserOptions: { 20 | ecmaVersion: 'latest', 21 | sourceType: 'module', 22 | project: ['./tsconfig.json', './tsconfig.node.json'], 23 | tsconfigRootDir: __dirname, 24 | }, 25 | } 26 | ``` 27 | 28 | - Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` 29 | - Optionally add `plugin:@typescript-eslint/stylistic-type-checked` 30 | - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list 31 | -------------------------------------------------------------------------------- /week-2/async-js/hard/promise-chain.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Write 3 different functions that return promises that resolve after t1, t2, and t3 seconds respectively. 3 | * Write a function that sequentially calls all 3 of these functions in order. 4 | * Return a promise chain which return the time in milliseconds it takes to complete the entire operation. 5 | * Compare it with the results from 3-promise-all.js 6 | */ 7 | 8 | function wait1(t) { 9 | return new Promise((resolve) => { 10 | setTimeout(() => { 11 | resolve(`wait1 resolved after ${t} seconds`); 12 | }, t * 1000); 13 | }); 14 | } 15 | 16 | function wait2(t) { 17 | return new Promise((resolve) => { 18 | setTimeout(() => { 19 | resolve(`wait2 resolved after ${t} seconds`); 20 | }, t * 1000); 21 | }); 22 | } 23 | 24 | function wait3(t) { 25 | return new Promise((resolve) => { 26 | setTimeout(() => { 27 | resolve(`wait3 resolved after ${t} seconds`); 28 | }, t * 1000); 29 | }); 30 | } 31 | 32 | function calculateTime(t1, t2, t3) { 33 | const startTime = Date.now(); 34 | 35 | // Sequentially call the three functions using promise chaining 36 | return wait1(t1) 37 | .then(() => wait2(t2)) 38 | .then(() => wait3(t3)) 39 | .then(() => { 40 | const endTime = Date.now(); 41 | return endTime - startTime; // Return the time taken for completion in milliseconds 42 | }); 43 | } 44 | 45 | module.exports = calculateTime; 46 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 3 | if (k2 === undefined) k2 = k; 4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); 5 | }) : (function(o, m, k, k2) { 6 | if (k2 === undefined) k2 = k; 7 | o[k2] = m[k]; 8 | })); 9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { 10 | Object.defineProperty(o, "default", { enumerable: true, value: v }); 11 | }) : function(o, v) { 12 | o["default"] = v; 13 | }); 14 | var __importStar = (this && this.__importStar) || function (mod) { 15 | if (mod && mod.__esModule) return mod; 16 | var result = {}; 17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); 18 | __setModuleDefault(result, mod); 19 | return result; 20 | }; 21 | var __exportStar = (this && this.__exportStar) || function(m, exports) { 22 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); 23 | }; 24 | Object.defineProperty(exports, "__esModule", { value: true }); 25 | exports.z = void 0; 26 | const z = __importStar(require("./external")); 27 | exports.z = z; 28 | __exportStar(require("./external"), exports); 29 | exports.default = z; 30 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/pages/Dashboard.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | import { useState, useEffect } from "react"; 3 | import { Appbar } from "../components/Appbar"; 4 | import { Balance } from "../components/Balance"; 5 | import { Users } from "../components/Users"; 6 | import axios from "axios"; 7 | import { endpoints } from "../configs/urls"; 8 | 9 | export const Dashboard = () => { 10 | const [balance, setBalance] = useState(0); 11 | const [isLoading, setIsLoading] = useState(false); 12 | const user = localStorage.getItem("user"); 13 | const fetchBalance = async () => { 14 | try { 15 | setIsLoading(true); 16 | const token = localStorage.getItem("token"); 17 | const config = { 18 | headers: { 19 | Authorization: `Bearer ${token}`, 20 | }, 21 | }; 22 | 23 | const response = await axios.get(endpoints.currentuserbalance, config); 24 | setBalance(response.data.balance); 25 | setIsLoading(false); 26 | } catch (error) { 27 | setIsLoading(false); 28 | console.error("Error fetching account balance:", error); 29 | } 30 | }; 31 | 32 | useEffect(() => { 33 | fetchBalance(); 34 | }, []); 35 | 36 | return ( 37 |
38 | 39 |
40 | 41 | 42 |
43 |
44 | ); 45 | }; 46 | -------------------------------------------------------------------------------- /week-7/assignments/all/src/components/Assignment1/index.jsx: -------------------------------------------------------------------------------- 1 | export default function Assignment1() { 2 | return ( 3 |
4 |

5 | Profile component 6 |

7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |

Name

15 |

Age

16 |
17 |

Place

18 |
19 |
20 |
21 |
22 |

100K

23 |

Followers

24 |
25 |
26 |

10K

27 |

Likes

28 |
29 |
30 |

1.4K

31 |

photos

32 |
33 |
34 |
35 |
36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/components/Appbar.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from "react" 2 | import { Avatar } from "./BlogCard" 3 | import { Link, useNavigate } from "react-router-dom" 4 | 5 | export const Appbar = () => { 6 | const [visible, setVisibile] = useState(false) 7 | const navigate = useNavigate(); 8 | 9 | return
10 | 11 | NxtGenBlog 12 | 13 |
14 | 15 | 16 | 17 | 18 | 21 | {visible &&
22 | 23 |
} 24 |
25 |
26 | } -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/App.jsx: -------------------------------------------------------------------------------- 1 | import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom"; 2 | import { Signup } from "./pages/Signup"; 3 | import { Signin } from "./pages/Signin"; 4 | import { Dashboard } from "./pages/Dashboard"; 5 | import { SendMoney } from "./pages/SendMoney"; 6 | import UserProfile from "./pages/UserProfile"; 7 | import PropTypes from "prop-types"; 8 | 9 | const isAuthenticated = () => { 10 | return localStorage.getItem("token") !== null; 11 | }; 12 | const ProtectedRoute = ({ element: Element, ...rest }) => { 13 | return isAuthenticated() ? : ; 14 | }; 15 | 16 | ProtectedRoute.propTypes = { 17 | element: PropTypes.element.isRequired, 18 | }; 19 | 20 | function App() { 21 | return ( 22 | <> 23 | 24 | 25 | } /> 26 | } /> 27 | } 30 | /> 31 | } 34 | /> 35 | } 38 | /> 39 | 40 | 41 | 42 | ); 43 | } 44 | 45 | export default App; 46 | -------------------------------------------------------------------------------- /week-6/1-use-memo/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-6/3-use-ref/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-1/basics/object.js: -------------------------------------------------------------------------------- 1 | // Object Methods Explanation 2 | function objectMethods(obj) { 3 | console.log("Original Object:", obj); 4 | 5 | let keys = Object.keys(obj); 6 | console.log("After Object.keys():", keys); 7 | 8 | let values = Object.values(obj); 9 | console.log("After Object.values():", values); 10 | 11 | let entries = Object.entries(obj); 12 | console.log("After Object.entries():", entries); 13 | 14 | let hasProp = obj.hasOwnProperty("property"); 15 | console.log("After hasOwnProperty():", hasProp); 16 | 17 | let newObj = Object.assign({}, obj, { newProperty: "newValue" }); 18 | console.log("After Object.assign():", newObj); 19 | } 20 | 21 | // Example Usage for Object Methods 22 | 23 | // Object 1 24 | const person = { 25 | name: "John Doe", 26 | age: 30, 27 | city: "New York", 28 | }; 29 | 30 | // Object 2 31 | const car = { 32 | make: "Toyota", 33 | model: "Camry", 34 | year: 2022, 35 | }; 36 | 37 | // Object 3 38 | const book = { 39 | title: "The Great Gatsby", 40 | author: "F. Scott Fitzgerald", 41 | year: 1925, 42 | }; 43 | 44 | // Object 4 45 | const fruit = { 46 | type: "Apple", 47 | color: "Red", 48 | quantity: 5, 49 | }; 50 | 51 | // Object 5 52 | const laptop = { 53 | brand: "Dell", 54 | model: "XPS 13", 55 | year: 2023, 56 | }; 57 | 58 | // Call the function with different objects 59 | objectMethods(person); 60 | objectMethods(car); 61 | objectMethods(book); 62 | objectMethods(fruit); 63 | objectMethods(laptop); 64 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-16/Auth/frontend/src/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | 16 | a { 17 | font-weight: 500; 18 | color: #646cff; 19 | text-decoration: inherit; 20 | } 21 | a:hover { 22 | color: #535bf2; 23 | } 24 | 25 | body { 26 | margin: 0; 27 | display: flex; 28 | place-items: center; 29 | min-width: 320px; 30 | min-height: 100vh; 31 | } 32 | 33 | h1 { 34 | font-size: 3.2em; 35 | line-height: 1.1; 36 | } 37 | 38 | button { 39 | border-radius: 8px; 40 | border: 1px solid transparent; 41 | padding: 0.6em 1.2em; 42 | font-size: 1em; 43 | font-weight: 500; 44 | font-family: inherit; 45 | background-color: #1a1a1a; 46 | cursor: pointer; 47 | transition: border-color 0.25s; 48 | } 49 | button:hover { 50 | border-color: #646cff; 51 | } 52 | button:focus, 53 | button:focus-visible { 54 | outline: 4px auto -webkit-focus-ring-color; 55 | } 56 | 57 | @media (prefers-color-scheme: light) { 58 | :root { 59 | color: #213547; 60 | background-color: #ffffff; 61 | } 62 | a:hover { 63 | color: #747bff; 64 | } 65 | button { 66 | background-color: #f9f9f9; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /week-6/2-use-callback/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-7/assignments/all/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/backend/db.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | require("dotenv").config(); 3 | 4 | async function connectToDatabase() { 5 | try { 6 | await mongoose.connect(process.env.MONGO_URL, { 7 | useNewUrlParser: true, 8 | useUnifiedTopology: true, 9 | }); 10 | console.log("Connected to DB"); 11 | } catch (error) { 12 | console.error("Error connecting to DB:", error); 13 | } 14 | } 15 | 16 | connectToDatabase(); 17 | 18 | const userSchema = new mongoose.Schema({ 19 | username: { 20 | type: String, 21 | required: true, 22 | unique: true, 23 | trim: true, 24 | lowercase: true, 25 | minLength: 3, 26 | maxLength: 30, 27 | }, 28 | password: { 29 | type: String, 30 | required: true, 31 | minLength: 6, 32 | }, 33 | firstName: { 34 | type: String, 35 | required: true, 36 | trim: true, 37 | maxLength: 50, 38 | }, 39 | lastName: { 40 | type: String, 41 | required: true, 42 | trim: true, 43 | maxLength: 50, 44 | }, 45 | }); 46 | 47 | const accountSchema = new mongoose.Schema({ 48 | userId: { 49 | type: mongoose.Schema.Types.ObjectId, 50 | ref: "User", 51 | required: true, 52 | }, 53 | balance: { 54 | type: Number, 55 | required: true, 56 | }, 57 | }); 58 | 59 | const Account = mongoose.model("Account", accountSchema); 60 | const User = mongoose.model("User", userSchema); 61 | 62 | module.exports = { 63 | User, 64 | Account, 65 | }; 66 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/pages/Blogs.tsx: -------------------------------------------------------------------------------- 1 | import { Appbar } from "../components/Appbar" 2 | import { BlogCard } from "../components/BlogCard" 3 | import { BlogSkeleton } from "../components/BlogSkeleton"; 4 | import { useBlogs } from "../hooks"; 5 | 6 | export const Blogs = () => { 7 | const { loading, blogs } = useBlogs(); 8 | 9 | if (loading) { 10 | return
11 | 12 |
13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 |
26 |
27 | } 28 | 29 | return
30 | 31 |
32 |
33 | {blogs.map(blog => )} 40 |
41 |
42 |
43 | } 44 | 45 | -------------------------------------------------------------------------------- /week-6/1-use-memo/src/components/Assignment2.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useMemo, useState } from "react"; 2 | 3 | // In this assignment, you will create a component that renders a large list of sentences and includes an input field for filtering these items. 4 | // The goal is to use useMemo to optimize the filtering process, ensuring the list is only re-calculated when necessary (e.g., when the filter criteria changes). 5 | // You will learn something new here, specifically how you have to pass more than one value in the dependency array 6 | 7 | const words = ["hi", "my", "name", "is", "for", "to", "random", "word"]; 8 | const TOTAL_LINES = 1000; 9 | const ALL_WORDS = []; 10 | for (let i = 0; i < TOTAL_LINES; i++) { 11 | let sentence = ""; 12 | for (let j = 0; j < words.length; j++) { 13 | sentence += words[Math.floor(words.length * Math.random())]; 14 | sentence += " "; 15 | } 16 | ALL_WORDS.push(sentence); 17 | } 18 | 19 | export function Assignment2() { 20 | const [sentences, setSentences] = useState(ALL_WORDS); 21 | const [filter, setFilter] = useState(""); 22 | 23 | const filteredSentences = useMemo(() => { 24 | return sentences.filter((x) => x.includes(filter)); 25 | }, [sentences, filter]); 26 | 27 | return ( 28 |
29 | { 32 | setFilter(e.target.value); 33 | }} 34 | > 35 | {filteredSentences.map((word) => ( 36 |
{word}
37 | ))} 38 |
39 | ); 40 | } 41 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/components/BlogSkeleton.tsx: -------------------------------------------------------------------------------- 1 | import { Circle } from "./BlogCard" 2 | 3 | export const BlogSkeleton = () => { 4 | return
5 |
6 |
7 |
8 |
9 |
10 |
11 | 12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | Loading... 28 |
29 | } -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/hooks/index.ts: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react" 2 | import axios from "axios"; 3 | import { BACKEND_URL } from "../config"; 4 | 5 | 6 | export interface Blog { 7 | "content": string; 8 | "title": string; 9 | "id": number 10 | "author": { 11 | "name": string 12 | } 13 | } 14 | 15 | export const useBlog = ({ id }: { id: string }) => { 16 | const [loading, setLoading] = useState(true); 17 | const [blog, setBlog] = useState(); 18 | 19 | useEffect(() => { 20 | axios.get(`${BACKEND_URL}/api/v1/blog/${id}`, { 21 | headers: { 22 | Authorization: localStorage.getItem("token") 23 | } 24 | }) 25 | .then(response => { 26 | setBlog(response.data.blog); 27 | setLoading(false); 28 | }) 29 | }, [id]) 30 | 31 | return { 32 | loading, 33 | blog 34 | } 35 | 36 | } 37 | export const useBlogs = () => { 38 | const [loading, setLoading] = useState(true); 39 | const [blogs, setBlogs] = useState([]); 40 | 41 | useEffect(() => { 42 | axios.get(`${BACKEND_URL}/api/v1/blog/bulk`, { 43 | headers: { 44 | Authorization: localStorage.getItem("token") 45 | } 46 | }) 47 | .then(response => { 48 | setBlogs(response.data.blogs); 49 | setLoading(false); 50 | }) 51 | }, []) 52 | 53 | return { 54 | loading, 55 | blogs 56 | } 57 | } -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/components/Loader.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react/prop-types */ 2 | import { helix } from "ldrs"; 3 | import { dotSpinner } from "ldrs"; 4 | import { bouncy } from "ldrs"; 5 | import { lineWobble } from "ldrs"; 6 | 7 | helix.register(); 8 | dotSpinner.register(); 9 | bouncy.register(); 10 | lineWobble.register(); 11 | 12 | function MoneyLoader({ isLoading }) { 13 | return ( 14 |
15 | {isLoading && } 16 |
17 | ); 18 | } 19 | function BufferLoader({ isLoading }) { 20 | return ( 21 |
22 | {isLoading && ( 23 | 24 | )} 25 |
26 | ); 27 | } 28 | 29 | function BalanceLoader({ isLoading }) { 30 | return ( 31 |
32 | {isLoading && } 33 |
34 | ); 35 | } 36 | 37 | function TransferLoader({ isLoading }) { 38 | return ( 39 |
40 | {isLoading && ( 41 | 48 | )} 49 |
50 | ); 51 | } 52 | 53 | export default { MoneyLoader, BufferLoader, BalanceLoader, TransferLoader }; 54 | -------------------------------------------------------------------------------- /week-2/async-js/hard/promise-all.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Write 3 different functions that return promises that resolve after t1, t2, and t3 seconds respectively. 3 | * Write a function that uses the 3 functions to wait for all 3 promises to resolve using Promise.all, 4 | * Return a promise.all which return the time in milliseconds it takes to complete the entire operation. 5 | */ 6 | function wait1(t) { 7 | return new Promise((resolve) => { 8 | setTimeout(() => { 9 | resolve(`wait1 resolved after ${t} seconds`); 10 | }, t * 1000); 11 | }); 12 | } 13 | 14 | function wait2(t) { 15 | return new Promise((resolve) => { 16 | setTimeout(() => { 17 | resolve(`wait2 resolved after ${t} seconds`); 18 | }, t * 1000); 19 | }); 20 | } 21 | 22 | function wait3(t) { 23 | return new Promise((resolve) => { 24 | setTimeout(() => { 25 | resolve(`wait3 resolved after ${t} seconds`); 26 | }, t * 1000); 27 | }); 28 | } 29 | 30 | function calculateTime(t1, t2, t3) { 31 | const startTime = Date.now(); 32 | 33 | // Use Promise.all to wait for all three promises to resolve 34 | return Promise.all([wait1(t1), wait2(t2), wait3(t3)]).then(() => { 35 | const endTime = Date.now(); 36 | return (endTime - startTime) / 1000; // Return the time taken for completion in milliseconds 37 | }); 38 | } 39 | 40 | console.log( 41 | calculateTime(1, 2, 3) 42 | .then((result) => { 43 | console.log(result); // Log the resolved value when the Promise resolves 44 | }) 45 | .catch((err) => { 46 | console.error(err); // Handle errors if the Promise rejects 47 | }) 48 | ); 49 | module.exports = calculateTime; 50 | -------------------------------------------------------------------------------- /week-0/zerodha-app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Zerodha app 5 | 6 | 7 |
10 |
11 | logo 16 |
17 |
18 | Sign up 19 | About Us 20 | Products 21 | pricing 22 | Support 23 |
24 |
25 |
26 | img 31 |
32 |
40 |

Invest in everything

41 |

42 | Online platform to invest in stocks, derivatives, mutual funds, and more 43 |

44 | 56 |
57 | 58 | 59 | -------------------------------------------------------------------------------- /week-3/mongo/routes/user.js: -------------------------------------------------------------------------------- 1 | const { Router } = require("express"); 2 | const router = Router(); 3 | const userMiddleware = require("../middleware/user"); 4 | const { User, Course } = require("../db"); 5 | const { default: mongoose } = require("mongoose"); 6 | 7 | router.post("/signup", (req, res) => { 8 | const username = req.body.username; 9 | const password = req.body.password; 10 | User.create({ 11 | username, 12 | password, 13 | }); 14 | res.json({ 15 | message: "User created successfully", 16 | }); 17 | }); 18 | 19 | router.get("/users", async (req, res) => { 20 | const users = await User.find({}); 21 | res.send({ users: users }); 22 | }); 23 | 24 | router.get("/courses", async (req, res) => { 25 | const response = await Course.find({}); 26 | 27 | res.json({ 28 | courses: response, 29 | }); 30 | }); 31 | 32 | router.post("/courses/:courseId", userMiddleware, async (req, res) => { 33 | const courseId = req.params.courseId; 34 | const username = req.headers.username; 35 | 36 | await User.updateOne( 37 | { 38 | username: username, 39 | }, 40 | { 41 | $push: { 42 | purchasedCourses: courseId, 43 | }, 44 | } 45 | ); 46 | res.json({ 47 | message: "Purchase complete!", 48 | }); 49 | }); 50 | 51 | router.get("/purchasedCourses", userMiddleware, async (req, res) => { 52 | const user = await User.findOne({ 53 | username: req.headers.username, 54 | }); 55 | 56 | console.log(user.purchasedCourses); 57 | const courses = await Course.find({ 58 | _id: { 59 | $in: user.purchasedCourses, 60 | }, 61 | }); 62 | 63 | res.json({ 64 | courses: courses, 65 | }); 66 | }); 67 | 68 | module.exports = router; 69 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/__tests__/Mocker.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.Mocker = void 0; 4 | function getRandomInt(max) { 5 | return Math.floor(Math.random() * Math.floor(max)); 6 | } 7 | const testSymbol = Symbol("test"); 8 | class Mocker { 9 | constructor() { 10 | this.pick = (...args) => { 11 | return args[getRandomInt(args.length)]; 12 | }; 13 | } 14 | get string() { 15 | return Math.random().toString(36).substring(7); 16 | } 17 | get number() { 18 | return Math.random() * 100; 19 | } 20 | get bigint() { 21 | return BigInt(Math.floor(Math.random() * 10000)); 22 | } 23 | get boolean() { 24 | return Math.random() < 0.5; 25 | } 26 | get date() { 27 | return new Date(Math.floor(Date.now() * Math.random())); 28 | } 29 | get symbol() { 30 | return testSymbol; 31 | } 32 | get null() { 33 | return null; 34 | } 35 | get undefined() { 36 | return undefined; 37 | } 38 | get stringOptional() { 39 | return this.pick(this.string, this.undefined); 40 | } 41 | get stringNullable() { 42 | return this.pick(this.string, this.null); 43 | } 44 | get numberOptional() { 45 | return this.pick(this.number, this.undefined); 46 | } 47 | get numberNullable() { 48 | return this.pick(this.number, this.null); 49 | } 50 | get booleanOptional() { 51 | return this.pick(this.boolean, this.undefined); 52 | } 53 | get booleanNullable() { 54 | return this.pick(this.boolean, this.null); 55 | } 56 | } 57 | exports.Mocker = Mocker; 58 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const discriminatedUnion_1 = __importDefault(require("./discriminatedUnion")); 7 | const object_1 = __importDefault(require("./object")); 8 | const primitives_1 = __importDefault(require("./primitives")); 9 | const realworld_1 = __importDefault(require("./realworld")); 10 | const string_1 = __importDefault(require("./string")); 11 | const union_1 = __importDefault(require("./union")); 12 | const argv = process.argv.slice(2); 13 | let suites = []; 14 | if (!argv.length) { 15 | suites = [ 16 | ...realworld_1.default.suites, 17 | ...primitives_1.default.suites, 18 | ...string_1.default.suites, 19 | ...object_1.default.suites, 20 | ...union_1.default.suites, 21 | ...discriminatedUnion_1.default.suites, 22 | ]; 23 | } 24 | else { 25 | if (argv.includes("--realworld")) { 26 | suites.push(...realworld_1.default.suites); 27 | } 28 | if (argv.includes("--primitives")) { 29 | suites.push(...primitives_1.default.suites); 30 | } 31 | if (argv.includes("--string")) { 32 | suites.push(...string_1.default.suites); 33 | } 34 | if (argv.includes("--object")) { 35 | suites.push(...object_1.default.suites); 36 | } 37 | if (argv.includes("--union")) { 38 | suites.push(...union_1.default.suites); 39 | } 40 | if (argv.includes("--discriminatedUnion")) { 41 | suites.push(...discriminatedUnion_1.default.suites); 42 | } 43 | } 44 | for (const suite of suites) { 45 | suite.run(); 46 | } 47 | -------------------------------------------------------------------------------- /week-2/nodejs/problems/fileServer.js: -------------------------------------------------------------------------------- 1 | /** 2 | You need to create an express HTTP server in Node.js which will handle the logic of a file server. 3 | - Use built in Node.js `fs` module 4 | The expected API endpoints are defined below, 5 | 1. GET /files - Returns a list of files present in `./files/` directory 6 | Response: 200 OK with an array of file names in JSON format. 7 | Example: GET http://localhost:3000/files 8 | 2. GET /file/:filename - Returns content of given file by name 9 | Description: Use the filename from the request path parameter to read the file from `./files/` directory 10 | Response: 200 OK with the file content as the response body if found, or 404 Not Found if not found. Should return `File not found` as text if file is not found 11 | Example: GET http://localhost:3000/file/example.txt 12 | - For any other route not defined in the server return 404 13 | Testing the server - run `npm run test-fileServer` command in terminal 14 | */ 15 | const express = require("express"); 16 | const fs = require("fs"); 17 | const path = require("path"); 18 | const app = express(); 19 | 20 | app.get("/files", function (req, res) { 21 | fs.readdir(path.join(__dirname, "./files/"), (err, files) => { 22 | if (err) { 23 | return res.status(500).json({ error: "Failed to retrieve files" }); 24 | } 25 | res.json(files); 26 | }); 27 | }); 28 | 29 | app.get("/file/:filename", function (req, res) { 30 | const filepath = path.join(__dirname, "./files/", req.params.filename); 31 | 32 | fs.readFile(filepath, "utf8", (err, data) => { 33 | if (err) { 34 | return res.status(404).send("File not found"); 35 | } 36 | res.send(data); 37 | }); 38 | }); 39 | 40 | app.all("*", (req, res) => { 41 | res.status(404).send("Route not found"); 42 | }); 43 | 44 | module.exports = app; 45 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/backend/index.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const { createTodo, updateTodo } = require("./types"); 3 | const { todo } = require("./db"); 4 | const app = express(); 5 | const cors = require("cors"); 6 | const PORT = 3000; 7 | 8 | app.use(express.json()); 9 | app.use(cors()); 10 | app.get("/todos", async function (req, res) { 11 | try { 12 | const todos = await todo.find({}); 13 | res.json({ todos: todos }); 14 | } catch (error) { 15 | res.status(404).json({ msg: "Error found" }); 16 | } 17 | }); 18 | 19 | app.post("/todos", async function (req, res) { 20 | const createPayload = req.body; 21 | const parsedPayload = createTodo.safeParse(createPayload); 22 | if (!parsedPayload.success) { 23 | res.status(411).json({ msg: "You sent wrong inputs" }); 24 | return; 25 | } 26 | try { 27 | await todo.create({ 28 | title: createPayload.title, 29 | description: createPayload.description, 30 | completed: false, 31 | }); 32 | res.json({ msg: "Todo Created" }); 33 | } catch (e) { 34 | res.status(404).json({ msg: "Error found" }); 35 | } 36 | }); 37 | 38 | app.put("/completed", async function (req, res) { 39 | const updatePayload = req.body; 40 | const parsedPayload = updateTodo.safeParse(updatePayload); 41 | if (!parsedPayload.success) { 42 | res.status(411).json({ msg: "You sent wrong inputs" }); 43 | return; 44 | } 45 | try { 46 | await todo.updateById( 47 | { 48 | _id: req.body.id, 49 | }, 50 | { 51 | completed: true, 52 | } 53 | ); 54 | res.json({ msg: "Updated Todo" }); 55 | } catch (err) { 56 | res.status(404).json({ msg: "Error found" }); 57 | } 58 | }); 59 | 60 | app.listen(PORT, function () { 61 | console.log(`server started at ${PORT}`); 62 | }); 63 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/string.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const index_1 = require("../index"); 8 | const SUITE_NAME = "z.string"; 9 | const suite = new benchmark_1.default.Suite(SUITE_NAME); 10 | const empty = ""; 11 | const short = "short"; 12 | const long = "long".repeat(256); 13 | const manual = (str) => { 14 | if (typeof str !== "string") { 15 | throw new Error("Not a string"); 16 | } 17 | return str; 18 | }; 19 | const stringSchema = index_1.z.string(); 20 | const optionalStringSchema = index_1.z.string().optional(); 21 | const optionalNullableStringSchema = index_1.z.string().optional().nullable(); 22 | suite 23 | .add("empty string", () => { 24 | stringSchema.parse(empty); 25 | }) 26 | .add("short string", () => { 27 | stringSchema.parse(short); 28 | }) 29 | .add("long string", () => { 30 | stringSchema.parse(long); 31 | }) 32 | .add("optional string", () => { 33 | optionalStringSchema.parse(long); 34 | }) 35 | .add("nullable string", () => { 36 | optionalNullableStringSchema.parse(long); 37 | }) 38 | .add("nullable (null) string", () => { 39 | optionalNullableStringSchema.parse(null); 40 | }) 41 | .add("invalid: null", () => { 42 | try { 43 | stringSchema.parse(null); 44 | } 45 | catch (err) { } 46 | }) 47 | .add("manual parser: long", () => { 48 | manual(long); 49 | }) 50 | .on("cycle", (e) => { 51 | console.log(`${SUITE_NAME}: ${e.target}`); 52 | }); 53 | exports.default = { 54 | suites: [suite], 55 | }; 56 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/realworld.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const index_1 = require("../index"); 8 | const shortSuite = new benchmark_1.default.Suite("realworld"); 9 | const People = index_1.z.array(index_1.z.object({ 10 | type: index_1.z.literal("person"), 11 | hair: index_1.z.enum(["blue", "brown"]), 12 | active: index_1.z.boolean(), 13 | name: index_1.z.string(), 14 | age: index_1.z.number().int(), 15 | hobbies: index_1.z.array(index_1.z.string()), 16 | address: index_1.z.object({ 17 | street: index_1.z.string(), 18 | zip: index_1.z.string(), 19 | country: index_1.z.string(), 20 | }), 21 | })); 22 | let i = 0; 23 | function num() { 24 | return ++i; 25 | } 26 | function str() { 27 | return (++i % 100).toString(16); 28 | } 29 | function array(fn) { 30 | return Array.from({ length: ++i % 10 }, () => fn()); 31 | } 32 | const people = Array.from({ length: 100 }, () => { 33 | return { 34 | type: "person", 35 | hair: i % 2 ? "blue" : "brown", 36 | active: !!(i % 2), 37 | name: str(), 38 | age: num(), 39 | hobbies: array(str), 40 | address: { 41 | street: str(), 42 | zip: str(), 43 | country: str(), 44 | }, 45 | }; 46 | }); 47 | shortSuite 48 | .add("valid", () => { 49 | People.parse(people); 50 | }) 51 | .on("cycle", (e) => { 52 | console.log(`${shortSuite.name}: ${e.target}`); 53 | }); 54 | exports.default = { 55 | suites: [shortSuite], 56 | }; 57 | -------------------------------------------------------------------------------- /week-1/basics/date.js: -------------------------------------------------------------------------------- 1 | function dateMethods() { 2 | // Getting the current date 3 | const currentDate = new Date(); 4 | console.log("Current Date:", currentDate); 5 | 6 | // Getting and setting time in milliseconds since 1970 7 | console.log("Time in milliseconds since 1970:", currentDate.getTime()); 8 | 9 | // Creating a new date 10 | const newDate = new Date(2023, 8, 15); 11 | console.log("New Date:", newDate); 12 | 13 | // Methods: 14 | 15 | // 1. getDate() - Get the day of the month (1-31) for the specified date. 16 | console.log("Day of the month:", currentDate.getDate()); 17 | 18 | // 2. getMonth() - Get the month (0-11) for the specified date. 19 | console.log("Month:", currentDate.getMonth()); 20 | 21 | // 3. getFullYear() - Get the year (four digits) for the specified date. 22 | console.log("Year:", currentDate.getFullYear()); 23 | 24 | // 4. getHours() - Get the hour (0-23) for the specified date. 25 | console.log("Hours:", currentDate.getHours()); 26 | 27 | // 5. getMinutes() - Get the minutes (0-59) for the specified date. 28 | console.log("Minutes:", currentDate.getMinutes()); 29 | 30 | // 6. getSeconds() - Get the seconds (0-59) for the specified date. 31 | console.log("Seconds:", currentDate.getSeconds()); 32 | 33 | // 7. getDay() - Get the day of the week (0-6) for the specified date. 34 | console.log("Day of the week:", currentDate.getDay()); 35 | 36 | // 8. toDateString() - Get a human-readable string representing the date portion. 37 | console.log("Date string:", currentDate.toDateString()); 38 | 39 | // 9. toTimeString() - Get a human-readable string representing the time portion. 40 | console.log("Time string:", currentDate.toTimeString()); 41 | 42 | // 10. toISOString() - Get a string in ISO format (YYYY-MM-DDTHH:mm:ss.sssZ). 43 | console.log("ISO String:", currentDate.toISOString()); 44 | } 45 | 46 | // Example Usage for Date Methods 47 | dateMethods(); 48 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/components/FullBlog.tsx: -------------------------------------------------------------------------------- 1 | import { Blog } from "../hooks" 2 | import { Appbar } from "./Appbar" 3 | import { Avatar } from "./BlogCard" 4 | 5 | export const FullBlog = ({ blog }: {blog: Blog}) => { 6 | return
7 | 8 |
9 |
10 |
11 |
12 | {blog.title} 13 |
14 |
15 | Post on 2nd December 2023 16 |
17 |
18 | {blog.content} 19 |
20 |
21 |
22 |
23 | Author 24 |
25 |
26 |
27 | 28 |
29 |
30 |
31 | {blog.author.name || "Anonymous"} 32 |
33 |
34 | Random catch phrase about the author's ability to grab the user's attention 35 |
36 |
37 |
38 |
39 | 40 |
41 |
42 |
43 | } -------------------------------------------------------------------------------- /week-1/problems/hard/todo-list.js: -------------------------------------------------------------------------------- 1 | /* 2 | Implement a class `Todo` having below methods 3 | - add(todo): adds todo to list of todos 4 | - remove(indexOfTodo): remove todo from list of todos 5 | - update(index, updatedTodo): update todo at given index 6 | - getAll: returns all todos 7 | - get(indexOfTodo): returns todo at given index 8 | - clear: deletes all todos 9 | 10 | Once you've implemented the logic, test your code by running 11 | */ 12 | 13 | class Todo { 14 | constructor() { 15 | this.todos = []; 16 | } 17 | 18 | add(todo) { 19 | this.todos.push(todo); 20 | } 21 | 22 | remove(indexOfTodo) { 23 | if (indexOfTodo >= 0 && indexOfTodo < this.todos.length) { 24 | this.todos.splice(indexOfTodo, 1); 25 | } else { 26 | throw new Error("Invalid index for removal."); 27 | } 28 | } 29 | 30 | update(index, updatedTodo) { 31 | if (index >= 0 && index < this.todos.length) { 32 | this.todos[index] = updatedTodo; 33 | } else { 34 | throw new Error("Invalid index for update."); 35 | } 36 | } 37 | 38 | getAll() { 39 | return this.todos; 40 | } 41 | 42 | get(indexOfTodo) { 43 | if (indexOfTodo >= 0 && indexOfTodo < this.todos.length) { 44 | return this.todos[indexOfTodo]; 45 | } else { 46 | throw new Error("Invalid index to get todo."); 47 | } 48 | } 49 | 50 | clear() { 51 | this.todos = []; 52 | } 53 | } 54 | 55 | // Test your code 56 | const todoList = new Todo(); 57 | todoList.add("Complete assignment"); 58 | todoList.add("Buy groceries"); 59 | todoList.add("Call mom"); 60 | 61 | console.log("All Todos:", todoList.getAll()); 62 | 63 | todoList.update(1, "Buy milk"); 64 | console.log("Updated Todo at index 1:", todoList.get(1)); 65 | 66 | todoList.remove(0); 67 | console.log("Todos after removal:", todoList.getAll()); 68 | 69 | todoList.clear(); 70 | console.log("Cleared Todos:", todoList.getAll()); 71 | 72 | module.exports = Todo; 73 | -------------------------------------------------------------------------------- /week-4/full_stack_todo/frontend/src/components/CreateTodo.jsx: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | function CreateTodo() { 4 | const [title, setTitle] = useState(""); 5 | const [description, setDescription] = useState(""); 6 | 7 | const handleTitleChange = (event) => { 8 | setTitle(event.target.value); 9 | }; 10 | 11 | const handleDescriptionChange = (event) => { 12 | setDescription(event.target.value); 13 | }; 14 | 15 | const handleAddTodo = () => { 16 | // Make sure title and description are not empty before sending the request 17 | if (!title.trim() || !description.trim()) { 18 | alert("Title and description are required"); 19 | return; 20 | } 21 | 22 | fetch("http://localhost:3000/todos", { 23 | method: "POST", 24 | headers: { 25 | "Content-Type": "application/json", 26 | }, 27 | body: JSON.stringify({ title, description }), 28 | }) 29 | .then((response) => { 30 | if (!response.ok) { 31 | throw new Error("Failed to add todo"); 32 | } 33 | return response.json(); 34 | }) 35 | .then((data) => { 36 | // Handle success response if needed 37 | console.log("Todo added successfully:", data); 38 | setTitle(""); 39 | setDescription(""); 40 | }) 41 | .catch((error) => { 42 | console.error("Error adding todo:", error); 43 | }); 44 | }; 45 | 46 | return ( 47 |
48 |

Create Todo

49 | 55 |
56 | 62 |
63 | 64 |
65 | ); 66 | } 67 | 68 | export default CreateTodo; 69 | -------------------------------------------------------------------------------- /week-0/basics/introduction.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------ 2 | In this week will learn some things those are 3 | 4 | *Before get started learn about Browsers and IDE's is most imp 5 | 6 | Browsers: 7 | Browser is some sort of software which used to allow people to search something on computer, and get back with some sort of information with using HTML and CSS and JS files from server. 8 | 9 | IDE's:(Integrated development environment) 10 | IDE's are code playground, simply where people write or manupulate code. 11 | 12 | start off web development mostly frontend development which includes 13 | * HTML 14 | * CSS 15 | 16 | 17 | HTML => Hypertext Markup Langauge 18 | 19 | Which mainly used to create the structure of the webpage. 20 | 21 | Mostly with 22 | @tags 23 | @attributes 24 | 25 | Tags: We have to structure the HTML elements using tags in HTML 26 | 27 | Some most tags used: 28 | 29 | 30 | 31 |

32 |

33 | 34 | 35 | 36 | 14 | 15 |

16 | 17 | 18 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/union.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const index_1 = require("../index"); 8 | const doubleSuite = new benchmark_1.default.Suite("z.union: double"); 9 | const manySuite = new benchmark_1.default.Suite("z.union: many"); 10 | const aSchema = index_1.z.object({ 11 | type: index_1.z.literal("a"), 12 | }); 13 | const objA = { 14 | type: "a", 15 | }; 16 | const bSchema = index_1.z.object({ 17 | type: index_1.z.literal("b"), 18 | }); 19 | const objB = { 20 | type: "b", 21 | }; 22 | const cSchema = index_1.z.object({ 23 | type: index_1.z.literal("c"), 24 | }); 25 | const objC = { 26 | type: "c", 27 | }; 28 | const dSchema = index_1.z.object({ 29 | type: index_1.z.literal("d"), 30 | }); 31 | const double = index_1.z.union([aSchema, bSchema]); 32 | const many = index_1.z.union([aSchema, bSchema, cSchema, dSchema]); 33 | doubleSuite 34 | .add("valid: a", () => { 35 | double.parse(objA); 36 | }) 37 | .add("valid: b", () => { 38 | double.parse(objB); 39 | }) 40 | .add("invalid: null", () => { 41 | try { 42 | double.parse(null); 43 | } 44 | catch (err) { } 45 | }) 46 | .add("invalid: wrong shape", () => { 47 | try { 48 | double.parse(objC); 49 | } 50 | catch (err) { } 51 | }) 52 | .on("cycle", (e) => { 53 | console.log(`${doubleSuite.name}: ${e.target}`); 54 | }); 55 | manySuite 56 | .add("valid: a", () => { 57 | many.parse(objA); 58 | }) 59 | .add("valid: c", () => { 60 | many.parse(objC); 61 | }) 62 | .add("invalid: null", () => { 63 | try { 64 | many.parse(null); 65 | } 66 | catch (err) { } 67 | }) 68 | .add("invalid: wrong shape", () => { 69 | try { 70 | many.parse({ type: "unknown" }); 71 | } 72 | catch (err) { } 73 | }) 74 | .on("cycle", (e) => { 75 | console.log(`${manySuite.name}: ${e.target}`); 76 | }); 77 | exports.default = { 78 | suites: [doubleSuite, manySuite], 79 | }; 80 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/object.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const index_1 = require("../index"); 8 | const emptySuite = new benchmark_1.default.Suite("z.object: empty"); 9 | const shortSuite = new benchmark_1.default.Suite("z.object: short"); 10 | const longSuite = new benchmark_1.default.Suite("z.object: long"); 11 | const empty = index_1.z.object({}); 12 | const short = index_1.z.object({ 13 | string: index_1.z.string(), 14 | }); 15 | const long = index_1.z.object({ 16 | string: index_1.z.string(), 17 | number: index_1.z.number(), 18 | boolean: index_1.z.boolean(), 19 | }); 20 | emptySuite 21 | .add("valid", () => { 22 | empty.parse({}); 23 | }) 24 | .add("valid: extra keys", () => { 25 | empty.parse({ string: "string" }); 26 | }) 27 | .add("invalid: null", () => { 28 | try { 29 | empty.parse(null); 30 | } 31 | catch (err) { } 32 | }) 33 | .on("cycle", (e) => { 34 | console.log(`${emptySuite.name}: ${e.target}`); 35 | }); 36 | shortSuite 37 | .add("valid", () => { 38 | short.parse({ string: "string" }); 39 | }) 40 | .add("valid: extra keys", () => { 41 | short.parse({ string: "string", number: 42 }); 42 | }) 43 | .add("invalid: null", () => { 44 | try { 45 | short.parse(null); 46 | } 47 | catch (err) { } 48 | }) 49 | .on("cycle", (e) => { 50 | console.log(`${shortSuite.name}: ${e.target}`); 51 | }); 52 | longSuite 53 | .add("valid", () => { 54 | long.parse({ string: "string", number: 42, boolean: true }); 55 | }) 56 | .add("valid: extra keys", () => { 57 | long.parse({ string: "string", number: 42, boolean: true, list: [] }); 58 | }) 59 | .add("invalid: null", () => { 60 | try { 61 | long.parse(null); 62 | } 63 | catch (err) { } 64 | }) 65 | .on("cycle", (e) => { 66 | console.log(`${longSuite.name}: ${e.target}`); 67 | }); 68 | exports.default = { 69 | suites: [emptySuite, shortSuite, longSuite], 70 | }; 71 | -------------------------------------------------------------------------------- /week-1/basics/strings.js: -------------------------------------------------------------------------------- 1 | // String handbook 2 | 3 | // String: length, indexOf(), lastIndexOf(), slice(), substring(), replace(), 4 | // split(), trim(), toUpperCase(), toLowerCase(), etc. 5 | 6 | // Run each function to see the output, play and learn by doing. 7 | 8 | // Length 9 | function getLength(str) { 10 | console.log("Original String:", str); 11 | console.log("Length:", str.length); 12 | } 13 | getLength("Hello World"); 14 | 15 | // indexOf 16 | function findIndexOf(str, target) { 17 | console.log("Original String:", str); 18 | console.log("Index:", str.indexOf(target)); 19 | } 20 | findIndexOf("Hello World", "World"); 21 | 22 | // lastIndexOf 23 | function findLastIndexOf(str, target) { 24 | console.log("Original String:", str); 25 | console.log("Index:", str.lastIndexOf(target)); 26 | } 27 | findLastIndexOf("Hello World World", "World"); 28 | 29 | // slice 30 | function getSlice(str, start, end) { 31 | console.log("Original String:", str); 32 | console.log("After slice:", str.slice(start, end)); 33 | } 34 | getSlice("Hello World", 0, 5); 35 | 36 | // substring 37 | function getSubstring(str, start, end) { 38 | console.log("Original String:", str); 39 | console.log("After substring:", str.substring(start, end)); 40 | } 41 | getSubstring("Hello World", 0, 5); 42 | 43 | // replace 44 | function replaceString(str, target, replacement) { 45 | console.log("Original String:", str); 46 | console.log("After replace:", str.replace(target, replacement)); 47 | } 48 | replaceString("Hello World", "World", "JavaScript"); 49 | 50 | // split 51 | function splitString(str, separator) { 52 | console.log("Original String:", str); 53 | console.log("After split:", str.split(separator)); 54 | } 55 | splitString("Hello World", " "); 56 | 57 | // trim 58 | function trimString(str) { 59 | console.log("Original String:", str); 60 | console.log("After trim:", str.trim()); 61 | } 62 | trimString(" Hello World "); 63 | 64 | // toUpperCase 65 | function toUpper(str) { 66 | console.log("Original String:", str); 67 | console.log("After toUpperCase:", str.toUpperCase()); 68 | } 69 | toUpper("Hello World"); 70 | 71 | // toLowerCase 72 | function toLower(str) { 73 | console.log("Original String:", str); 74 | console.log("After toLowerCase:", str.toLowerCase()); 75 | } 76 | toLower("Hello World"); 77 | -------------------------------------------------------------------------------- /week-13/blog-stack/validateCommon/node_modules/zod/lib/benchmarks/discriminatedUnion.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const index_1 = require("../index"); 8 | const doubleSuite = new benchmark_1.default.Suite("z.discriminatedUnion: double"); 9 | const manySuite = new benchmark_1.default.Suite("z.discriminatedUnion: many"); 10 | const aSchema = index_1.z.object({ 11 | type: index_1.z.literal("a"), 12 | }); 13 | const objA = { 14 | type: "a", 15 | }; 16 | const bSchema = index_1.z.object({ 17 | type: index_1.z.literal("b"), 18 | }); 19 | const objB = { 20 | type: "b", 21 | }; 22 | const cSchema = index_1.z.object({ 23 | type: index_1.z.literal("c"), 24 | }); 25 | const objC = { 26 | type: "c", 27 | }; 28 | const dSchema = index_1.z.object({ 29 | type: index_1.z.literal("d"), 30 | }); 31 | const double = index_1.z.discriminatedUnion("type", [aSchema, bSchema]); 32 | const many = index_1.z.discriminatedUnion("type", [aSchema, bSchema, cSchema, dSchema]); 33 | doubleSuite 34 | .add("valid: a", () => { 35 | double.parse(objA); 36 | }) 37 | .add("valid: b", () => { 38 | double.parse(objB); 39 | }) 40 | .add("invalid: null", () => { 41 | try { 42 | double.parse(null); 43 | } 44 | catch (err) { } 45 | }) 46 | .add("invalid: wrong shape", () => { 47 | try { 48 | double.parse(objC); 49 | } 50 | catch (err) { } 51 | }) 52 | .on("cycle", (e) => { 53 | console.log(`${doubleSuite.name}: ${e.target}`); 54 | }); 55 | manySuite 56 | .add("valid: a", () => { 57 | many.parse(objA); 58 | }) 59 | .add("valid: c", () => { 60 | many.parse(objC); 61 | }) 62 | .add("invalid: null", () => { 63 | try { 64 | many.parse(null); 65 | } 66 | catch (err) { } 67 | }) 68 | .add("invalid: wrong shape", () => { 69 | try { 70 | many.parse({ type: "unknown" }); 71 | } 72 | catch (err) { } 73 | }) 74 | .on("cycle", (e) => { 75 | console.log(`${manySuite.name}: ${e.target}`); 76 | }); 77 | exports.default = { 78 | suites: [doubleSuite, manySuite], 79 | }; 80 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/backend/routes/account.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const { authMiddleware } = require("../middleware"); 3 | const { Account } = require("../db"); 4 | const { default: mongoose } = require("mongoose"); 5 | 6 | const router = express.Router(); 7 | 8 | router.get("/balance", authMiddleware, async (req, res) => { 9 | const account = await Account.findOne({ 10 | userId: req.userId, 11 | }); 12 | 13 | res.json({ 14 | balance: account.balance, 15 | }); 16 | }); 17 | 18 | router.get("/specific/balance", authMiddleware, async (req, res) => { 19 | try { 20 | const { userId } = req.query; 21 | 22 | if (!mongoose.Types.ObjectId.isValid(userId)) { 23 | return res.status(400).json({ message: "Invalid userId" }); 24 | } 25 | 26 | const account = await Account.findOne({ userId }); 27 | if (!account) { 28 | return res.status(404).json({ message: "Account not found" }); 29 | } 30 | 31 | res.json({ balance: account.balance }); 32 | } catch (error) { 33 | console.error("Error fetching user balance:", error); 34 | res.status(500).json({ message: "Internal server error" }); 35 | } 36 | }); 37 | 38 | router.post("/transfer", authMiddleware, async (req, res) => { 39 | const session = await mongoose.startSession(); 40 | 41 | session.startTransaction(); 42 | const { amount, to } = req.body; 43 | 44 | const account = await Account.findOne({ userId: req.userId }).session( 45 | session 46 | ); 47 | 48 | if (!account || account.balance < amount) { 49 | await session.abortTransaction(); 50 | return res.status(400).json({ 51 | message: "Insufficient balance", 52 | }); 53 | } 54 | 55 | const toAccount = await Account.findOne({ userId: to }).session(session); 56 | 57 | if (!toAccount) { 58 | await session.abortTransaction(); 59 | return res.status(400).json({ 60 | message: "Invalid account", 61 | }); 62 | } 63 | 64 | await Account.updateOne( 65 | { userId: req.userId }, 66 | { $inc: { balance: -amount } } 67 | ).session(session); 68 | await Account.updateOne( 69 | { userId: to }, 70 | { $inc: { balance: amount } } 71 | ).session(session); 72 | 73 | await session.commitTransaction(); 74 | res.json({ 75 | message: "Transfer successful", 76 | }); 77 | }); 78 | 79 | module.exports = router; 80 | -------------------------------------------------------------------------------- /week-13/blog-stack/backend/src/routes/user.ts: -------------------------------------------------------------------------------- 1 | import { Hono } from "hono"; 2 | import { PrismaClient } from '@prisma/client/edge' 3 | import { withAccelerate } from '@prisma/extension-accelerate' 4 | import { sign } from 'hono/jwt' 5 | import { signupInput, signinInput } from "@sai48/medium-validate2"; 6 | 7 | export const userRouter = new Hono<{ 8 | Bindings: { 9 | DATABASE_URL: string; 10 | JWT_SECRET: string; 11 | } 12 | }>(); 13 | 14 | userRouter.post('/signup', async (c) => { 15 | const body = await c.req.json(); 16 | const { success } = signupInput.safeParse(body); 17 | if (!success) { 18 | c.status(411); 19 | return c.json({ 20 | message: "Inputs not correct" 21 | }) 22 | } 23 | const prisma = new PrismaClient({ 24 | datasourceUrl: c.env.DATABASE_URL, 25 | }).$extends(withAccelerate()) 26 | 27 | try { 28 | const user = await prisma.user.create({ 29 | data: { 30 | username: body.username, 31 | password: body.password, 32 | name: body.name 33 | } 34 | }) 35 | const jwt = await sign({ 36 | id: user.id 37 | }, c.env.JWT_SECRET); 38 | 39 | return c.text(jwt) 40 | } catch(e) { 41 | console.log(e); 42 | c.status(411); 43 | return c.text('Invalid') 44 | } 45 | }) 46 | 47 | 48 | userRouter.post('/signin', async (c) => { 49 | const body = await c.req.json(); 50 | const { success } = signinInput.safeParse(body); 51 | if (!success) { 52 | c.status(411); 53 | return c.json({ 54 | message: "Inputs not correct" 55 | }) 56 | } 57 | 58 | const prisma = new PrismaClient({ 59 | datasourceUrl: c.env.DATABASE_URL, 60 | }).$extends(withAccelerate()) 61 | 62 | try { 63 | const user = await prisma.user.findFirst({ 64 | where: { 65 | username: body.username, 66 | password: body.password, 67 | } 68 | }) 69 | if (!user) { 70 | c.status(403); 71 | return c.json({ 72 | message: "Incorrect creds" 73 | }) 74 | } 75 | const jwt = await sign({ 76 | id: user.id 77 | }, c.env.JWT_SECRET); 78 | 79 | return c.text(jwt) 80 | } catch(e) { 81 | console.log(e); 82 | c.status(411); 83 | return c.text('Invalid') 84 | } 85 | }) -------------------------------------------------------------------------------- /week-7/README.md: -------------------------------------------------------------------------------- 1 | # A Mini-PayTM Application 2 | 3 | ### This application allows you 4 | 5 | - To register and login with the email account. 6 | - Users can see their balance and existing users then and there. 7 | - Users can transfer money to existing users & can search for users from the search bar. 8 | - Users can see their profile and update their user information. 9 | - Users can delete the account. 10 | 11 | ### This is a complete `full-stack application` built with `MERN stack` and `Zod` for input validation, `JWT` for authentication, and some more things on the top of the stack. 12 | 13 | ## 1. Users can register and login with the email account. 14 | 15 | ![image](https://github.com/Saivaraprasad48/Paytm_Clone/assets/93783719/5abbbf98-340b-4d1d-8df1-5eb7267a1f13) 16 | 17 | ![image](https://github.com/Saivaraprasad48/Paytm_Clone/assets/93783719/59c8d3c8-acbd-413b-b876-f3d30a2e7b98) 18 | 19 | ## 2. Users can see their balance and existing users then and there. 20 | 21 | ![image](https://github.com/Saivaraprasad48/Paytm_Clone/assets/93783719/9bc588aa-0396-47a5-a5c1-7552ffe45d62) 22 | 23 | ## 3. Users can transfer money to existing users & can search for users from the search bar. 24 | 25 | ![image](https://github.com/Saivaraprasad48/Paytm_Clone/assets/93783719/a61a0190-3e13-42d1-82fe-8f6bbf839b01) 26 | 27 | ![image](https://github.com/Saivaraprasad48/Paytm_Clone/assets/93783719/183a0a51-cc5d-4e6d-880f-6e1366496ece) 28 | 29 | ## 4. Users can see their profiles and update their user information. 30 | 31 | ![image](https://github.com/Saivaraprasad48/Paytm_Clone/assets/93783719/1683f629-8e73-4b99-9ff8-c643aa277a0b) 32 | 33 | ![image](https://github.com/Saivaraprasad48/Paytm_Clone/assets/93783719/6ca7fa9e-0727-4f26-87c1-ee5c5b433be9) 34 | 35 | ![image](https://github.com/Saivaraprasad48/Paytm_Clone/assets/93783719/ca14748c-b94b-4618-9638-05d4ddfc955e) 36 | 37 | ![image](https://github.com/Saivaraprasad48/Paytm_Clone/assets/93783719/8823457d-57d9-4974-8766-b6b9d829feb1) 38 | 39 | ## 5. Users can delete the account. 40 | 41 | ![image](https://github.com/Saivaraprasad48/Paytm_Clone/assets/93783719/b949e219-a35b-4ed0-ba00-c80682d69e6f) 42 | 43 | ![image](https://github.com/Saivaraprasad48/Paytm_Clone/assets/93783719/23ab95e7-ee24-457c-90dc-3aee17980795) 44 | 45 | ## This is a completely CRUD application 46 | 47 | ## Backend 48 | 49 | - ExpressJs 50 | - Nodemon 51 | - Zod input validation 52 | - JWT Auth 53 | 54 | ## Database 55 | 56 | - MongoDB 57 | 58 | ## Frontend 59 | 60 | - ReactJS 61 | - Tailwind 62 | - Axios 63 | - Toastify 64 | -------------------------------------------------------------------------------- /week-7/paytm-fullstack/frontend/src/components/Appbar.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react/prop-types */ 2 | import { useState } from "react"; 3 | import Image from "../assets/paytm.png"; 4 | import { Button } from "./Button"; 5 | import { useNavigate } from "react-router-dom"; 6 | import { toast } from "react-toastify"; 7 | 8 | export const Appbar = ({ user }) => { 9 | const [dropDown, setDropDown] = useState(false); 10 | const navigate = useNavigate(); 11 | 12 | return ( 13 |
14 |
{ 17 | navigate("/dashboard"); 18 | }} 19 | > 20 | icon 21 | 22 | Mini PayTM 23 | 24 |
25 |
setDropDown((p) => !p)} 28 | > 29 |
30 | 👋 {user} 31 |
32 |
33 |
34 | {user[0]} 35 |
36 |
37 | {dropDown && ( 38 |
39 |
65 | )} 66 |
67 |
68 | ); 69 | }; 70 | -------------------------------------------------------------------------------- /week-13/blog-stack/frontend/src/pages/Publish.tsx: -------------------------------------------------------------------------------- 1 | import { Appbar } from "../components/Appbar" 2 | import axios from "axios"; 3 | import { BACKEND_URL } from "../config"; 4 | import { useNavigate } from "react-router-dom"; 5 | import { ChangeEvent, useState } from "react"; 6 | 7 | export const Publish = () => { 8 | const [title, setTitle] = useState(""); 9 | const [description, setDescription] = useState(""); 10 | const navigate = useNavigate(); 11 | 12 | return
13 | 14 |
15 |
16 | { 17 | setTitle(e.target.value) 18 | }} type="text" className="w-full bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" placeholder="Title" /> 19 | 20 | { 21 | setDescription(e.target.value) 22 | }} /> 23 | 36 |
37 |
38 |
39 | } 40 | 41 | 42 | function TextEditor({ onChange }: {onChange: (e: ChangeEvent) => void}) { 43 | return
44 |
45 |
46 |
47 | 48 |