DeveloperBreeze

Calculate Age from Birthdate

$birthdate = '1990-01-01';
$age = date_diff(date_create($birthdate), date_create('today'))->y;
echo $age;

Continue Reading

Discover more amazing content handpicked just for you

Code

How to Create a New MySQL User with Full Privileges

No preview available for this content.

May 01, 2025
Read More
Code
python

Configuring SQLAlchemy with PostgreSQL on Heroku: A Quick Guide

  • When you provision a PostgreSQL database on Heroku, it sets an environment variable called DATABASE_URL with the connection string for your database.
  • This URI uses the format postgres://.
  • SQLAlchemy (especially when using the psycopg2 driver for PostgreSQL) requires the URI to be in the format postgresql+psycopg2://.
  • This prefix specifies the dialect (postgresql) and the driver (psycopg2) explicitly, which SQLAlchemy uses to establish the connection.

Nov 08, 2024
Read More
Code
php

How to Delete All WordPress Posts and Their Uploads Using a Custom PHP Script

<?php
// Load WordPress environment
require_once('/path/to/your/wp-load.php');

// Get all posts (any post type)
$args = array(
    'post_type'      => 'any', // 'any' retrieves all post types (posts, pages, custom post types)
    'post_status'    => 'any', // 'any' retrieves all post statuses
    'posts_per_page' => -1,    // Retrieve all posts
);

$all_posts = get_posts($args);

foreach ($all_posts as $post) {
    // Get the post ID
    $post_id = $post->ID;

    // Check if the post has attachments (media files)
    $attachments = get_attached_media('', $post_id);

    // Delete each attachment associated with the post
    foreach ($attachments as $attachment) {
        $attachment_id = $attachment->ID;
        // This deletes the file from the uploads directory and the database record
        wp_delete_attachment($attachment_id, true);
    }

    // Delete the post itself
    wp_delete_post($post_id, true); // true = force delete, bypass trash
}

echo 'All posts and their uploads have been deleted.';
  • Backup: Make sure you have a backup of your database and uploads folder before running this script.
  • Use on a staging site: Test it on a staging environment before running on a live site, as it will permanently delete all posts and their uploads.

Oct 25, 2024
Read More
Code
php

How To enable all error debugging in PHP

No preview available for this content.

Oct 25, 2024
Read More
Code
bash

How to Paste in an SSH Terminal Without a Mouse

  • Copy: Select text (it automatically copies to the clipboard).
  • Paste: Right-click or Shift + Insert.
  • Copy: Ctrl + Shift + C
  • Paste: Ctrl + Shift + V

Oct 20, 2024
Read More
Note
javascript nodejs

Vite vs Webpack

  • Vite: Vite handles modern JavaScript features natively, leveraging the browser’s capabilities during development and optimizing for production only when needed.
  • Webpack: Webpack can bundle any kind of asset (JavaScript, CSS, images, etc.) and provides advanced features like code splitting, tree shaking, and asset management, but these can add complexity to the build process.
  • Vite: Vite has a growing ecosystem with plugins, and it's designed to be framework-agnostic, although it has strong support for Vue and React.
  • Webpack: Webpack has a mature ecosystem with a vast array of plugins and integrations, making it suitable for complex and large-scale projects.

Aug 14, 2024
Read More
Code
nodejs graphql

GraphQL API Server with Node.js and Apollo Server

Install the required packages:

   npm install express apollo-server-express graphql

Aug 12, 2024
Read More
Code
javascript

React Custom Hook for API Requests

  • Custom Headers: Extend the hook to accept custom headers or authentication tokens in the options parameter.
  • Polling: Implement a polling mechanism by setting up a setInterval within the useEffect for periodically fetching data.
  • Data Transformation: Add a callback function to transform the fetched data before setting it in state.

Aug 12, 2024
Read More
Code
csharp

Unity Inventory System using Scriptable Objects

No preview available for this content.

Aug 12, 2024
Read More
Code
csharp

Unity Player Controller Blueprint

No preview available for this content.

Aug 12, 2024
Read More
Code
bash

Bash: How to Loop Over Files in a Directory

No preview available for this content.

Aug 12, 2024
Read More
Code
csharp

C#: How to Read a File

No preview available for this content.

Aug 12, 2024
Read More
Code
html

HTML: Basic Template Structure

No preview available for this content.

Aug 12, 2024
Read More
Code
php

PHP: How to Connect to a MySQL Database

No preview available for this content.

Aug 12, 2024
Read More
Code
css

CSS: How to Center a Div Horizontally and Vertically

No preview available for this content.

Aug 12, 2024
Read More
Code
java

Java: How to Sort a List

No preview available for this content.

Aug 12, 2024
Read More
Code
javascript nodejs

Node.js: How to Create an HTTP Server

No preview available for this content.

Aug 12, 2024
Read More
Code
sql

SQL: How to Select Top N Records

No preview available for this content.

Aug 12, 2024
Read More
Code
python

Python: How to Reverse a String

No preview available for this content.

Aug 12, 2024
Read More
Code
javascript json

How to Deep Clone a JavaScript Object

No preview available for this content.

Aug 12, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!