The Ultimate
Snippet Library.

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

BASH

Manage Node.js Versions with NVM

Learn how to efficiently switch between different Node.js versions using nvm (Node Version Manager) in your development environment for various project requirements.

View Snippet →
BASH

Run Multiple Dev Servers Concurrently

Discover a simple bash script to simultaneously start multiple web development servers (e.g., frontend, backend, mock API) in the background, streamlining your local development workflow.

View Snippet →
BASH

Check for Open Ports and Kill Processes

Learn how to use a bash script to check if a specific port is in use and, if desired, automatically identify and terminate the process occupying that port.

View Snippet →
BASH

Automate Git Branch Cleanup

Streamline your Git workflow with a bash script that automatically deletes merged local branches that are no longer needed, helping to keep your repository tidy.

View Snippet →
BASH

Dynamic API Endpoint Switching

Configure dynamic API endpoints for development, staging, or production environments using a simple bash script that exports environment variables.

View Snippet →
SQL

Rank Records within Groups using Window Functions

Learn to use SQL window functions like ROW_NUMBER() and RANK() to assign ranks to records within specific groups, perfect for leaderboards or top-N queries.

View Snippet →
SQL

Perform an UPSERT Operation with ON DUPLICATE KEY UPDATE (MySQL)

Master the MySQL UPSERT pattern to either insert new rows or update existing ones if a unique key conflict occurs, ensuring data integrity efficiently.

View Snippet →
SQL

Query Hierarchical Data with Recursive Common Table Expressions

Discover how to traverse and query tree-like or hierarchical data structures (e.g., organizational charts, categories) using powerful SQL Recursive CTEs.

View Snippet →
SQL

Aggregate Rows into JSON Arrays and Objects (PostgreSQL)

Learn to transform relational data into structured JSON format directly within PostgreSQL using `json_build_object`, `json_agg`, and `json_object_agg`.

View Snippet →
BASH

Automate Daily Backups with Timestamps

Learn to create a bash script for automating daily backups of a directory, incorporating timestamps for unique archives and using tar for compression.

View Snippet →
BASH

Monitor Directory for New Files and Process

Implement a bash script that continuously monitors a specified directory for new files, processes them, and moves them to an archived location.

View Snippet →
BASH

Robust Error Handling and Logging

Enhance your bash scripts with robust error handling and logging capabilities, ensuring critical failures are caught and reported clearly.

View Snippet →