Anatomy of a Gradle file

Motivation Understanding Gradle is mandatory if you want to build good Android apps Bare Minimum This is the bare minimum you need to be able to compile and run an Android application: plugins { id ‘com.android.application’ id ‘kotlin-android’ } android { compileSdk 30 defaultConfig { applicationId “de.creatronix.myapplication” minSdk 21 } } dependencies { implementation ‘androidx.core:core-ktx:1.6.0’…

How to write your __init__.py

What should you put into your __init__.py? Perhaps you already know that a python package is a directory which contains a __init__.py file In this article we will solve the mystery around the __init__.py For this article let’s assume the following project structure: Empty init file Sometimes doing nothing isn’t so bad at all. You…

How to implement Python Decorators

Motivation Python decorators are a nice way to implement the decorator pattern. Perhaps you read the article about Python data classes and wondered how the @dataclass thingy worked. Example Let’s say we created the following function: def un_decorated_function(): print(‘–> Starting un_decorated_function’) print(‘Inside un_decorated_function’) print(‘<– un_decorated_function finished’) This works but violates the DRY principle if repeated…

How to structure your Python project

This is not a “my way or the highway” kind of advice. Just a bunch of good practices. A starting point if you are new to Python. You will likely inspect and adapt your own project structure over time. The bare minimum This is a setup I recommend when just want to start with a…

Why you should use PyHamcrest in testing

Motivation I’ve written about Software Testing Concepts in general and also about pytest in particular. Now I want to introduce you to a nice little add-on which makes your testing -hopefully- easier. Hamcrest Hamcrest is around for a couple of years. I’ve used it together with JUnit back in the days. It had a bit…

Anatomy of a Jenkinsfile – Tutorial

Why should you use a Jenkinsfile? The biggest advantage of a Jenkinsfile is the ability to use version control to manage your build system. When you use freestyle jobs you can loose you configuration due to limit history depth. Descriptive vs Scripted Jenkinsfiles come in two flavours: Declarative pipelines always begin with the word pipeline…

How to use Python shutil

Sometimes you want to delete a folder in Python. You know that os.rmdir() can do that for you. But then you realize it can only remove empty folders. If you want to remove the content before deleting the folder you come up with: def remove_non_empty_dir(path_to_dir): if os.path.exists(path_to_dir): files_in_dir = os.listdir(path_to_dir) for file in files_in_dir: os.remove(os.path.join(path_to_dir,…

Logging in Python – Cheat Sheet

I’ve written a piece about logging Log4j2 for Kotlin and the motivation to use logging in Python is the same: Logging is a common good practice in software engineering. It enables you to monitor applications in production to gather information about crashes and other malfunctions for further analysis. It is the “little brother” of debugging…

Books about Space

Motivation Over the years I gathered some nice books about space exploration, rocketry and space in general. The List To Space and Back Endurance: My Year in Space, A Lifetime of Discovery Von Braun: Dreamer of Space, Engineer of War Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future Flying to the Moon:…