Skip to content

Instantly share code, notes, and snippets.

View rabeehebrahim's full-sized avatar

Rabeeh Ebrahim rabeehebrahim

View GitHub Profile
@rabeehebrahim
rabeehebrahim / app.js
Last active October 28, 2022 06:10
React Input Field Validation: if the value is empty in the form and user click submit, then show 'Name must not be empty' else show nothing.
import react, {useRef, useState} from "react";
const SimpleInput = (props) => {
const [enteredName, setEnteredName] = useState('')
const [enteredNameIsValid, setEnteredNameIsValid] = useState(true)
const nameInputChangeHandler = event => {
setEnteredName(event.target.value)
}
@rabeehebrahim
rabeehebrahim / users.test.ts
Created June 6, 2023 17:00
Replacing jwt token verification middleware when testing end points in jest.
// before importing app and supertest
// you should write jest.mock function
// with the first argument is the path of your
// actual middleware and second argument write a
// fake middle function.
jest.mock('../middleware/verifyToken', () => {
return jest.fn((req, res, next) => {
next()
})
@rabeehebrahim
rabeehebrahim / gist:821a47d3651d279ca7771385853b6d31
Created July 8, 2024 07:11
Get the exact branch from origin branch to local respository in git

To get the main branch in your local project as it is on the original repository, follow these steps:

  1. Fetch the latest changes from the remote:

    git fetch origin
    
  2. Switch to the main branch:

git checkout main

@rabeehebrahim
rabeehebrahim / node_nginx_ssl.md
Last active July 8, 2024 07:15 — forked from bradtraversy/node_nginx_ssl.md
Node app deploy with nginx & SSL

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for Digital Ocean

If you use the referal link below, you get $10 free (1 or 2 months) https://m.do.co/c/5424d440c63a

2. Create a droplet and log in via ssh

I will be using the root user, but would suggest creating a new user

@rabeehebrahim
rabeehebrahim / gist:ca8d8345bcc844ed756679f31cb99adf
Last active July 8, 2024 11:22
Nginx Config file for AWS Hosting /etc/nginx/sites-available/default
server {
server_name website.com www.website.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 40
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
@rabeehebrahim
rabeehebrahim / logDB.ts
Created July 15, 2024 06:37
Creating a Transaction Example in Sequelize ORM
import Log from "../model";
import { ILogs } from "../types";
export const createALog = async (tenantId: string, table: string, logId: string, options: any) => {
const args = {TenantID: tenantId, Table: table, logId}
return await Log.create(args, options)
}