Skip to content

Instantly share code, notes, and snippets.

View oelbaga's full-sized avatar

Omar Elbaga oelbaga

View GitHub Profile
@oelbaga
oelbaga / gist:b77d38eb9706b5ff01ea909e5aa24f81
Created February 14, 2023 02:17
Update Array of Objects in React State
//add object to state
setProducts([
...products,
{
product_id: newproduct.product_id,
product_name: newproduct.product_name,
},
]);
@oelbaga
oelbaga / gist:9e2789be304b622b9df9141544ce7b8d
Created February 14, 2023 02:13
NextJS connect to My SQL db connection wrapper
import mysql from "mysql2/promise";
export async function query({ query, values = [] }) {
// PlanetScale;
const dbconnection = await mysql.createConnection(
process.env.MYSQL_DATABASE_URL
);
//Digital ocean ubuntu
// const dbconnection = await mysql.createConnection({
@oelbaga
oelbaga / gist:fed237d3a2b38b2b0b2bd43286b86e12
Created February 14, 2023 02:06
Create MySQL user to access database from React/NextJS
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL ON *.* TO 'username'@'localhost';
GRANT ALL ON *.* TO 'username'@'%';
@oelbaga
oelbaga / 01 - Setup Nextjs site on Ubuntu Server - Terminal commands
Last active May 7, 2024 11:05
Setup NextJS app on Digital Ocean Ubuntu server Full Terminal Commands Step by Step
#Setup NextJS on Ubuntu server (Digital Ocean, EC2,...) Terminal Commands
#based on my YouTube video
#Recommended: An ubuntu server with at least 2 GB memory to handle npm run build
#login to server
ssh root@ip_address
#Upgrade Server - may take a few minutes
sudo apt update
sudo apt upgrade