Simple FFI in Idris
FFI Foreign Functions Inerface allows you to call a code written in one language from a code written in another language. In this post I will show you how to do that in dependently typed programming language called Idris. We will be able to call C code from Idris and vice versa. Invoking C code from Idris First let's create simple program in C which will allow us to calculate factorial (file factorial.c) ```c include "factorial.h" int factorial(int number) { if(number == 0) return 1; ret...
Connect to your RDS instance from another VPC
Suppose you have created a PostgreSQL database without public accessibility (we are talking about AWS RDS right now) within some VPC (e.g. VPC B) and you have a regular EC2 instance in another VPC (e.g. VPC A). Now you want to connect a client (e.g. psql) from an instance to database. VPC peering is a tool that you need to use in such a case Check different scenarios here if you want to connect from different VPC or without it altogether. First of all you need to have a peering connection in pl...
Creating desktop screenshots with Python
In this article I'm going to show how to accomplish a simple task of creating a screenshot using various Python tools. Alongside we'll see other useful methods of working with pictures. Let's start with the simplest way possible. We'll be using pyscreenshot package pip install pyscreenshot ```python import pyscreenshot im = pyscreenshot.grab() save image file im.save('screenshot1.png') show image in a window im.show() ``` Three lines of code (importing/instantiating/saving). Is there anything ea...
Quick introduction to DataDog agent
DataDog is a very powerful monitoring platform. In this article I'm going to show couple of the most frequently used commands for a new developer who has a little experience working with it previously. So let's go over main things and create a simple configuration for monitoring disk space. Imagine that we have an Ubuntu instance up and running an agent. Visit installation page if don't have it already or provision your instance with Ansible using Galaxy playbook. Check the agent is up and runni...
Writing simple Telegram bot with Telethon
In this article I will quickly create a showcase of using Telethon Python library in order to make a simple Telegram bot. Our bot will be a member of a group/channel and once someone changes group's description bot will post that about information as a separate message. Preparation We need a couple of things in order to get started 1. Register a new bot with a help of BotFather 2. Create new API application to obtain APP_ID and APP_HASH variables. Follow the steps here 3. Install Telethon libr...
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...
People never notice anything.
The Catcher in the Rye

What's inside?