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

# 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 Snippets21](/codesnippets)[Cloud1](/codesnippets/categories/cloud)[Aws6](/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)[View All…](/codesnippets/categories)

[All Snippets21](/codesnippets)[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)[Javascript1](/codesnippets/javascript)[Python7](/codesnippets/python)[Typescript3](/codesnippets/typescript)

LanguageAllBash (7)Python (7)Typescript (3)Bash and Python (1)Javascript (1)Python, Node.js and Go (1)SQL and Python (1)CategoryAllDevops (9)Aws (6)Shell scripting (6)Backend (5)Python (5)Automation (3)Nodejs (3)Productivity (3)Database (2)Performance (2)Ai ml (1)Async (1)Bash (1)Clean code (1)Cloud (1)Computer vision (1)Data modeling (1)Document processing (1)Linux (1)Networking (1)Security (1)Typescript (1)TagAllPython (8)DevOps (7)Bash (6)AWS (5)NodeJS (5)Shell Scripting (5)Automation (4)Performance (4)Configuration (3)S3 (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)Terminal (2)Validation (2)AI Models (1)Aiohttp (1)Asyncio (1)AWS SDK v3 (1)BestPractices (1)BigData (1)Caching (1)CloudSecurity (1)Computer Vision (1)Context managers (1)Cron (1)CRUD (1)Database (1)Dataclass (1)DataScience (1)Document Processing (1)DocumentClient (1)Dotenv (1)DynamoDB (1)EC2 (1)Echo (1)Exitstack (1)Exponential Backoff (1)File upload (1)Flock (1)Frozen (1)Go (1)HTTP (1)Indexes (1)Infrastructure (1)Locking (1)Machine Learning (1)MemoryOptimization (1)MLOps (1)MultiEnvironment (1)Multipart (1)OCR (1)Open Source (1)Optimization (1)Pid file (1)PostgreSQL (1)Presigned url (1)Printf (1)Pydantic (1)QueryOptimization (1)Redis (1)Resources (1)Retry (1)Scripting (1)Scripting Best Practices (1)SecretsManagement (1)SecretsManager (1)Security (1)Shell (1)Slots (1)SQL (1)Text Recognition (1)Vault (1)With statement (1)Zod (1)Zsh (1)SortNewest firstOldest firstA to ZShortest read first

[![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)

[![AWS Secrets Manager](/_astro/hero.BIDl4oI2_Z1yJEXf.webp)](/codesnippets/post/nodejs-aws-secrets-manager)

## [AWS Secrets Manager](/codesnippets/post/nodejs-aws-secrets-manager)

-   [Aws](/codesnippets/categories/aws)
-   [Devops](/codesnippets/categories/devops)
-   18 Jun 2025
-   03 Mins read

Loading secrets in a Node.js app without exposing them If you're still storing API keys or database credentials in .env files or hardcoding them into your codebase, it's time for a better appro

[#NodeJS](/codesnippets/tags/nodejs)[#TypeScript](/codesnippets/tags/typescript)[#AWS](/codesnippets/tags/aws)+3 tags

[Typescript](/codesnippets/typescript)

[View Code](/codesnippets/post/nodejs-aws-secrets-manager)

[![Check S3 Bucket Existence](/_astro/hero.CWiO4GWV_1YUYTb.webp)](/codesnippets/post/bash-s3-bucket-exists)

## [Check S3 Bucket Existence](/codesnippets/post/bash-s3-bucket-exists)

-   [Aws](/codesnippets/categories/aws)
-   [Shell scripting](/codesnippets/categories/shell-scripting)
-   11 Jun 2025
-   02 Mins read

Quick Tip Don't let your deployment blow up because of a missing S3 bucket. This Bash script lets you check if a bucket exists before anything fails. The Problem Missing bucket failure

[#Bash](/codesnippets/tags/bash)[#AWS](/codesnippets/tags/aws)[#DevOps](/codesnippets/tags/devops)+3 tags

[Bash](/codesnippets/bash)

[View Code](/codesnippets/post/bash-s3-bucket-exists)

[](/codesnippets/page/2)

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

Page 3 of 3

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

-   [Cloud1](/codesnippets/categories/cloud)
-   [Aws6](/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)
-   [Nodejs3](/codesnippets/categories/nodejs)
-   [Database2](/codesnippets/categories/database)
-   [Typescript1](/codesnippets/categories/typescript)
-   [Backend5](/codesnippets/categories/backend)
-   [Performance2](/codesnippets/categories/performance)
-   [Linux1](/codesnippets/categories/linux)
-   [Python5](/codesnippets/categories/python)
-   [Async1](/codesnippets/categories/async)
-   [Networking1](/codesnippets/categories/networking)
-   [Clean code1](/codesnippets/categories/clean-code)
-   [Data modeling1](/codesnippets/categories/data-modeling)
-   [Ai ml1](/codesnippets/categories/ai-ml)
-   [Computer vision1](/codesnippets/categories/computer-vision)
-   [Document processing1](/codesnippets/categories/document-processing)

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

[#Aws5](/codesnippets/tags/aws)[#Ec21](/codesnippets/tags/ec2)[#Boto32](/codesnippets/tags/boto3)[#Python8](/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)[#S33](/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)[#Nodejs5](/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)[#Validation2](/codesnippets/tags/validation)[#Dotenv1](/codesnippets/tags/dotenv)[#Backend2](/codesnippets/tags/backend)[#Presigned url1](/codesnippets/tags/presigned-url)[#File upload1](/codesnippets/tags/file-upload)[#Multipart1](/codesnippets/tags/multipart)[#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)[#Context managers1](/codesnippets/tags/context-managers)[#With statement1](/codesnippets/tags/with-statement)[#Exitstack1](/codesnippets/tags/exitstack)[#Resources1](/codesnippets/tags/resources)[#Dataclass1](/codesnippets/tags/dataclass)[#Slots1](/codesnippets/tags/slots)[#Frozen1](/codesnippets/tags/frozen)[#Pydantic1](/codesnippets/tags/pydantic)[#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)
