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

Improving the throughput of a Producer ✈

Hello 👋, In this article I will give you some tips on how to improve the throughput of a message producer. I had to write a Golang based application which would consume messages from Apache Kafka and send them into a sink using HTTP JSON / HTTP Protocol Buffers. To see if my idea works, I started using a naïve approach in which I polled Kafka for messages and then send each message into the sink, one at a time....

August 28, 2021 · 4 min · Denis Nuțiu

AutoFixture in ASP.Net Core 🎥

Hello, 👋 This is my first video blog post in which I try to explain AutoFixture. Here’s the test case referenced in the video and the code repository for the Retroactiune project. I used the following packages in my project. <ItemGroup> <PackageReference Include="AutoFixture" Version="4.17.0" /> <PackageReference Include="AutoFixture.Xunit2" Version="4.17.0" /> </ItemGroup> Thanks for watching! 🙂

August 19, 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

Tail Recursion

Hello everyone! 👋 Today’s article will be about tail recursion, a technique that allows you to optimize certain recursive functions. Introduction In short, when you write a recursive function, each new call it does allocates a frame onto the stack. For example, let us take this following function: private static long RecursiveFib(long n) { if (n <= 1) { return n; } return RecursiveFib(n - 1) + RecursiveFib(n - 2); } If we set a breakpoint at return n and call the function with RecursiveFib(10), we will get the following stack frame....

July 3, 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

PMS5003 C# Library

Hello everyone, I just want to let you know that I’ve released a C# library for interfacing with the PMS5003 (Particulate Matter Sensor) via UART. The code is available on Github and the package is available on NuGet. If you have any feedback or need some feature into the library, please open an issue on Github. Thank you!

April 11, 2021 · 1 min · Denis Nuțiu

PMS5003 Particulate Matter Sensor Test Run

Hi In this article we’ll test out the PMS5003 sensor in order to see if it works. I’ve forgot to buy a connector board, so we will do a manual connection to the Raspberry Pi 3 B V2. This involves cutting the wires and adding some resistors. Please note that you need: 5 Jumper Wires 2 Resistors 10K Ohm Raspberry Pi Setup Before connecting the sensor to the Pi we need to configure the Pi for this usecase....

March 28, 2021 · 2 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