dataDesk BLOG

Welcome to the blog of Mr.G


Blog 36: New_Project.md | (Open) | (Share)

▲ Previous | Next ▼

/Dev/HowTo/Git

Last modified: March 16 2025 12:44:13

New Project

To add your project to GitLab, follow these steps:


1️⃣ Create a New Repository on GitLab

  1. Go to your GitLab account.
  2. Click on New Project.
  3. Choose Create Blank Project.
  4. Give your project a name (e.g., my-ubuntu-project).
  5. Set visibility (Private, Internal, or Public).
  6. Click Create Project.
  7. Copy the Git URL (e.g., git@gitlab.com:username/my-ubuntu-project.git).

2️⃣ Initialize Git in Your Project Folder

Open a terminal and navigate to your project folder:

cd /path/to/your/project

Initialize Git:

git init

Set the GitLab remote repository:

git remote add origin git@gitlab.com:username/my-ubuntu-project.git

(Replace username with your GitLab username and my-ubuntu-project.git with your repo name.)


3️⃣ Add and Push Your Files

Stage all files:

git add .

Commit with a message:

git commit -m "Initial commit"

Push your project:

git branch -M main  # Ensure you're on the main branch
git push -u origin main

4️⃣ (Optional) Set Up SSH for GitLab

If you haven't already set up SSH authentication:

ssh-keygen -t rsa -b 4096 -C "your-email@example.com"

Copy your SSH key:

cat ~/.ssh/id_rsa.pub

Add it to GitLab (Profile → Preferences → SSH Keys).


! [rejected] main -> main (fetch first)
error: failed to push some refs to 'digts.de:firstgroup/user-handling-2.0.git'

Solution

This error occurs because the remote GitLab repository already has some commits that your local repository doesn’t have. To fix it, follow these steps:


1️⃣ Fetch and Merge Remote Changes

First, pull the latest changes from the remote repository before pushing your local changes:

git pull --rebase origin main

If you get a merge conflict, Git will show the affected files. You’ll need to manually resolve them and commit.


2️⃣ Force Push (If Needed)

If you are sure your local version is correct and you want to overwrite the remote changes, you can force push:

git push -f origin main

⚠ Warning: This will overwrite the remote repository with your local version, erasing any remote changes.


3️⃣ Alternative: Create a Backup Branch

If you’re unsure about force pushing, create a backup before pulling:

git branch backup-main
git push origin backup-main

Then try:

git pull --rebase origin main
git push origin main

4️⃣ If You Want to Keep Both Local & Remote Changes

Instead of --rebase, do a merge:

git pull origin main
# Resolve conflicts if needed
git commit -am "Merged remote changes"
git push origin main

gitignore


1️⃣ Check If config.php Is Still Tracked Locally

Run:

git ls-files | grep config.php
  • If it returns nothing, Git is not tracking config.php.
  • If it shows config.php, Git is still tracking it.

To be sure, check:

git status

If config.php is listed under "Untracked files", it means it's not in Git anymore (which is what you want).


2️⃣ Ensure config.php Is Ignored

To prevent Git from tracking it in the future, add it to .gitignore:

echo "config.php" >> .gitignore
git add .gitignore
git commit -m "Ignore config.php"
git push origin main

Now config.php will never be added again.




Blog 37: Css_generator_test.md | (Open) | (Share)

▲ Previous | Next ▼

/

(Last modified: March 12 2025 08:55:20)

Css generator test


<style>
.parent {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 8px;
}

.div1 {
    grid-column: span 3 / span 3;
    grid-row: span 5 / span 5;
    grid-column-start: 2;
    grid-row-start: 1;
}

.div2 {
    grid-row: span 3 / span 3;
    grid-column-start: 1;
    grid-row-start: 1;
}

.div3 {
    grid-row: span 2 / span 2;
    grid-column-start: 1;
    grid-row-start: 4;
}

.div4 {
    grid-column-start: 5;
    grid-row-start: 1;
}

.div5 {
    grid-row: span 4 / span 4;
    grid-column-start: 5;
    grid-row-start: 2;
}
        </style>

<div class="parent">
    <div class="div1">1 main</div>
    <div class="div2">2 top left</div>
    <div class="div3">3 bottom left</div>
    <div class="div4">4 top right</div>
    <div class="div5">5 bottom right</div>
</div>
1 main
2 top left
3 bottom left
4 top right
5 bottom right

alt text



Blog 38: Client-Side_Pagination___Fast_Pagination.md | (Open) | (Share)

▲ Previous | Next ▼

/Dev/Tutorials

Last modified: March 09 2025 09:34:57

Client-Side Pagination / Fast Pagination

Yes, you’re thinking in the right direction! This is called "Client-Side Pagination" (or "Fast Pagination"), and it's commonly used in tools like DataTables, React Tables, and many modern UI frameworks.


✅ Two Approaches for Fast Pagination

Since you want to fetch 100 items from MySQL at once and then allow the user to navigate within those results without hitting the database again, here are two ways to do it:


🏆 Best Approach: Client-Side Pagination (Load All at Once)

Steps:

  1. Fetch all data at once (e.g., 100 items from MySQL).
  2. Store the data in the browser’s memory (JavaScript array).
  3. Paginate within the already loaded data (using .slice() in JavaScript).

🔧 Code Implementation

1️⃣ Modify searchEbay() to Fetch All Results at Once

async function searchEbay(dbOnly = false, newSearch = false, page = 1) {
    const response = await fetch(
        `search_ebay.php?q=${encodeURIComponent(query)}&dbOnly=${dbOnly}${filterString}&limit=100`
    );

    const data = await response.json();

    // Normalize item list
    window.cachedItems = Array.isArray(data.items) ? data.items : []; // Store results globally

    renderPage(page);  // Show the first page
}

2️⃣ Modify loadPage() to Just Slice the Data (No More Fetching!)

function loadPage(page) {
    renderPage(page); // Just render a new page, don't re-fetch data
}

3️⃣ Modify Pagination to Use Local Data

function renderPage(page) {
    const limit = 25;
    const start = (page - 1) * limit;
    const end = page * limit;

    const pageItems = window.cachedItems.slice(start, end); // Use the cached data

    document.querySelector("#itemContainer").innerHTML = pageItems.map(item => `
${item.name}
`).join(''); const paginationHtml = renderPagination(window.cachedItems.length, limit, page); document.querySelector("#paginationContainer").innerHTML = paginationHtml; }

4️⃣ First Search Loads Data, Later Pages Use Cached Data

  • The first time, searchEbay() fetches 100 results.
  • All results are stored in window.cachedItems.
  • When clicking pagination buttons, loadPage(page) only slices the data — no more database calls!

🚀 Benefits of This Approach

✅ Super fast pagination (no extra database queries).
✅ Smoother user experience (only updates UI, not the whole page).
✅ Reduces load on your server (fewer SQL queries).


💾 Alternative: Cache JSON on the Server

If you want to avoid fetching data repeatedly from MySQL, you can:

  1. Save the results into a JSON file on the server.
  2. Fetch the JSON file instead of hitting MySQL again.

🔧 Server-Side JSON Cache Example

1️⃣ Modify search_ebay.php

$cacheFile = 'cache/results.json';

// If cache file exists and is fresh, return it
if (file_exists($cacheFile) && time() - filemtime($cacheFile) 

2️⃣ Modify JavaScript to Fetch JSON Instead of MySQL

async function searchEbay(page = 1) {
    const response = await fetch('cache/results.json');
    const data = await response.json();

    window.cachedItems = data.items || [];
    renderPage(page);
}

✅ Which Approach is Best?

Approach Best For Downsides
Client-Side Pagination (Cache in JavaScript) Most cases where results are under ~500 items Uses memory, needs initial full load
Server-Side Cached JSON Large datasets where fetching 100+ items at once might be slow Cache expires, slower than pure client-side

🏆 Final Recommendation



Blog 39: Javascript_Shortcuts.md | (Open) | (Share)

▲ Previous | Next ▼

/Dev/Tutorials

(Last modified: March 12 2025 12:12:34)

Javascript Shortcuts

Vanilla JavaScript supports import, but there are a few things to keep in mind.

1. Using import in Vanilla JavaScript

You can use ES Modules (ECMAScript Modules) in plain JavaScript without frameworks by adding type="module" to your

✅ It works natively in modern browsers!


2. Important Rules for Using import in Vanilla JS

  1. You Must Use type="module"

    • Normal scripts () won’t support import.
    • Use:
  2. Modules Must Be Served Over HTTP (No file:// Access)

    • If you open index.html directly in your browser (file://), you’ll get a CORS error.
    • Solution: Run a local server.
      • Python: python -m http.server
      • Node.js: npx http-server
      • VS Code: Use the "Live Server" extension.
  3. Modules Are Automatically in "Strict Mode"

    • You don’t need "use strict";—ES modules enforce strict mode by default.
  4. Module Scope Is Isolated

    • Variables inside a module are not global.
    • Example: const test = 123; in domUtils.js won’t be available in main.js unless explicitly exported.

3. Alternative Without import: Use window

If you don’t want to use import, you can still define global functions in a separate script:

📄 domUtils.js

window.q = (selector) => document.querySelector(selector);
window.qa = (selector) => document.querySelectorAll(selector);
window.on = (el, event, callback) => el.addEventListener(event, callback);

Then, just include it before your main script:


Now you can use q(), qa(), and on() anywhere without importing them.


Which One Should You Use?

  • For modern, scalable projects: Use import/export with type="module".
  • For simple scripts without a server: Use window.q = ... in a separate script.

If you like staying compatible and keeping things clean, the module approach (import/export) is best for long-term maintainability.



Blog 40: Cronjob.md | (Open) | (Share)

▲ Previous

/Dev/HowTo

(Last modified: March 11 2025 12:50:46)

Cronjob


🔥 Cron Time Cheat Sheet

Expression Runs At
0 7 * * * 7:00 AM every day
10 7 * * * 7:10 AM every day
0 7 10 * * 7:00 AM on the 10th of each month
0 7 * * 1 7:00 AM every Monday
0 7 * 6 * 7:00 AM every day in June


Who I am

"Just me, myself, and I, exploring the universe of unknownment, embracing the mystery of what lies beyond, one star at a time."

Share this page on Facebook | X.com | Reddit

Page Content

  • Image New Project
    Published: 2025-03-16
    Read
  • Image Css generator test
    Published: 2025-03-13
    Read
  • Image Client-Side Pagination Fast Pagination
    Published: 2025-03-12
    Read
  • Image Javascript Shortcuts
    Published: 2025-03-12
    Read
  • Image Cronjob
    Published: 2025-03-11
    Read

Tags

WebDev New York London AI NORWAY DIY Ideas Life Family News Clothing Invest Sports Health