---
title: "Code Snippets - Reusable Code Examples and Solutions"
lang: "en"
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/page/2
---

# Code Snippets

Working code you can lift straight into a project: shell, Python, TypeScript, Terraform. Each snippet says what it does and where it bites.

[All Snippets18](/codesnippets)[Cloud1](/codesnippets/categories/cloud)[Aws5](/codesnippets/categories/aws)[Devops9](/codesnippets/categories/devops)[Automation3](/codesnippets/categories/automation)[Shell scripting6](/codesnippets/categories/shell-scripting)[Productivity3](/codesnippets/categories/productivity)[More…](/codesnippets/categories)

[Bash and Python1](/codesnippets/bash-and-python)[Python, Node.js and Go1](/codesnippets/python-nodejs-and-go)[SQL and Python1](/codesnippets/sql-and-python)[Bash7](/codesnippets/bash)[Python5](/codesnippets/python)[Typescript3](/codesnippets/typescript)

LanguageAllBash (7)Python (5)Typescript (3)Bash and Python (1)Python, Node.js and Go (1)SQL and Python (1)CategoryAllDevops (9)Shell scripting (6)Aws (5)Automation (3)Productivity (3)Python (3)Backend (2)Database (2)Nodejs (2)Performance (2)Ai ml (1)Async (1)Bash (1)Cloud (1)Computer vision (1)Document processing (1)Linux (1)Networking (1)Security (1)Typescript (1)TagAllDevOps (7)Bash (6)Python (6)Shell Scripting (5)Automation (4)AWS (4)NodeJS (4)Performance (4)Configuration (3)TypeScript (3)Backend (2)Boto3 (2)CI/CD (2)Cloud (2)Concurrency (2)DevTools (2)Environment Variables (2)IAM (2)Linux (2)Microservices (2)POSIX (2)Productivity (2)S3 (2)Terminal (2)AI Models (1)Aiohttp (1)Asyncio (1)AWS SDK v3 (1)BestPractices (1)BigData (1)Caching (1)CloudSecurity (1)Computer Vision (1)Cron (1)CRUD (1)Database (1)DataScience (1)Document Processing (1)DocumentClient (1)Dotenv (1)DynamoDB (1)EC2 (1)Echo (1)Exponential Backoff (1)Flock (1)Go (1)HTTP (1)Indexes (1)Infrastructure (1)Locking (1)Machine Learning (1)MemoryOptimization (1)MLOps (1)MultiEnvironment (1)OCR (1)Open Source (1)Optimization (1)Pid file (1)PostgreSQL (1)Printf (1)QueryOptimization (1)Redis (1)Retry (1)Scripting (1)Scripting Best Practices (1)SecretsManagement (1)SecretsManager (1)Security (1)Shell (1)SQL (1)Text Recognition (1)Validation (1)Vault (1)Zod (1)Zsh (1)SortNewest firstOldest firstA to ZShortest read first

[![Multi-Environment Secret Management with HashiCorp Vault](/_astro/hero.B4H3tk7I_1BuPOM.webp)](/codesnippets/post/hashicorp-vault-multi-environment-secrets)

## [Multi-Environment Secret Management with HashiCorp Vault](/codesnippets/post/hashicorp-vault-multi-environment-secrets)

-   [Security](/codesnippets/categories/security)
-   [Devops](/codesnippets/categories/devops)
-   03 Mar 2026
-   04 Mins read

Managing secrets safely across multiple environments with HashiCorp Vault Storing secrets in .env files, hardcoding them, or even using separate secret managers per environment creates security

[#Vault](/codesnippets/tags/vault)[#SecretsManagement](/codesnippets/tags/secretsmanagement)[#MultiEnvironment](/codesnippets/tags/multienvironment)+3 tags

[Bash and Python](/codesnippets/bash-and-python)

[View Code](/codesnippets/post/hashicorp-vault-multi-environment-secrets)

[![Top 7 Open Source OCR Models for Document Processing](/_astro/hero.DIJ2knuO_ah4wu.webp)](/codesnippets/post/top-7-open-source-ocr-models)

## [Top 7 Open Source OCR Models for Document Processing](/codesnippets/post/top-7-open-source-ocr-models)

-   [Ai ml](/codesnippets/categories/ai-ml)
-   [Computer vision](/codesnippets/categories/computer-vision)
-   09 Jan 2026
-   04 Mins read

AI Tool Turn your documents into accurate digital copies with these open source OCR models. Instead of fighting messy text extraction, you get clean markdown from PDFs, images, and scanned docume

[#OCR](/codesnippets/tags/ocr)[#Computer Vision](/codesnippets/tags/computer-vision)[#Document Processing](/codesnippets/tags/document-processing)+5 tags

[Python](/codesnippets/python)

[View Code](/codesnippets/post/top-7-open-source-ocr-models)

[![Why printf Beats echo in Linux Scripts](/_astro/hero.Dl3YkIwZ_Z1w9hux.webp)](/codesnippets/post/printf-beats-echo-linux-scripts)

## [Why printf Beats echo in Linux Scripts](/codesnippets/post/printf-beats-echo-linux-scripts)

-   [Shell scripting](/codesnippets/categories/shell-scripting)
-   [Devops](/codesnippets/categories/devops)
-   02 Jan 2026
-   03 Mins read

Scripting Tip A script that works on your machine can produce different output on another system. The output command is often the reason. printf behaves the same way across shells, and echo d

[#Bash](/codesnippets/tags/bash)[#Shell Scripting](/codesnippets/tags/shell-scripting)[#Printf](/codesnippets/tags/printf)+5 tags

[Bash](/codesnippets/bash)

[View Code](/codesnippets/post/printf-beats-echo-linux-scripts)

[![Essential Bash Variables for Every Script](/_astro/hero.B4bDowyY_YQpD7.webp)](/codesnippets/post/essential-bash-variables)

## [Essential Bash Variables for Every Script](/codesnippets/post/essential-bash-variables)

-   [Shell scripting](/codesnippets/categories/shell-scripting)
-   [Devops](/codesnippets/categories/devops)
-   26 Dec 2025
-   08 Mins read

Overview Quick Tip You know what's worse than writing scripts? Writing scripts that break every time you move them to a different machine. Built-in Bash variables fix that. The problem wi

[#Bash](/codesnippets/tags/bash)[#Shell Scripting](/codesnippets/tags/shell-scripting)[#Linux](/codesnippets/tags/linux)+4 tags

[Bash](/codesnippets/bash)

[View Code](/codesnippets/post/essential-bash-variables)

[![Per-App Shell History for Bash](/_astro/hero.Da_6jPH6_Z1EorRD.webp)](/codesnippets/post/bash-per-app-history)

## [Per-App Shell History for Bash](/codesnippets/post/bash-per-app-history)

-   [Shell scripting](/codesnippets/categories/shell-scripting)
-   [Productivity](/codesnippets/categories/productivity)
-   18 Dec 2025
-   02 Mins read

Organize your Bash history per terminal app. Ever jumped between iTerm2, Ghostty, and VS Code's terminal only to have your command history get all mixed up? This Bash snippet keeps things clean b

[#Bash](/codesnippets/tags/bash)[#Shell Scripting](/codesnippets/tags/shell-scripting)[#Productivity](/codesnippets/tags/productivity)+3 tags

[Bash](/codesnippets/bash)

[View Code](/codesnippets/post/bash-per-app-history)

[![Per-App Shell History for Zsh](/_astro/hero.DRenzVy__1xwzSL.webp)](/codesnippets/post/zsh-per-app-history)

## [Per-App Shell History for Zsh](/codesnippets/post/zsh-per-app-history)

-   [Shell scripting](/codesnippets/categories/shell-scripting)
-   [Productivity](/codesnippets/categories/productivity)
-   18 Dec 2025
-   02 Mins read

Organize your shell history per terminal app. Ever jumped between iTerm2, Ghostty, and VS Code's terminal only to have your command history get all mixed up? This Zsh snippet keeps things clean b

[#Zsh](/codesnippets/tags/zsh)[#Shell Scripting](/codesnippets/tags/shell-scripting)[#Productivity](/codesnippets/tags/productivity)+3 tags

[Bash](/codesnippets/bash)

[View Code](/codesnippets/post/zsh-per-app-history)

[![Optimizing your python code with \_\_slots\_\_?](/_astro/hero.DP_vYsHU_gYDXn.webp)](/codesnippets/post/python-slots-optimization)

## [Optimizing your python code with \_\_slots\_\_?](/codesnippets/post/python-slots-optimization)

-   [Python](/codesnippets/categories/python)
-   [Productivity](/codesnippets/categories/productivity)
-   16 Jul 2025
-   04 Mins read

Memory optimization with slots Understanding the problem Optimizing data models in big data workflows with slots In big data and MLOps workflows, you often work with massive

[#Python](/codesnippets/tags/python)[#MemoryOptimization](/codesnippets/tags/memoryoptimization)[#DataScience](/codesnippets/tags/datascience)+4 tags

[Python](/codesnippets/python)

[View Code](/codesnippets/post/python-slots-optimization)

[![List S3 Buckets](/_astro/hero.BsiJ6hry_1X9XLn.webp)](/codesnippets/post/python-list-s3-buckets)

## [List S3 Buckets](/codesnippets/post/python-list-s3-buckets)

-   [Aws](/codesnippets/categories/aws)
-   [Python](/codesnippets/categories/python)
-   25 Jun 2025
-   02 Mins read

Overview Multi-profile S3 management Ever juggled multiple AWS accounts and needed a quick S3 bucket inventory across all of them? This Python script handles it. Use case Perfect for or

[#Python](/codesnippets/tags/python)[#Boto3](/codesnippets/tags/boto3)[#AWS](/codesnippets/tags/aws)+5 tags

[Python](/codesnippets/python)

[View Code](/codesnippets/post/python-list-s3-buckets)

[](/codesnippets)

[1](/codesnippets)[2](/codesnippets/page/2)[3](/codesnippets/page/3)

[](/codesnippets/page/3)Page 2 of 3

### [Categories](/codesnippets/categories)

-   [Cloud1](/codesnippets/categories/cloud)
-   [Aws5](/codesnippets/categories/aws)
-   [Devops9](/codesnippets/categories/devops)
-   [Automation3](/codesnippets/categories/automation)
-   [Shell scripting6](/codesnippets/categories/shell-scripting)
-   [Productivity3](/codesnippets/categories/productivity)
-   [Bash1](/codesnippets/categories/bash)
-   [Security1](/codesnippets/categories/security)
-   [Nodejs2](/codesnippets/categories/nodejs)
-   [Database2](/codesnippets/categories/database)
-   [Typescript1](/codesnippets/categories/typescript)
-   [Backend2](/codesnippets/categories/backend)
-   [Performance2](/codesnippets/categories/performance)
-   [Linux1](/codesnippets/categories/linux)
-   [Python3](/codesnippets/categories/python)
-   [Async1](/codesnippets/categories/async)
-   [Networking1](/codesnippets/categories/networking)
-   [Ai ml1](/codesnippets/categories/ai-ml)
-   [Computer vision1](/codesnippets/categories/computer-vision)
-   [Document processing1](/codesnippets/categories/document-processing)

### [Tags](/codesnippets/tags)

[#Aws4](/codesnippets/tags/aws)[#Ec21](/codesnippets/tags/ec2)[#Boto32](/codesnippets/tags/boto3)[#Python6](/codesnippets/tags/python)[#Devops7](/codesnippets/tags/devops)[#Automation4](/codesnippets/tags/automation)[#Iam2](/codesnippets/tags/iam)[#Cloud2](/codesnippets/tags/cloud)[#Infrastructure1](/codesnippets/tags/infrastructure)[#Bash6](/codesnippets/tags/bash)[#Shell scripting5](/codesnippets/tags/shell-scripting)[#Productivity2](/codesnippets/tags/productivity)[#Devtools2](/codesnippets/tags/devtools)[#Terminal2](/codesnippets/tags/terminal)[#Configuration3](/codesnippets/tags/configuration)[#Retry1](/codesnippets/tags/retry)[#Exponential backoff1](/codesnippets/tags/exponential-backoff)[#Cicd2](/codesnippets/tags/cicd)[#Shell1](/codesnippets/tags/shell)[#S32](/codesnippets/tags/s3)[#Pid file1](/codesnippets/tags/pid-file)[#Locking1](/codesnippets/tags/locking)[#Flock1](/codesnippets/tags/flock)[#Cron1](/codesnippets/tags/cron)[#Concurrency2](/codesnippets/tags/concurrency)[#Linux2](/codesnippets/tags/linux)[#Environment variables2](/codesnippets/tags/environment-variables)[#Posix2](/codesnippets/tags/posix)[#Vault1](/codesnippets/tags/vault)[#Secretsmanagement1](/codesnippets/tags/secretsmanagement)[#Multienvironment1](/codesnippets/tags/multienvironment)[#Security1](/codesnippets/tags/security)[#Nodejs4](/codesnippets/tags/nodejs)[#Typescript3](/codesnippets/tags/typescript)[#Secretsmanager1](/codesnippets/tags/secretsmanager)[#Cloudsecurity1](/codesnippets/tags/cloudsecurity)[#Dynamodb1](/codesnippets/tags/dynamodb)[#Aws sdk v31](/codesnippets/tags/aws-sdk-v3)[#Crud1](/codesnippets/tags/crud)[#Documentclient1](/codesnippets/tags/documentclient)[#Zod1](/codesnippets/tags/zod)[#Validation1](/codesnippets/tags/validation)[#Dotenv1](/codesnippets/tags/dotenv)[#Backend2](/codesnippets/tags/backend)[#Postgresql1](/codesnippets/tags/postgresql)[#Queryoptimization1](/codesnippets/tags/queryoptimization)[#Indexes1](/codesnippets/tags/indexes)[#Performance4](/codesnippets/tags/performance)[#Sql1](/codesnippets/tags/sql)[#Database1](/codesnippets/tags/database)[#Microservices2](/codesnippets/tags/microservices)[#Printf1](/codesnippets/tags/printf)[#Echo1](/codesnippets/tags/echo)[#Scripting best practices1](/codesnippets/tags/scripting-best-practices)[#Aiohttp1](/codesnippets/tags/aiohttp)[#Asyncio1](/codesnippets/tags/asyncio)[#Http1](/codesnippets/tags/http)[#Scripting1](/codesnippets/tags/scripting)[#Memoryoptimization1](/codesnippets/tags/memoryoptimization)[#Datascience1](/codesnippets/tags/datascience)[#Mlops1](/codesnippets/tags/mlops)[#Bigdata1](/codesnippets/tags/bigdata)[#Bestpractices1](/codesnippets/tags/bestpractices)[#Redis1](/codesnippets/tags/redis)[#Caching1](/codesnippets/tags/caching)[#Go1](/codesnippets/tags/go)[#Optimization1](/codesnippets/tags/optimization)[#Ocr1](/codesnippets/tags/ocr)[#Computer vision1](/codesnippets/tags/computer-vision)[#Document processing1](/codesnippets/tags/document-processing)[#Open source1](/codesnippets/tags/open-source)[#Ai models1](/codesnippets/tags/ai-models)[#Machine learning1](/codesnippets/tags/machine-learning)[#Text recognition1](/codesnippets/tags/text-recognition)[#Zsh1](/codesnippets/tags/zsh)
