Juggling with (your) balls – Quick sort in Python

Juggling with (your) balls – Quick sort in Python

A milltion times already on the internet and sorting methods already integrated in the language – so why?Because written things stay better in the brain and I like to understand things from the ground. ArjanCodes (I love your content!) recently posted a video about recursive functions and used a similar code. I won’t have written…

Is it a bird? Is it a plane? Nah – just a Python class behaving like a dictionary.
|

Is it a bird? Is it a plane? Nah – just a Python class behaving like a dictionary.

For a container class with a dictionary with config values (among other members) I wanted easy reading access as if it was a dict itself. For that you only have to implement the __getitem__ method. You can extend the provided dict functionality for your class if needed like the following: All but the update method…

I am here. Definitively NOT sleeping or sunbathing – A configurable anti-AFK Python script with pyautogui

I am here. Definitively NOT sleeping or sunbathing – A configurable anti-AFK Python script with pyautogui

Yeah I know it’s kinda pointless. I was thinking the same thing when I doomscrolled youtube shorts watching a so called programmer “Herr Programmierer” showing a simple script moving the mouse in a fixed interval to coordinates in a fixed square. I was bored, I like Python and sure I could create a better pointless…

Finding Nemo or check a Python list if there is one or all elements matching a condition
|

Finding Nemo or check a Python list if there is one or all elements matching a condition

Yeah we all can loop, but can you any or all? Checking if condition matches for at least one element of an iterable (e.g. list, tuple, set) In Python you can write that nicer with the builtin method any(): But who doesn’t like a one-liner (that is understandable): Very similar is the case if you…

Deciphering the expected secret – Python this.s in a one liner

Deciphering the expected secret – Python this.s in a one liner

The little easter egg of “import this” in Python is well known – it shows Zen of Python. Nice guideline of how to keep your code clean. The Zen of Python, by Tim Peters Beautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Complex is better than complicated.Flat is better than nested.Sparse…

Where are they going? – int angle to direction mapping in Python

Where are they going? – int angle to direction mapping in Python

A little util to map direction angle from weather API to ‘NW’ (SHORT, default) or ‘north west’ (LONG). Supports english (default) and german. An example API call to the weather API I am using and mapping the current wind direction to readable format. All my weather related code at github https://github.com/worksonmymachine-de/weather.

It’s raining codes and docs. WMO weather interpretation code mapping and translation for english and german

It’s raining codes and docs. WMO weather interpretation code mapping and translation for english and german

Just wanted to let you know I wrote a little mapper / translation for WMO weather codes as the (free) API I use for current weather and forecast also provides it. An example API call to the weather API I am using and mapping the current weather code to readable format. The code is on…

Multitasking: “Fucking up multiple things at the same time!” – MicroPython uasyncio howto

Multitasking: “Fucking up multiple things at the same time!” – MicroPython uasyncio howto

Most code for simple IoT devices is a script with an endless loop with the code for the connected hardware like reading a sensor or polling something from the network followed by a delay. Keeping that pattern in mind helps to write new or convert your existing code for asynchronous execution. If you want to…

“These ARE the devices you are looking for” – a MAC based identifier in Python, Micropython and C++

“These ARE the devices you are looking for” – a MAC based identifier in Python, Micropython and C++

TLDR: Code for MAC address in (Micro)Python and C++ for D1 Mini, Raspberry devices and NodeMCU. I was looking for a unique static identifier to handle my IoT devices without baking the mqtt publish topics, name and location into the code. The code on identical devices should be the same, the the individual configuration should…

Software tests

Software tests

Write them. Do not try to save time writing them poorly or even not at all. You and your coworkers and even often your future self will appreciate the work you put in. Many many times I found probable issues, uncovered cases and bugs lurking in my code I wrote by testing the code step…

A snake with no name – Lambdas in Python (also functions and list comprehensions)

A snake with no name – Lambdas in Python (also functions and list comprehensions)

Sweet and short: Instead of a function you can write a single statement in Python as a lambda. Either is one either better or worse nor does one replace the other. They both have their place and intended use. Functions hopefully have describing names, are probably used multiple times and handle a specific part which…