Looking at S-Core today feels a bit like walking into a German factory that has just announced a “major transformation initiative.” Before anything actually starts to change, there are: The intention is good, but as my colleague from work pointed out some time ago: “bureaucracy expands to meet the needs…
How to write Arduino Uno code with Python?
Recently I came across a Reddit thread where someone asked: “I was thinking about using an Arduino, but I have been learning Python and do not want to learn a whole other programming language to do basic things that an Arduino can. (Planning on making a robot, will be using…
Combining Bazel with Docker
Welcome to the next pikoTutorial! In one of the recent articles, I showed how to build and run Docker containers using CMake. Today, we will see how to do a similar thing, but using Bazel. Today’s project structure: Note: on the contrary to the project structure used in the article…
Running commands with timeout on Linux
Welcome to the next pikoTutorial! Bash comes with a bunch of useful, built-in commands. One of them is timeout which allows you to run another command with a time limit. The syntax is simple: To avoid providing large numbers for long timeouts, duration parameter accepts suffixes which mark the exact…
Running Python unit tests with CMake
Welcome to the next pikoTutorial ! If you haven’t read the previous pikoTutorial on setting up a Python project with CMake, you may want to check it out first because in today’s article I’ll be using the setup we’ve done there: However, I will extend it with the test directories…
Thirdparty dependencies with FetchContent
Welcome to the next pikoTutorial ! FetchContent module tries to be the solution to never-ending discussion about the package management in C++ (I wrote a bit about it in one of the articles of Make C++ a better place series). It’s not a package manager by itself, but it integrates…
Bug of the week #11
Welcome to the next pikoTutorial ! The error we’re handling today is a C++ compilation error: What does it mean? It often occurs when the compiler encounters a place in the code where it would normally expect a static member function, but the actual function is not static. Let’s say…
Combining CMake with Docker
Welcome to the next pikoTutorial ! In one of the recent articles, I showed how to use CMake for setting up a Python project. Today, we will see how to further extend it by adding building of Docker images to the CMakeLists.txt files. Today’s project structure: Top CMakeLists.txt file Nothing…
How to search the internet from Linux terminal?
Welcome to the next pikoTutorial ! Linux terminal is a basic tool for many software engineers and the place where we often spend a lot of our time during the work day. Even if you’re not doing anything in the terminal right now, it is for sure opened for the…
Folding expressions in C++
Welcome to the next pikoTutorial ! What is a folding expression? Imagine that you have a vector of integers and you need to add some predefined values to it. The obvious choice seems to be just using push_back() function applied a couple of times: This works, but look how much…
How to derive from an enum in Python?
Welcome to the next pikoTutorial ! Recently I’m experimenting with different ways of error handling in Python and I stumbled upon a use case in which it would be very helpful to create an enum by deriving from a different enum. Use case Let’s say we design an interface for…
Bug of the week #10
Welcome to the next pikoTutorial ! The error we’re handling today is a C++ compilation error: Or a similar one: What does it mean? This error occurs in situations when you provide a declaration of a type, but don’t provide definition of that type. For example, if I try to…
Trying ROS2: client/server within a single container
Welcome to the next pikoTutorial ! In the first article of Trying ROS2 series I showed how to implement and examine a basic publisher and subscriber within a single Docker container. Now it’s time for checking out how do you implement and set up a client/server connection within a single…
Make C++ a better place #4: Go as an alternative
The Go programming language brings simplicity and a clear design philosophy that make it attractive for developers who are tired of the complexity of C++. In this article, we will explore the most interesting features of the Go language that distinguish it from C++. Producer/consumer implementation with Go If you…
How to convert hex to dec in Linux terminal?
Welcome to the next pikoTutorial ! Conversion from hexadecimal to decimal Add the following function to your .bashrc file: Usage: Conversion from decimal to hexadecimal Add the following function to your .bashrc file: Usage:
Setting up a Python project with CMake
Welcome to the next pikoTutorial ! CMake is often associated only with C/C++ and occupies a high place in the ranking of the most hated tools. Today, I want to show an unusual, but interesting use case – setting up and running Python applications with CMake and its underlying generators.…
Separating builds for different configs with Bazel
Welcome to the next pikoTutorial ! Let’s consider a simple project with the following structure: The main function has 2 compile switches: And we have 2 separate Bazel configurations including these switches: When we build the application with the following command: I can run the application by invoking: But as…
UDP multicasting with Python
Welcome to the next pikoTutorial! The minimal receiver Note for beginners: do not remove line 14 from the receiver implementation! Without the ability to re-use the same address, you will not be able to run more than 1 multicast receiver and you’ll end up with a simple UDP client/server setup.…
Destruction order vs thread safety in C++
Welcome to the next pikoTutorial ! What’s the problem? Let’s take a look at the simple example below: Let’s quickly sum up what’s going on here and what could be the expected output of such program: To understand why it happens, let’s add a custom deleter to the unique pointer,…
Let’s review some code: C++ #2
Below you can find the code that we will be reviewing today. Before you scroll down to section where I fix it, feel free to check how many mistakes you can find. Without running this code, one could expect that the output which it generates looks like this: But when…
Make C++ a better place #3: D as an alternative
The D programming language, commonly known as DLang, offered a fresh perspective on system-level programming by blending familiar features of C++ with modern mechanisms to enhance code safety, simplicity, and performance. Created by Walter Bright, it is meant to be a viable alternative to C++ for developers seeking to improve…
Registering callback using std::function in C++
Welcome to the next pikoTutorial! Imagine you’re building an application that processes some data and once it’s done, the user needs to be notified about the result. Since you don’t want to hard-code the notification logic, it’s better to allow the user to register a custom function that will be…
Bug of the week #8
Welcome to the next pikoTutorial! The error we’re handling today is a C++ compilation error: What does it mean? In C++, the error occurs when you try to invoke a function that has been explicitly marked as deleted or implicitly deleted by the compiler. This error commonly arises in relation…
TCP client/server with Python
Welcome to the next pikoTutorial ! The minimal TCP server A TCP server listens for incoming connections on a specified port and communicates with clients over that connection. The minimal TCP client A TCP client establishes a connection with a server, sends data, and receives responses. Bidirectional communication You can…
Simple menus in Bash scripts with select
Welcome to the next pikoTutorial! The select keyword in shell scripting provides an easy way to present a list of options to the user and handle their selection. It is particularly useful when you have a predefined set of choices and want the user to pick one. When you run…
Calling member function on a nullptr in C++
Welcome to the next pikoTutorial! nullptr and the segmentation fault One of the first things that beginner C++ programmers realize after starting to play around with pointers is that dereferencing a nullptr leads to an immediate program crash caused by the segmentation fault. This leads to a common belief that…
Bug of the week #7
Welcome to the next pikoTutorial! The error we’re handling today is a C++ compilation error: What does it mean? The requirement for main to return an integer stems from convention and standardization within the programming languages. In C and C++, the main function is typically defined with a return type…
Python lru_cache explained
Welcome to the next pikoTutorial! Imagine you’re developing an application that fetches data from external API. For example, a weather app might request current weather conditions for a list of cities and then display them. While the data is updated periodically, repeatedly querying the API with the same city is…
How to dockerize a Python application?
Welcome to the next pikoTutorial! If you ever wanted to ensure a consistent environment for your application, you most probably know that containerization is the way to go. To containerize a Python application, let’s first set up a simple file structure: Now add a simple Python application: Note for beginners:…
Make C++ a better place #2: CppFront as an alternative
In this article, we will explore how CppFront aims to make C++ a better place by introducing a new syntax, improving safety and usability and providing modern features that align with good programming practices – all while maintaining full interoperability with C++. The origins and philosophy of CppFront CppFront is…
Parameters combinations in GoogleTest
Welcome to the next pikoTutorial! Parameterized unit tests are priceless. They help to test code thoroughly through multiple possible input values, without having to write multiple and almost the same unit tests – if you have a function accepting an enum and output for some of them is the same,…
Data transfer with curl
Welcome to the next pikoTutorial! Short for “Client URL,” curl is a command-line tool and library for transferring data with URLs. It supports various protocols, including HTTP, HTTPS, FTP, FTPS, SCP, SFTP, LDAP, and more. Basic usage At its core, curl allows you to fetch content from or send content…
Python reduce explained
Welcome to the next pikoTutorial! The reduce function is a powerful tool placed in the functools module that facilitates the cumulative application of a function to the items of an iterable (from left to right), to reduce them to a single value. Initially introduced in Python 2, later moved to…
Bug of the week #6
Welcome to the next pikoTutorial! The error we’re handling today is a Python runtime error: What does it mean? The “too many values to unpack” error typically occurs when there is a mismatch between the number of variables or elements being unpacked and the number of values being assigned. This…
Custom literals in C++
Welcome to the next pikoTutorial! What are C++ literals? Literals in C++ are constant values directly embedded into the code, such as numbers, characters and strings. They represent fundamental data, making the code more readable and expressive. C++ provides several built-in literals, like integer literals (42), floating-point literals (3.14), and…
Linux and hash command
Welcome to the next pikoTutorial! What is hash? The hash command in Linux is a built-in shell utility used to optimize the execution of commands by recording paths of the invoked commands, so subsequent executions don’t need to search through the PATH variable again. You can see it in action…
5 Python good practices which make life easier
Welcome to the next pikoTutorial! Print exceptions traceback after catching them Consider the following example code that raises an exception: When we run it, we see the following output: The traceback provides detailed information, including where the error occurred, the exception type, and the error message. However, the downside is…
Let’s review some code: Python #1
Below you can find the code that we will be reviewing today. Before you scroll down to section where I fix it, feel free to check how many mistakes you can find. This function is meant to take a list of strings, count the occurrences of each individual string and…
Make C++ a better place #1: What does better mean
Let’s define word “better” In the title of this series, I used the term “better”, but as an engineer, I can’t begin my research with such a vague objective. The world of software engineering is so complex and varied that word “better” can have very different meanings depending on the…
Enums vs enum class in C++
Welcome to the next pikoTutorial! When dealing with enumerations in C++, developers have two primary options: traditional enum and enum class. Traditional enums vs enum classes At the first glance, the only difference appears to be in the class keyword: The real difference is however in how both of them…
Bug of the week #5
A segmentation fault, often referred to as a ‘segfault,’ is a specific kind of error encountered in computing when a program tries to access a memory location that it is not allowed to access.
UDP client/server with Python
Unlike TCP (Transmission Control Protocol), UDP is connectionless, meaning it does not require a handshake process to establish a connection before data transmission.
Hard links in Linux
Unlike symbolic (soft) links, which point to a file by its pathname, hard links are direct pointers to the file’s inode.
Functions calling order in unit tests in C++
To ensure a certain order of function calls, GTest provides 2 ways to do that: InSequence and Sequence objects.
Bug of the week #4
Welcome to the next pikoTutorial! The error we’re handling today is a Git error: which occurs when trying to copy file from another branch using command: What does it mean? It means that the commit hash you provided was not recognized by Git as a valid object which could be…
Yield in Python – state machines, coroutines and more
yield is a well known keyword in Python which allows to optimize the code by generating data streams on the fly instead of generating the same data all at once.
Copy files from another branch with Git
Welcome to the next pikoTutorial! What’s the problem? Imagine that you are working on a feature branch called target_branch and someone else commits some folder to another feature branch called source_branch. You need this folder, but these are completely different branches, with different changes and diverged history, so you can’t…
Make C++ a better place #0: Introduction
The world of software development is built on dreams of engineers who aspired to create their own programming languages.
5 misconceptions about std::move in C++
Welcome to the next pikoTutorial! std::move moves an object One of the most prevalent misconceptions is that std::move actually moves an object. In reality, std::move does not perform any movement – it casts its argument to an rvalue reference. This enables the compiler to apply move semantics, but std::move itself…
How to use xargs on Linux?
Welcome to the next pikoTutorial! xargs reads items from standard input, delimited by blanks or newlines and executes the specified command with those items as arguments. Basic usage The most basic pattern of using xargs commands consists of 4 elements: Examples Create files basing on a text file Let’s assume…
How to test method call order with unittest in Python?
Welcome to the next pikoTutorial! Sometimes when writing unit test it is necessary to check not only if certain function has been called, but also the order in which functions have been called. To do that with unittest in Python, use the following code: If you change the order of…
Bug of the week #3
Welcome to the next pikoTutorial! The error we’re handling today is a C++ linker error: What does it mean? In C++, an “undefined reference” error occurs during the linking stage. This error indicates that the linker cannot find the definition for a function, variable or object that has been declared…
Build & run C++ unit tests with CMake
Welcome to the next pikoTutorial! Building and running a single test file To present the easiest case, we need to assume some folder structure of our project: Here the easiest case means that we have only on library and only one test file for it. Firstly of all, we need…
Arrange text with sort on Linux
At its most basic, the sort command sorts lines in a file alphabetically. For example, if you have a file named data.txt, you can print its sorted content with:
Key derivation function with Python
Below you can find the extended example of how to use PBKDF2HMAC key derivation function in Python.
Let’s review some code #1: C++
Below you can find the code that we will be reviewing today. Before you scroll down, feel free to check how many mistakes you can find.
5 ways of passing unique pointer to a function in C++
std::unique_ptr is one of the most common non-copyable types – types, whose constructor has been explicitly deleted in their implementation.
Bug of the week #2
ISO C++ forbids declaration with no type – check what does it mean and how to fix that error.
Symmetric data encryption with Python
One of the simplest ways to perform symmetric encryption in Python is to use Fernet algorithm from cryptography module. Let’s see how to use it.
How to read ip addr output on Linux?
ip command was designed to replace older networking tools like ifconfig, route or netstat. Learn about how to decode ip addr output.
5 least known STL utilities in C++
Learn about 5 least known yet very useful utilities from STL like std::shared_mutex or std::clamp.
Bug of the week #1
When you see the error message “Unable to index file” in Git, it typically indicates that Git has encountered an issue while trying to add a file to its index.
Hacking Python functions by changing their source code
Changing function by modifying its implementation manually is obvious, but can we change the implementation of the function at runtime of the application?
How to dockerize a C++ application?
If you ever wanted to ensure a consistent environment for your application, you most probably know that containerization is the way to go.
Why implement custom copy constructor in C++?
Nowadays there are many high level languages in which you don’t have to care about how objects are copied around. However, if you want to write in C++, you must understand that copying is a very distinct operation.
Welcome to pikoTutorial!
Your best source of byte-sized programming knowledge! Inspired by the SI unit prefix “piko” (10^-12), our portal aims to deliver short software tutorials.