Using Poetry in production
In this article I want to share my experience of using Poetry dependency manager in production environment. At the moment of writing it's still immature and have no major release yet (only alpha pre-release version is available). Nevertheless I was able to successfully adopt it for real production Python web application (Docker/Python/Django) as well as migrate engine of this blog to use it (so if you are reading this article all the things is going good so far). I'll provide some code snippets ...
Reinforcement learning with Python. Part 1
Hi there, this is the first part on reinforcement learning series. In this article I will try to explain some basic concepts using simple problem and in the next one we will implement a primitive algorithm to solve that in Python. Along the way we will create a complete solution for the real world problem using reinforcement learning techniques. Let's get started! Journey begins Suppose we want to travel from Los Angeles to Last Vegas. We have a car with a tank's volume of 60L. Along the road we...
Writing custom remote commands for Celery workers
There are a lot of celery commands allowing you to monitor task/worker statuses. It's really easy to extend that list with your custom command and we'll do that in order to get some extra monitoring for any task launched. I suppose that you already have Flower configured and running and it runs on each of your workers hosted on AWS. You can definitely update the code below according to your needs and make it work for your case as well. So what we are trying to accomplish: we want to be able go t...
Monitoring Celery queue with Datadog
Sometimes your Celery workers are having hard time processing all the tasks from a queue. It might be due to your tasks being long running or due to a high load on workers themselves. Obviously you need to consider autoscaling in order to handle this issue but in a first place you need to know is something going wrong. For this purpose we will setup monitoring with Datadog platform. The easiest way to know when your queue is getting bigger is by restricting your workers of fetching more than on...
Using pyenv on Ubuntu
Pyenv is a tool that allows you to easily install multiple different Python versions and flawlessly switch between them. Pyenv is not a replacement for virtual environment but it can also help you manage those. The easiest way to obtain pyenv along with a set of useful plugins is the following $ curl https://pyenv.run | bash You can list plugins installed via $ ls -1 ~/.pyenv/plugins/ The pyenv-virtualenv one is used to manage you virtual environments and also will be mentioned below. Update you...
MySQL installation on Ubuntu 18.04
Basic installation is an easy process and requires typing just a couple of commands $ sudo apt update $ sudo apt install mysql-server $ sudo mysql_secure_installation Answer the questions provided and your basic installation is finished. Now you need to make sure your can access your database with username/password pair. $ sudo mysql This will take you in MySQL prompt where you need to set a password for the root user with commands provided below mysql> SELECT user,authentication_string,plugin,...
Using XML RPC to control your GoPiGo
GoPiGo is a really nice robot that you can build by your own. It's inexpensive and a good starting point when learning robotics. First you need to assemble it by your own and install Raspbian for robots (a modified version of Raspbian OS for GoPiGo). With a help of step-by-step instructions it would be an easy deal. Once assembled you can use Python to program it. Usually you need to be remotely logged in and launch your script from remote terminal, so in this article we'll be exploring another...
Generating events to count probabilities with Python
In the previous article we have talked about confirming solution for simple probabilistic problems. What if we have slightly complex environment and we cannot calculate all the possible outcomes? We can still make a bunch of experiments and by the law of large numbers the average of the results will be close to expected value. As usually Python will help us generate vast amount of possible events and we will compare that result to our initial guess. Let's try to solve some examples using this ap...
Count your probabilities using Python
Everyone familiar with probabilities knows that they can be tricky. And when solving even really simple problems an answer might be unituitive (as in famous Linda problem). The simplest way to count your probability is by using straightforward formula P = (number of successful outcomes) / (number of all outcomes). There is one issue with this approach though: we need to know the size for the space of the events in order to calculate the result. That's why there is a number of other helpful form...
Beware when using dict.keys() and dict.values()
Starting with Python3.7 dict.keys() and dict.values() preserves an insertion order [1] [2] [3]. That's not true for older versions, so the code below ``` data = { 'one': 1, 'two': 2, 'three': 3, 'four': 4, } keys = ['one', 'two', 'three', 'four'] values = [1, 2, 3, 4] data_keys = list(data.keys()) data_values = list(data.values()) k_equals = data_keys == keys v_equals = data_values == values if not k_equals: print('wrong keys', data_keys) if not v_equals: print('wrong va...
People never notice anything.
The Catcher in the Rye

What's inside?