Skip to content

Instantly share code, notes, and snippets.

@edoves
edoves / gitbash.md
Last active October 30, 2024 14:17

Git and GitHub Essentials

1. Basic Git Commands for Cloning and Collaboration

  • Clone a Repository: git clone <repository-url>
  • Navigate to Directory: cd <directory>
  • List Directory Contents: ls
  • Check Git Status: git status (useful for verification)
  • Add File to Staging Area: git add <filename>
  • Commit Changes: git commit -m "Your commit message here"
  • Push Changes: git push
@edoves
edoves / Readme1.md
Last active September 3, 2024 11:46
PDO Class Object

Signup and SignIn and Signout

class Database
{
    private $host = "localhost";
    private $db_name = "mydb";
    private $username = "root";
    private $password = "";
    public $conn;
@edoves
edoves / readme.md
Last active October 28, 2024 07:02
Which strategy is most effective for reducing load on a Node.js server during high traffic?

Which strategy is most effective for reducing load on a Node.js server during high traffic?

To effectively reduce load on a Node.js server during high traffic, the following strategies are highly effective:

1. Implement Caching:

  • Static Caching: Use tools like Nginx or Varnish as a reverse proxy to cache static assets (e.g., HTML, CSS, JS, images) and reduce server load by serving cached responses.
  • Dynamic Caching: Cache frequently accessed API responses using Redis or Memcached. This reduces the number of database queries and computations.

2. Load Balancing:

  • Distribute incoming traffic across multiple Node.js servers using a load balancer like Nginx, HAProxy, or AWS ELB. This helps manage traffic spikes by spreading the load evenly across your servers.

If two asynchronous functions depend on each other, what should be used to maintain execution order?

If two asynchronous functions depend on each other and you need to maintain execution order, you should use async and await to control the sequence of execution. The await keyword ensures that the second function only runs after the first function has completed, preserving the correct order.

Here's an example:

async function firstFunction() {
    // Some asynchronous operation
    return new Promise(resolve => setTimeout(() => {
@edoves
edoves / 1renderinnextjs.md
Last active November 6, 2024 02:26
Static Rendering vs Dynamic Rendering

Static Rendering vs Dynamic Rendering

Static rendering and dynamic rendering are two approaches used to serve web pages, each with distinct advantages and use cases. Here’s a breakdown of each:

Static Rendering

Definition: In static rendering, the HTML content is generated at build time and served as is to users. Each page is pre-generated as a static HTML file, which doesn’t change until a new build is triggered.

Advantages:

  1. Performance: Static files load faster since they don’t require server processing for each request.
@edoves
edoves / ssh-key-setup.md
Created October 30, 2024 14:37
Generate a New SSH Key and Add it to your GitHub

Generate a New SSH Key and Add it to your GitHub

After following this video in setting up your ssh-key with a custom algo like id_custom you might end up having error. the next step is add a configuration

To create or update an SSH config file (~/.ssh/config), follow these steps:

1. Open the Terminal

2. Open the Config File

@edoves
edoves / readme.md
Created October 30, 2024 14:39
How to add typescript to an existing vite react app?

How to add typescript to an existing vite react app?

  1. Install typescript, @types/react and @types/react-dom.
npm install --save-dev typescript @types/react @types/react-dom
  1. In packages.json, replace vite build with tsc && vite build.
"build": "vite build"
@edoves
edoves / readme1.md
Created October 30, 2024 14:42
Gulp Questions

Question 1?

Can you help with gulp rendering my css and js during production and development current html files is on the root folder. the src folder includes scss and js files and directory the problem is how I am going to set up my <script src=""></script> that it will in both production and development

Answer

To handle CSS and JavaScript rendering in both production and development environments using Gulp, you can follow these steps:

1. Folder Structure

Let's assume your folder structure is something like this:

@edoves
edoves / controllerExpress.md
Created October 30, 2024 14:44
How to use catchAsync with Class conroller in both function declaration and class fields

How to use catchAsync with Class conroller in both function declaration and class fields

catchAsync function

import { NextFunction, Request, Response } from 'express'

type AsyncFunction = (
  req: Request,
  res: Response,
  next: NextFunction
@edoves
edoves / contextApi.md
Created October 30, 2024 14:45
Context API setup with Typescript

Context API setup with Typescript

Step 1: Define Types

First, define the interfaces for your products and cart items. Create a file types.ts for these definitions: types.ts

export Type Product {
  id: number;
  name: string;
  price: number;