The Ultimate
Snippet Library.

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

JAVASCRIPT

Access Child Methods in Vue 3 with `ref` and `defineExpose`

Learn how to call methods of a child component directly from its parent in Vue 3 by using template refs and explicitly exposing methods with `defineExpose`.

View Snippet →
PHP

Secure Input Handling: Escape HTML & Sanitize for Database

Learn to prevent XSS and SQL injection by properly escaping HTML output and sanitizing user inputs using prepared statements in PHP, enhancing web application security.

View Snippet →
PHP

Implement Secure Password Hashing and Verification

Discover how to securely hash and verify user passwords in PHP using the `password_hash()` and `password_verify()` functions, a critical step for robust user authentication.

View Snippet →
PHP

Strengthen PHP Session Security Practices

Enhance PHP session security by implementing session regeneration, secure cookie flags, and proper session destruction to prevent session fixation and hijacking attacks.

View Snippet →
JAVASCRIPT

Add Basic API Rate Limiting to Express.js

Implement a basic rate limiting middleware for Express.js applications to protect against brute-force attacks and API abuse by restricting the number of requests per client.

View Snippet →
JAVASCRIPT

Configure Secure CORS for Express.js APIs

Learn to securely configure Cross-Origin Resource Sharing (CORS) in your Express.js API, controlling which domains can access your resources and preventing unauthorized cross-origin requests.

View Snippet →
BASH

Automatically Clean Up Old Log and Temp Files

Learn to create a Bash script that automatically identifies and deletes old log files or temporary files from a specified directory, preventing disk space issues.

View Snippet →
BASH

Extract Unique IP Addresses from Web Server Access Logs

Create a Bash script to efficiently parse web server access logs (Apache/Nginx) and extract all unique IP addresses, useful for security analysis or traffic monitoring.

View Snippet →
BASH

Check if a Port is in Use or a Service is Running

Write a Bash script to verify if a specific TCP port is actively being used by a process or if a given service process is currently running on the system.

View Snippet →
BASH

Batch Rename Multiple Files with a Specific Pattern

Learn to use a Bash script to efficiently rename multiple files in a directory by applying a common prefix, suffix, or replacing parts of their names.

View Snippet →
PHP

Find Common Values Across Multiple PHP Arrays

Efficiently identify and extract all values that are present in every one of several PHP arrays using the `array_intersect` function, useful for data validation or finding common elements.

View Snippet →
PHP

Re-index PHP Array After Element Removal

Understand how to reset and re-sequence numeric keys in a PHP array after elements have been removed using `unset`, ensuring sequential indexing starting from zero.

View Snippet →