DeveloperBreeze

Leap Year Checker

javascript
// Function to check if a year is a leap year
function isLeapYear(year) {
    return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
}

// Example: Check if the year 2024 is a leap year
const year = 2024;
console.log('Is Leap Year:', isLeapYear(year));

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

  • If the DATABASE_URL starts with postgres:// (Heroku's default), it replaces it with the correct format, postgresql+psycopg2://, making the URI compatible with SQLAlchemy.

Instead of manually replacing the URI, you can use libraries like dj-database-url to parse and adapt the DATABASE_URL for different frameworks or drivers. However, the manual approach is straightforward and works well for most cases.

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 is designed to be faster, especially in development mode. It achieves this by serving native ES modules directly to the browser, which eliminates the need for a full bundle during development. It also uses an optimized Hot Module Replacement (HMR) system, which significantly speeds up updates.
  • Webpack: Webpack bundles the entire project before serving it, which can make the development process slower, especially for larger projects. However, it also provides a robust and flexible environment for production builds.
  • Vite: Vite comes with a simpler configuration out of the box. It’s opinionated, meaning it has built-in best practices and defaults, making it easier to get started with.
  • Webpack: Webpack is highly configurable and can be customized extensively, but this flexibility often comes with a steeper learning curve and more complex configuration files.

Aug 14, 2024
Read More
Code
nodejs graphql

GraphQL API Server with Node.js and Apollo Server

   node index.js

Open a browser and go to http://localhost:4000/graphql. You'll see the Apollo GraphQL Playground, where you can test your queries and mutations.

Aug 12, 2024
Read More
Code
javascript

React Custom Hook for API Requests

No preview available for this content.

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

-- For SQL Server
SELECT TOP 10 * FROM Customers;

-- For MySQL and PostgreSQL
SELECT * FROM Customers LIMIT 10;

-- For Oracle
SELECT * FROM (SELECT * FROM Customers) WHERE ROWNUM <= 10;

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!