How to identify similar images using hashing and Python

Hi 👋, In this article I would like to talk about image hashing. Image hashing algorithms are specialized hashing functions that output the hash of an image based on the image’s properties. Duplicate images output the same hash value and visually identical images output a hash value that is slightly different. To simplify hash("white_cat") = "aaaa" hash("brown_cat") = "aaba" hash("car") = "xkjwe" Some use cases for image hashing are: Duplicate Image Detection Anti-Impersonation / Image Stealing Image filtering Reverse image search Let’s play around with image hashing techniques using Python and the ImageHash library....

September 21, 2022 Â· 4 min Â· Denis NuČ›iu

Multiple Python versions on Windows

Hi đź‘‹ In this short article I will show you two ways of changing Python versions on Windows. It is useful when you have installed multiple Python versions on your system and want to run a specific version from the terminal. For example, if we have the following versions installed: We can use either the Python Launcher py to run Python or the python command. Python Launcher To list installed Python versions with Python launcher we can use the py -0 command....

April 8, 2022 Â· 2 min Â· Denis NuČ›iu

A custom HomeKit accessory with Python

Hi 👋, In this short article I want to showcase how I implemented a custom HomeKit accessory with python. My Home Assistant’s SD card died 🪦 a few days ago and the support for GPIO based sensors will be removed in newer releases. This makes it unsuitable for my needs, while giving me the perfect opportunity to try other things. To continue monitoring temperature and humidity in my home I’ve built a custom HomeKit accessory with HAP Python....

March 11, 2022 Â· 3 min Â· Denis NuČ›iu

Pytest Fixtures and Yield

Hi 👋 In this short article I want to explain the use of the yield keyword in pytest fixtures. What is pytest? Pytest is a complex python framework used for writing tests. It has lots of advanced features and it supports plugins. Many projects prefer pytest in addition to Python’s unitttest library. What is a fixture? A test fixture is a piece of code that fixes some common functionality that is required for writing the unit tests....

December 14, 2021 Â· 3 min Â· Denis NuČ›iu

How to document a project with MkDocs đź“ą

Hello, Welcome my third video tutorial, this time, on how to get started with MkDocs. In this video I try to give you a basic overview of MkDocs and a configuration consisting of the material theme and search plugin. Config The MkDocs configuration used in the video. site_name: My Cool Project Documentation theme: name: material features: - search.suggest - search.highlight - content.tabs.link plugins: - search nav: - Introduction: "index.md" - Tutorial: - Tutorial Subsection: "pages/tutorial/tutorial_subsection....

October 16, 2021 Â· 2 min Â· Denis NuČ›iu

How to write parametrized tests in Python with pytest 🎥

Hi 👋 Welcome to another video tutorial on how to write parametrized tests in Python using pytest. If you want to follow along, here’s the code that I’ve tested in the video. from typing import List class Solution: def move_zeroes(self, nums: List[int]) -> None: last_zero = 0 index = 0 while index < len(nums): if nums[index] != 0: nums[last_zero], nums[index] = nums[index], nums[last_zero] last_zero += 1 index += 1 def main(): solution = Solution() arr = [1,0,1] solution....

September 30, 2021 Â· 1 min Â· Denis NuČ›iu

Testing Python projects with Tox

Hi đź‘‹ In this article I will show you how to test your Python projects with Tox. Introduction Tox is a tool for automating testing in Python, their vision is to standardize the testing process. It can be used to easily test your project using multiple Python interpreters and run various commands. Getting Started To get started all you need to add to your project is a tox.ini file. To simplify running the tests we will make use of the following Dockerfile, which contains Python interpreters for 3....

July 29, 2021 Â· 3 min Â· Denis NuČ›iu

FastAPI Uvicorn logging in Production

Hello 🙋‍♂️, Running a ⏩FastAPI ⏩ application in production is very easy and fast, but along the way some Uvicorn logs are lost. In this article I will discuss how to write a custom UvicornWorker and to centralize your logging configuration into a single file. To keep things as simple as possible I’ve put all my code in a single Python file. main.py import uvicorn as uvicorn from fastapi import FastAPI, APIRouter router = APIRouter(prefix="") def create_app(): fast_app = FastAPI() fast_app....

May 18, 2021 Â· 3 min Â· Denis NuČ›iu

Context Managers and Cross Cutting concerns in Python

Hello, In this short article I would like to talk about context managers. I personally consider that at the core they are just a form of decorators. If you don’t know what a decorator is check the Decorator Pattern Wikipedia article. Decorators can be used to implement cross-cutting concerns. We have componentA and we need logging and security, we could write the logic for logging and security handling in componentA but some people consider component a should be componentA not componentAthatAlsoKnowsAboutSecurityAndOtherStuff....

March 7, 2021 Â· 4 min Â· Denis NuČ›iu

Method Injection and Property Injection Design Patterns

Hello, In this article we’re going to explore the Method Injection and Property Injection design patterns. To demonstrate the patterns I’m going to add a new interface named Encoder to the printer.py file and a concrete implementation for two encoders: Rot13Encoder and NullEncoder. class Encoder(metaclass=abc.ABCMeta): def encode(self, message: Message) -> Message: raise NotImplementedError("encode must be implemented!") class Rot13Encoder(metaclass=abc.ABCMeta): def encode(self, message: Message) -> Message: return Message(codecs.encode(str(message), 'rot_13')) class NullEncoder(metaclass=abc.ABCMeta): def encode(self, message: Message) -> Message: return message The Encoder will be used by the printer in order to encode the messages before printing them....

December 28, 2020 Â· 2 min Â· Denis NuČ›iu