Einträge über Computer

I had my first computer with 5 and started C programming when I was 13. Then I made some simple websites using PHP which grew into ever more complex ones. In 2007, I created some Java applications, some of them are still among the portfolio on this page. While I was an intern at the DLR, I started to learn Python and IDL, which introduced me to matrix based languages. For the numerical methods lecture and especially my bachelor’s thesis I used C++. During my master’s thesis I have learned Haskell for fun. Later on for my PhD thesis I also learned R and the Wolfram Language.

See my portfolio of programming projects.

My most popular hobby project is the Vigilant Crypto Snatch, a little program that buys crypto currency whenever the prices fall.

This section of my site is for articles about programming practices and performance tests. Also various stuff about computer hardware and software.

Qt GUI for Vigilant Crypto Snatch

The Vigilant Crypto Snatch software started as a two-user project, where Chris and I just had it running on our respective machines. Over time a few other users came along, and now we have a Telegram group with around 50 members and likely even more users of the software. Initially the software was just a command line utility and ran only on Linux. Then I've used Streamlit to create a little web user interface to simulate triggers. People have asked for Windows support, which was not hard to do with Python. The user basis grew even more, and eventually somebody asked for a GUI. Command line programs are very uncommon on Windows, and the reach of the software seems to be large enough to be of interest to non-tech-savy users.

Given my general preference for Qt as a GUI library, my experiences with Qt 4 at the DLR in 2015 and my recent experiences with PyQt 6 for the autobright project, I was motivated to try this. The installation of Vorta (which uses PyQt) on Windows was easy via PIP, so I have the hope that it will turn out easy with this program as well. With PyInstaller one might even be able to package it nicely.


Qt GUI for Autobright

I have been working with the combination of the ambient light sensor and the display control software for a while, see the tag ColorHug. After the rewrite I had the software in a modular fashion and had a reasonable wrapper for the sensor, as well as for the display control. The problem still is the model that translated in between. And to improve the model, I needed to gather data. So I have been collecting data tuples of date and time, manually set brightness and sensor reading throughout my work and leisure time at the computer.

In order to take these measurements, I wrote a little GUI. And in the first iteration I just used Streamlit, because I had some experience with that. And the GUI looks reasonable. The one big issue with Streamlit is the model of state, though. It works reasonable for certain things, but it doesn't really work well for things that need persistent state. And the sensor needs initialization just once, but Streamlit would re-create all the objects. And that made it a bit cumbersome to use.

In order to get around that, I started with Qt and PyQt in particular. With that I can use both the amazing Qt library to build my GUI, but I can also use Python as a programming language. And with that I managed to build the first Qt version of the measurement program.


Creating a Tree Search Library

I have recently simulated a few games using Python code, see the articles with the Game Simulation Toolbox tag. All the code is in one repository, but I haven't really written good code. It was mostly just experimenting, and I did not work as cleanly as I otherwise do. My latest addition, the backtracking with Railroad Ink ended up as completely hacky code: Control flow on the module level, no clear separation, huge functions, little use of classes. It is a total mess.

Eventually I had everything in place to write that article and generate the video. But it turned out that the backtracking algorithm just isn't the best choice for this problem. I then wanted to try a random walk to generate funny videos. And also I wanted to try Monte Carlo Tree Search (MCTS). In my sandbox I have already implemented the MCTS for Nidavellir and also wanted to use that for Tic-Tac-Toe at some point. The random walk is trivial to implement. I had implemented beam search for Scythe. But I could not just mix-and-match the algorithms with the different games.

Prototyping without having to spend time to work professionally can be fun. For a while. And now it is getting on my nerves, and I will refactor it. The basic idea is that tree search algorithms and the games are independent of each other. This notion should be reflected in the design of the software as well. Therefore I propose to refactor it like this:


Notifications from Python to Android

For the Vigilant Crypto Snatch we currently use Telegram to send notifications from the Python program to the phones (mostly Android, I guess). Each user has independently set up a bot with Telegram. This bot token is registered in the configuration file and the Python script can then use the bot to send messages. The users have to write to their bot using Telegram such that the bot knows about their personal account. Then the bot can send messages to that particular end user.

This works fine. It's just that I don't particularly like Telegram as a service. The messages are not end-to-end encrypted by default, everything resides on their servers and is stored there potentially indefinitely. Then it has attracted quite a strange flock of people, although that in itself doesn't need to mean much. When a platform is really good, various bad people will also use that. But what makes me wary is that the people who speak for Telegram seem to consistently overlook the blatant flaws in their security model. They just use big words like “freedom” or “independent”, but I find that irritating. The server code is closed source (fine), but messages exchanged via that server are unencrypted.

So I have already diverted most of my contacts to Threema, Signal or WhatsApp. One use case are these notifications. I would like to find out whether there are alternatives, and whether they are viable.


Trying out GitHub Boards

Recently I became a fan of Kanban boards, see the article about board software. GitLab has boards for a while, and GitHub has them too now. I wanted to try them out, but it turned out to be quite hard to understand at first. After understanding Jira, I have a different mental model for such boards. Basically there are two major ways of having a board:

  1. The board can be the fundamental thing. This is how Trello and Todoist work. You define columns, then you add your issues as cards on that board. The cards don't have intrinsic state, rather their status gets defined by their position on the board.
  2. The board is just a view. Fundamentally the cards correspond to tickets which have certain meta information attached to them. You can create multiple board views from the same underlying pool of tickets. This is how Jira and GitLab issues work. Jira issues have a status, and you map statuses to columns. And in GitLab you specify filters for each column (usually with tags) and then tag the issues such that they appear in the columns.

GitHub seems to be neither of that. And I find it really confusing. This is what I could understand about it.


Adding CCXT to Vigilant Crypto Snatch

The Vigilant Crypto Snatch software had been refactored into the Clean Architecture a while ago. This process started when we wanted to also support the Kraken marketplace next to the Bitstamp marketplace. Then I switched over from the clikraken package to krakenex to improve the support with Kraken.

Recently somebody mentioned the CCXT package which provides a unified interface to over a hundred of exchanges. Adding this to our software would significantly increase the applicability. So I have looked into it. The license of CCXT is MIT, so it fits perfectly to my code.

Because it promises a unified interface to all markets, it basically does the same as my internal marketplace module. One might consider getting rid of that, and using CCXT directy. But that won't be a good idea. What if they change their API? What if I don't like it? What if they change their license model? And most importantly: Why should I change my other code only because I add a new marketplace library?


Heart Rate Monitor with Python

Recently I've talked to somebody who has an interest in psychology, sports and data science. His idea was to measure the level of relaxation using brain waves and then light the room in a specific color to give the meditating person a direct feedback on their progress. They could then train to reach certain meditative states using the external feedback.

I don't know how hard it would be to measure brain waves, and also have no idea how to interpret them. But I recently got a Garmin HRM-Dual, a heart rate monitor (HRM) chest strap. It works with the Strava app on my smartphone via Bluetooth, so there must be some way to get the data.

We had discussed this a bit further, and I wanted to give it a try. The light in the room would ideally be realized using a computer controllable RGB light, but I don't have one of them. I could just use a solid color with the computer or a TV screen.


Refactoring with Dependency Inversion and Injection

In this post I want to show how to refactor with the Dependency Inversion Principle. I find it hard to create a mock example with sufficient complexity, so I will just take the cryptocurrency buy software that I have featured in this blog a few times. In each iteration I will show the full code, talk about the problems.

We start with a really simple case. We just have a command line argument which controls how much money we want to invest. It will look like this:

import argparse

def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("--volume", type=float, default=25.0)
    options = parser.parse_args()

    print(f"Buying for {options.volume} on market X.")

if __name__ == "__main__":

The problem here is that we only have one market, and we only have one strategy to buy. Although I have mocked that with a print call, we only have one particular library which makes the HTTP requests. But we don't really see these parts in the code, it is just in the prose.


Kanban Board Software

I have used todo lists for quite a while, and I find it relaxing to be able to write tasks down. This way I don't have to keep all the tasks in my mind and try not to forget anything. The software that I have used was list-based. For short lists or short-term projects this was nice. One could just add a few tasks, and complete them later. One could just pick the next task from the list, and eventually it was all done.

But over time, there were always these tasks which accumulated on the bottom of the list; these things that I felt that I should or could do at some point, but never really thought important enough to actually take the time to do. Yet I have this desire to finish all tasks on a todo list. This of course cannot be realized with this sort of list. And actually it is not desirable either. Once the list is empty, there are no ideas left. I have noticed that at work, where a non-empty todo list stressed me out. And then an empty todo list also stressed me out, because I nothing to work on.

Over time I got a better relationship with my todo list when I discovered the agile approach. It is a big philosophy, but the important part here is that one doesn't plan for too long into the future, but rather picks the relevant tasks every week. The Kanban board is the manifestation of agile that I like at the moment. The tasks are cards in a column on a board, and they are moved between the columns. The first column is called the “backlog”, it is a repository of things that one could do. From these one picks the tasks which one want to work on, and put them into the next column. Once they are done, they are put into the next column, which is usually something like “review”. And then they go into the archive, which is the last column.


Better Exceptions for Vigilant Crypto Snatch

When running the Vigilant Crypto Snatch software, I often get these error messages sent via Telegram:

  • 🔴 An exception of type <class 'vigilant_crypto_snatch.marketplace.interface.BuyError'> has occurred: ['EOrder:Insufficient funds']
  • 🟠 An exception of type <class 'vigilant_crypto_snatch.myrequests.HttpRequestError'> has occurred: Connection error in Kraken Ticker
  • 🟡 Could not retrieve a historical price, so cannot determine if strategy “Drop(delay_minutes=10080, drop=15)” was triggered. The original error is: No source could deliver.

These exceptions get caught up in the main loop, and are just reported and then ignored. They have different reporting priorities, but still they are reported in the same fashion. For the user it is rather important to know that there are insufficient funds on the marketplace, but having plain HTTP errors reported is boring. Except when they indicate something that the user could change. So some changes are due in this regard.