Skip to content

Instantly share code, notes, and snippets.

@AhmadHRai
AhmadHRai / TablePagination.md
Last active December 13, 2023 19:32
Table Pagination in React/Nextjs (with Tailwind CSS)

To implement pagination for an HTML table in a Next.js project with Tailwind CSS, you can follow these steps:

  1. Create a state for the current page and the number of rows per page: You can use the useState hook from React to create these states. The initial value for the current page can be 1, and the initial value for the number of rows per page can be 10.
const [currentPage, setCurrentPage] = useState(1);
const [rowsPerPage, setRowsPerPage] = useState(10);
  1. Calculate the total number of pages: You can calculate the total number of pages by dividing the total number of rows by the number of rows per page. If there's a remainder, you add 1 to the total number of pages to account for the last page that might not be full.
@AhmadHRai
AhmadHRai / prune-git-history.md
Created January 15, 2024 14:54
Pushed .env File to Remote? Steps to Remove and Add to .gitignore

If you accidentally push a .env file to a remote repository, you should immediately take steps to remove it and add it to .gitignore to prevent it from being tracked in the future. Here are the detailed steps:

Step 1: Remove the file from your repository's history

Use the git filter-branch command to rewrite the history of your repository and remove the file. Replace PATH-TO-YOUR-FILE with the actual path to the .env file in your repository.

git filter-branch --force --index-filter\
 "git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE"\
@AhmadHRai
AhmadHRai / emptyString.md
Created April 20, 2024 11:57
Ways to check if a string is null, empty or equals an empty string ('')
  1. Using the typeof Operator and length Property:
  • Check if the variable is a string and its length is 0
let str = "";
if (typeof str === "string" && str.length === 0) {
  console.log("The string is empty");
}
  1. Using the length Property Directly: