DeveloperBreeze

Snippets Programming Tutorials, Guides & Best Practices

Explore 196+ expertly crafted snippets tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

How to Create a New MySQL User with Full Privileges

Code May 01, 2025

CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

Configuring SQLAlchemy with PostgreSQL on Heroku: A Quick Guide

Code November 08, 2024
python

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import os

app = Flask(__name__)

# Adjust the DATABASE_URL format for SQLAlchemy compatibility
database_url = os.getenv("DATABASE_URL", "")
if database_url.startswith("postgres://"):
    database_url = database_url.replace("postgres://", "postgresql+psycopg2://")

app.config["SQLALCHEMY_DATABASE_URI"] = database_url

# Initialize the SQLAlchemy object
db = SQLAlchemy(app)

# Sample route to test the setup
@app.route("/")
def index():
    return "Database URI setup complete!"

if __name__ == "__main__":
    app.run()
  • This code retrieves the DATABASE_URL from the environment.
  • If DATABASE_URL starts with postgres://, it replaces it with postgresql+psycopg2://.
  • The db instance is initialized with SQLAlchemy(app) for use with SQLAlchemy ORM.
  • The replacement of "postgres://" with "postgresql+psycopg2://" is necessary because of a compatibility issue between the URI format provided by Heroku and the URI format expected by SQLAlchemy.

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

Code October 25, 2024
php

  • 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.

This script will ensure that both the posts and their associated media files are removed from the WordPress database and the filesystem.

How to Paste in an SSH Terminal Without a Mouse

Code October 20, 2024
bash

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

Vite vs Webpack

Note August 14, 2024
javascript nodejs

  • 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.