The Ultimate
Snippet Library.

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

SQL

Find Duplicate Rows Based on a Column

Discover how to identify and list duplicate entries in your SQL database based on one or more columns, essential for data cleansing and integrity checks.

View Snippet →
SQL

Upsert (Insert or Update) Data in MySQL

Implement an 'upsert' operation in MySQL to either insert new records or update existing ones if a key conflict occurs, streamlining data management.

View Snippet →
SQL

Count Related Items for Each Parent Record

Learn to count associated records from a child table for each parent record using a LEFT JOIN and GROUP BY, useful for summary reports.

View Snippet →
SQL

Generate Conditional Summary Report with CASE

Create flexible summary reports by conditionally counting or summing values based on specific criteria within a single SQL query using CASE statements.

View Snippet →
JAVASCRIPT

Dynamically Create and Append Elements from an Array

Learn how to programmatically create multiple new DOM elements from a JavaScript array of data and efficiently append them to a parent container.

View Snippet →
JAVASCRIPT

Read and Write Custom Data Attributes with `dataset`

Learn how to easily access and modify custom HTML5 `data-*` attributes on DOM elements using the convenient `dataset` property in JavaScript.

View Snippet →
JAVASCRIPT

Smoothly Scroll an Element into View

Learn how to programmatically scroll to any DOM element on your page, with an option for smooth scrolling behavior, enhancing user experience.

View Snippet →
BASH

Automate PostgreSQL Database Backups with Retention

Learn to automate PostgreSQL database backups using bash, incorporating timestamps for versioning and implementing a retention policy to manage old backups efficiently.

View Snippet →
BASH

Securely Deploy Website Files with Rsync and SSH

Master using rsync over SSH for efficient and secure deployment of website files, including excluding specific directories and verbose output for debugging.

View Snippet →
BASH

Monitor Server Disk Space and Send Email Alerts

Implement a bash script to monitor server disk space usage, automatically sending an email alert when a predefined threshold is exceeded, preventing potential outages.

View Snippet →
BASH

Parse Command Line Arguments in Bash with getopts

Discover how to robustly parse command-line options and arguments in bash scripts using `getopts`, supporting both short and long options for flexible script execution.

View Snippet →
BASH

Interact with REST APIs using cURL and Parse JSON with jq

Learn to make authenticated GET and POST requests to REST APIs using `curl` and effectively parse the JSON responses with `jq` in your bash scripts for automation.

View Snippet →