The Ultimate
Snippet Library.

Hundreds of production-ready scripts and coding solutions.
Brought to you by the experts at DigitalCodeLabs.

PHP

Aggregate PHP Array Values to a Single Result

Master `array_reduce()` to iterate through an array and progressively build a single result, like a sum, concatenation, or complex object, using a callback function.

View Snippet →
BASH

Securely Sync Local Files to Remote Server with Rsync

Automate secure file deployments from your local machine to a remote web server using rsync, ensuring only changed files are transferred efficiently.

View Snippet →
BASH

Automate Compressed MySQL Database Backups

Learn to create automated, timestamped, and gzipped backups of your MySQL or MariaDB databases, essential for disaster recovery and data protection.

View Snippet →
BASH

Check and Restart Web Service if Down

Create a robust Bash script to periodically check the status of a web service (e.g., Nginx, Apache) and automatically restart it if it's not running.

View Snippet →
SQL

Finding Duplicate Rows

Efficiently identify all duplicate rows in your SQL table based on specified columns. This snippet helps in data cleaning and maintaining unique data integrity.

View Snippet →
SQL

Calculate Running Total with Self-Join

Learn how to compute a cumulative sum or running total for your data using a SQL self-join. This technique is valuable for financial analysis and trend tracking.

View Snippet →
SQL

Find Gaps in a Numeric Sequence

Discover how to locate missing IDs or gaps in a continuous numeric sequence within your SQL table. Essential for auditing and ensuring data completeness.

View Snippet →
SQL

Delete Duplicate Rows Keeping One

Clean your SQL table by removing duplicate rows, while ensuring one unique record based on a set of columns is preserved. Crucial for data maintenance.

View Snippet →
SQL

Conditional Aggregation with CASE

Perform multiple counts or sums based on different conditions within a single SQL query using `CASE` statements. Ideal for concise reporting and dashboards.

View Snippet →
JAVASCRIPT

Validate Email Address

Validate email addresses with a robust JavaScript regex pattern, ensuring correct format for user input in web forms and applications.

View Snippet →
JAVASCRIPT

Validate Strong Password

Enforce strong password policies using a JavaScript regex to check for minimum length, uppercase, lowercase, numbers, and special characters.

View Snippet →
JAVASCRIPT

Sanitize Input: Remove Non-Alphanumeric Characters

Clean user input by removing all characters that are not letters or numbers, using a simple and effective JavaScript regex `replace` method.

View Snippet →