dataDesk BLOG

Welcome to the blog of Mr.G


Blog 16: Tailwind_3_CSS_-_CLI_+_local_build.md | (Open) | (Share)

▲ Previous | Next ▼

/Dev/Design/Tailwind

(Last modified: July 30 2025 23:27:27)

Tailwind 3 CSS - CLI + local build

A clean summary of how we got Tailwind CSS working without the CDN, using the CLI + local build setup:


✅ Your Working Tailwind Setup: Summary

1. Issue: Tailwind v4 didn't include the CLI binary

  • You tried installing Tailwind v4.x (^4.1.11)
  • npx tailwindcss init failed
  • node_modules/.bin/tailwindcss was missing
  • Confusion from missing docs/warnings

2. Fix: Downgraded to stable Tailwind v3.4.3

npm uninstall tailwindcss
npm install -D tailwindcss@^3.4.3 postcss autoprefixer

✅ This version includes the CLI (tailwindcss) binary


3. Initialized config files

npx tailwindcss init -p

Created:

  • tailwind.config.js
  • postcss.config.js

4. Created input file

src/input.css:

@tailwind base;
@tailwind components;
@tailwind utilities;

5. Configured tailwind.config.js

content: [
  "./**/*.html",
  "./**/*.php",
  "./**/*.js",
  "!./node_modules/**/*", // ⛔ exclude unnecessary scanning
]

6. Replaced CDN with compiled CSS

From:

<script src="https://cdn.tailwindcss.com"></script>

To:

<link href="/dist/output.css" rel="stylesheet">

7. Built the Tailwind output

🔁 For development:

npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch

🛠 For one-time build:

npx tailwindcss -i ./src/input.css -o ./dist/output.css

✅ Result:

You now have a fully working, production-ready Tailwind setup, with:

  • Class scanning and purging
  • Local builds (fast, offline)
  • No bloat from unused CSS
  • Full customization support (themes, plugins)

Let me know if you want to:

  • Add minification for production builds
  • Add dark mode support
  • Set up a ready-to-deploy structure (with HTML/PHP)



Blog 17: DHH-Managers-are-useless---Leave-enginee_1753203515358.md | (Open) | (Share)

▲ Previous | Next ▼

/WebDAV/SyncPhone

(Last modified: July 22 2025 23:30:07)

DHH: Managers are useless - Leave engineers the hell alone | Lex Fridman Podcast Clips - YouTube

thumbnail
#menu">DHH: Managers are useless - Leave engineers the hell alone | Lex Fridman Podcast Clips - YouTube



Blog 18: Laravel-vs-Core-PHP_1753184273875.md | (Open) | (Share)

▲ Previous | Next ▼

/Dev/PHP

Last modified: July 22 2025 13:37:55

Laravel’s expressive, feature-rich layers come at the cost of some extra overhead compared to “plain” or “core” PHP. Below are several common scenarios where you’ll typically see Laravel slower than equivalent core-PHP code, along with illustrative examples:


1. Framework Bootstrapping & Routing

Why it’s slower:
Every request in Laravel must bootstrap the entire framework—load service providers, configuration, middleware, etc.—before even dispatching your route.

// core PHP (public/index.php)
$start = microtime(true);
if ($_SERVER['REQUEST_URI'] === '/hello') {
    echo 'Hello, world!';
}
$time = microtime(true) - $start;
error_log("core PHP boot + dispatch: {$time}");
# Laravel (public/index.php → handled by /routes/web.php)
Route::get('/hello', function () {
    return 'Hello, world!';
});

// Measured in public/index.php:
$start = microtime(true);
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
$response = $app->handle(
    $request = Illuminate\Http\Request::capture()
);
$response->send();
$app->terminate($request, $response);
$time = microtime(true) - $start;
error_log("Laravel boot + dispatch: {$time}");

Typical result:
– Core PHP: \~0.5 ms
– Laravel: \~10–20 ms

The bulk of that difference is framework initialization and routing logic.


2. Simple Database Queries: PDO vs Eloquent

Why it’s slower:
Eloquent adds layers (models, relationships, collections) that make each query more convenient—but heavier.

// core PHP using PDO
$pdo = new PDO($dsn, $user, $pass);
$start = microtime(true);
$stmt = $pdo->query('SELECT * FROM posts WHERE id = 1');
$post = $stmt->fetch(PDO::FETCH_ASSOC);
$time = microtime(true) - $start;
error_log("PDO query: {$time}");
// Laravel using Eloquent
use App\Models\Post;

$start = microtime(true);
$post = Post::find(1);
$time = microtime(true) - $start;
Log::info("Eloquent find: {$time}");

Typical result:
– PDO raw fetch: \~1 ms
– Eloquent → Model hydration: \~3–5 ms


3. Bulk Inserts

Why it’s slower:
Inserting many rows one-by-one with Eloquent invokes events, mass-assignment checks, and individual queries.

// core PHP bulk insert
$data = [];
for ($i = 0; $i < 1000; $i++) {
    $data[] = "(?, ?)";
    $bindings[] = "Title {$i}";
    $bindings[] = "Body {$i}";
}
$sql = "INSERT INTO posts (title, body) VALUES " . implode(',', $data);
$start = microtime(true);
$pdo->prepare($sql)->execute($bindings);
$time = microtime(true) - $start;
error_log("PDO bulk insert: {$time}");
// Laravel Eloquent looped insert
$start = microtime(true);
for ($i = 0; $i < 1000; $i++) {
    Post::create([
        'title' => "Title {$i}",
        'body'  => "Body {$i}",
    ]);
}
$time = microtime(true) - $start;
Log::info("Eloquent 1000× create: {$time}");

Typical result:
– PDO single bulk statement: \~15–30 ms
– Eloquent in a loop: \~800–1200 ms

Tip: For large datasets in Laravel, use the query builder’s insert() with a batch array:

Post::insert($arrayOf1000Rows);

4. View Rendering

Why it’s slower:
Blade templates are compiled to PHP then rendered, and include features like sections, inheritance, and directives.

// core PHP simple include
$start = microtime(true);
extract(['name' => 'Alice']);
include 'views/hello.php';  // just: <?php echo "Hello, $name"; ?>
$time = microtime(true) - $start;
error_log("PHP include view: {$time}");
// Laravel Blade
// resources/views/hello.blade.php
// Hello, {{ $name }}

$start = microtime(true);
return view('hello', ['name' => 'Alice']);
$time = microtime(true) - $start;
Log::info("Blade render: {$time}");

Typical result:
– PHP include: \~0.2 ms
– Blade render: \~2–4 ms


5. Middleware Pipeline

Why it’s slower:
Each middleware class adds a function call and possibly logic (authentication, CSRF, logging, etc.) before reaching your controller.



Blog 19: php_in_html_..._endif.md | (Open) | (Share)

▲ Previous | Next ▼

/Dev/HowTo/PHP

(Last modified: July 06 2025 18:56:10)

php in html ... endif


<?php if($this->value): ?>
Hello
<?php elseif($this->asd): ?>
Your name is: <?= $this->name ?>
<?php else: ?>
You don't have a name.
<?php endif; ?>



Blog 20: User_Authentication_Flow.md | (Open) | (Share)

▲ Previous

/Projects/dataDesk/Docs

(Last modified: June 06 2025 23:21:24)

User Authentication Flow

User Authentication Flow

🔐 User Authentication Flow

1. Entry Point: index.php

When the user navigates to the sign-in page, the app is accessed via:

index.php/?page=signin

Route Handling:

switch ($route) {
    case 'signin':
        $force = $_GET['force_select'] ?? null;

        if (isset($_SESSION['user_id']) && !$force) {
            // User already signed in and not switching accounts
            header("Location: ./");
            exit;
        }

        require __DIR__ . '/app/auth/signin.html';
        break;
}
  • If the user is already signed in and not explicitly forcing account switch, they are redirected to the homepage.
  • Otherwise, the signin.html page is loaded.

2. Sign-In Form Submission: /app/auth/signin.html

JavaScript sends the form data via fetch:

fetch('./user.php?action=signin', {
    method: 'POST',
    body: formData
})
.then(response => response.json())
.then(data => {
    if (data.status === "success") {
        window.location.href = data.redirect;
    }
});
  • Sends a POST request to user.php?action=signin
  • If login is successful, the user is redirected to the given URL.

3. Login Handler: user.php

require 'config.php';
require 'includes/AuthManager.php';

$auth = new AuthManager($pdo);
$action = $_GET['action'] ?? '';

header('Content-Type: application/json');

try {
    switch ($action) {
        case 'signin':
            $email = $_POST['email'] ?? '';
            $password = $_POST['password'] ?? '';
            $remember = isset($_POST['remember_me']);
            echo json_encode($auth->login($email, $password, $remember));
            break;
    }
} catch (Exception $e) {
    echo json_encode([
        "status" => "error",
        "message" => $e->getMessage()
    ]);
}
  • Loads dependencies and initializes AuthManager
  • Handles signin action by calling login() with form data
  • Returns a JSON response indicating success or error

4. Authentication Logic: AuthManager.php

public function login($email, $password, $remember_me = false)
{
    // Validate user and authenticate (code omitted)
    $_SESSION['user_id'] = $user['id'];

    if ($remember_me) {
        setcookie("remember_token", $remember_token, [...]);
        setcookie("remember_selector", $remember_selector, [...]);
    }

    return [
        "status" => "success",
        "message" => "Welcome, you are now signed in!",
        "redirect" => $redirectUrl
    ];
}
  • Authenticates the user and stores their ID in $_SESSION
  • If "Remember Me" is checked, persistent cookies are set
  • Returns a JSON response with status and redirect URL

https://mermaid.live/


sequenceDiagram
    participant U as User
    participant B as Browser (index.php)
    participant F as signin.html
    participant S as user.php
    participant A as AuthManager

    U->>B: Request /?page=signin
    B->>F: Load signin.html
    F->>S: POST user.php?action=signin
    S->>A: login(email, password, remember)
    A-->>S: JSON (status, redirect)
    S-->>F: JSON response
    F->>U: Redirect to success page

alt text


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 Tailwind 3 CSS - CLI + local build
    Published: 2025-07-30
    Read
  • Image DHH-Managers-are-useless---Leave-enginee 1753203515358
    Published: 2025-07-23
    Read
  • Image Laravel-vs-Core-PHP 1753184273875
    Published: 2025-07-22
    Read
  • Image php in html ... endif
    Published: 2025-07-06
    Read
  • Image User Authentication Flow
    Published: 2025-06-07
    Read

Tags

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