Posts

Enforcing Singleton per Thread with Thread-Local Storage

Image
Learn how to enforce the Singleton design pattern per thread in Python using thread-local storage to ensure each thread maintains its own Singleton instance. Enforcing Singleton Per Thread in Python Using Thread-Local Storage In this tutorial, we explore how to enforce the Singleton design pattern per thread in Python. This approach ensures that each thread maintains its own unique instance of a Singleton object, which is particularly useful in multi-threaded applications that require thread-specific data isolation. Why Thread-Local Singleton? Normally, the Singleton pattern restricts instantiation to a single object globally. However, in multi-threaded programs, there are scenarios where each thread needs its own Singleton instance, isolated from other threads. This prevents shared state conflicts and race conditions. What is Thread-Local Storage? Thread-local storage (TLS) allows data to be stored such that each thread...

Viewing Commit History git log

Image
Learn how to view the commit history in Git using the `git log` command with useful formatting options for better readability. Viewing Commit History with git log One of Git’s strengths is its detailed and accessible project history. The git log command allows you to view past commits, helping you track changes and debug issues. Basic Usage of git log To see a list of recent commits in your repository: git log This shows each commit’s hash, author, date, and message. Common git log Options 1. Compact One-Line Summary git log --oneline Shows each commit in a single line, useful for quick browsing. 2. Show Last 3 Commits git log -3 --oneline Limits the output to the last three commits in one-line format. 3. Graph View git log --graph --oneline --all Displays commit history as a branch graph, handy for visualizing branching and merging. Viewing Specif...

Viewing Commit History git log

Image
Learn how to view the commit history in Git using the `git log` command with useful formatting options for better readability. Viewing Commit History with git log One of Git’s strengths is its detailed and accessible project history. The git log command allows you to view past commits, helping you track changes and debug issues. Basic Usage of git log To see a list of recent commits in your repository: git log This shows each commit’s hash, author, date, and message. Common git log Options 1. Compact One-Line Summary git log --oneline Shows each commit in a single line, useful for quick browsing. 2. Show Last 3 Commits git log -3 --oneline Limits the output to the last three commits in one-line format. 3. Graph View git log --graph --oneline --all Displays commit history as a branch graph, handy for visualizing branching and merging. Viewing Specif...

Freeze Class Attributes Using setattr Override

Image
Learn how to freeze class attributes in Python by overriding setattr, preventing accidental changes and ensuring data integrity. Freezing Class Attributes in Python with __setattr__ Override In Python, classes are highly dynamic. Attributes can be added, changed, or removed on the fly. However, in some situations, you may want to make your class attributes immutable after initialization. This prevents accidental modifications that could lead to bugs or inconsistent state. Why Freeze Attributes? Freezing attributes is helpful in data models, configuration objects, or any case where object state should remain constant after creation. By overriding __setattr__ , we can control how and when attributes are assigned. Basic Example of __setattr__ Override The following example shows how to make class attributes immutable after initialization: class Frozen: def __init__(self, name, age): super().__setattr__(...

Freeze Class Attributes Using setattr Override

Image
Learn how to freeze class attributes in Python by overriding setattr, preventing accidental changes and ensuring data integrity. Freezing Class Attributes in Python with __setattr__ Override In Python, classes are highly dynamic. Attributes can be added, changed, or removed on the fly. However, in some situations, you may want to make your class attributes immutable after initialization. This prevents accidental modifications that could lead to bugs or inconsistent state. Why Freeze Attributes? Freezing attributes is helpful in data models, configuration objects, or any case where object state should remain constant after creation. By overriding __setattr__ , we can control how and when attributes are assigned. Basic Example of __setattr__ Override The following example shows how to make class attributes immutable after initialization: class Frozen: def __init__(self, name, age): super().__setattr__(...

Understanding the Git Directory Structure git folder

Image
Learn about the hidden `.git` directory, its internal structure, and how Git stores your project’s history and configuration data. Understanding the Git Directory Structure (.git Folder) Every Git repository contains a hidden .git folder at its root. This folder holds all the internal data Git uses to manage your project, including commit history, branches, and configuration. What is the .git Folder? The .git directory makes a folder a Git repository. Without it, Git commands won't work in that directory. To see it: ls -a Look for a directory named .git . Key Subdirectories and Files inside .git config: Repository-specific configuration settings. HEAD: Points to the current branch reference. objects/: Stores all commits, trees, and blobs (Git’s data model). refs/: Contains references like branches and tags. logs/: Keeps a log of all reference updates....

Understanding the Git Directory Structure git folder

Image
Learn about the hidden `.git` directory, its internal structure, and how Git stores your project’s history and configuration data. Understanding the Git Directory Structure (.git Folder) Every Git repository contains a hidden .git folder at its root. This folder holds all the internal data Git uses to manage your project, including commit history, branches, and configuration. What is the .git Folder? The .git directory makes a folder a Git repository. Without it, Git commands won't work in that directory. To see it: ls -a Look for a directory named .git . Key Subdirectories and Files inside .git config: Repository-specific configuration settings. HEAD: Points to the current branch reference. objects/: Stores all commits, trees, and blobs (Git’s data model). refs/: Contains references like branches and tags. logs/: Keeps a log of all reference updates....