Just my blog

Blog about everything, mostly about tech stuff I made. Here is the list of stuff I'm using at my blog. Feel free to ask me about implementations.

Soft I recommend
Py lib I recommend

I'm using these libraries so you can ask me about them.

Django middleware for the rescue!

Now I can save visitors locally without external tools and also track a bad acting requests.

Finally, I can have a better working middleware which can catch HTTP status errors, make a redirect-response to the main page and also save a visitor.

Now I can also catch HTTP status codes in the database to see what a bad actor wants to achieve.

Thanks to: LINK

I can now save site visits without external analytics and save a bad example to later expose them in a fancy table.

Only I need to mask IP addresses before I show requests and paths to the public.

TBH I also need to add some load balancing.

    def __call__(self, request: HttpRequest) -> typing.Optional[HttpResponse]:
        Check request for validity here and response with correct answers.
        Use bad codes when needed.
        Save visitor now with status code relation.
        :param request:
            response = self.get_response(request)
        except SuspiciousOperation as e:
            save_visit_task(request, status='SUS')
            return HttpResponseForbidden('CSRF verification failed.')
        except Exception as e:
            log.error(f"General …


Raspberry 5 test-to-speech using Piper

How to make your Raspberry 5 talking with python lib Piper?

I wanted to make my Raspberry tell me about power outages and air alerts near my location.

The setup is pretty simple and described ar the repo:

I didn't want to waste my time making yet another Python venv and that's why I've chosen a simple binary mode.


Now about the setup:

  • Raspberry 5.
  • USB sound card with 3.5 jack.
  • USB-powered speaker with a 3.5 jack.


CMD to change the volume programmatically:

amixer set Master 80% >> /dev/null

 Sound devices and controls

You may have a problem with playing generated WAV files and making voice directly. So you need to choose devices for a different output.

To list devices run:

# List devices
aplay -L
# I only have USB card:
     USB Audio, USB Audio
    Direct hardware device without any conversions
     USB Audio, USB Audio
    Hardware device with all software conversions
     USB Audio, …


WSGI mod, Python, Django, Celery and a nice fella virtualenv


Here I'll show how to use Python (3.8.0 in the current example, but legit for latest 3.+ versions, not for os.name == 'NT') and virtualenv to setup WGSI enabled website on Django (or any) with implemented Celery + Flower + RabbitMQ. This example is my own path used for automated test framework: Octopus (not available now, but have dev branch opened: Lobster)


Here only configurations and setup for Python 3.8.0, virtualenv, WSGI, Django, Celery (worker and beat services), Flower and that's it. Later I'll show Django + Celery configuration when they run together (sort of).


You may want to install Python at first: Read


When your modern and fancy python is installed, we'll make a virtual environment for our website. Never underestimate a power of virtualenv as I did, because since you start to use it, you will never understand how did you work without them …


Centos Python Installation Guide with no Pain

Old me installing Python

Centos 7 + Python 3(4,5,6,7,8) installation guide with no pain. As for me.


I can't even say how many times I have to update my python executables for web servers and how much pain I feel during this routine.


Usual Google\StackOverflow advice only describes one particular problem. But there're few of them, and they're different so you spent hours trying to collect them all and pick the right decision.


Then you just drop it and use yum for any latest python version available!


Here I'll show you and make a reminder for myself about how to install modern python in the best way, once, without pain.


I use Centos 7 typical install as for WebServer (minimal install could require to install tonnes of dev-libs and yum, be sure you prepared them before)


1. Preparations:


You need to install some compil libs.


yum …


Test design and implementation.

Old stuff, very old


Very beginning


Test design


Our test system has a pretty simple configuration, so I do not want to bother you with the detailed description of it. Simply - it's just a standalone execution of a test.py file with all requirements (test setup and tear down) in local internal test utility. Helper local utility has a usual amount of preparation functions, test data loading and some other configurations. In the very end of test loading, it just compares a node-set result of "real" scan (software and hardware nodes in a database after the scan) with predefined node-set (from test.py). Node set we usually expect at the end of the test should be added by the developer when product discovery pattern is ready or have a new feature or fix.


Now I'm trying to implement entirely new and somewhere different test design because current is not …


Test automation or: How I Learned to Stop Worrying and Love Async __init__

Old stuff

Morning everybody…


I recommend reading this part of the blog only in the morning with a cup of dark and strong coffee.


I'll show you some new cases, and howto's to help you automate routines in the developer's life. There will be an example of my fails and win on different scenarios. The poor code I'll include also.


Very beginning


Firstly - I'll try to make this thread in English. And maybe later when I have time - to make Ukrainian and Russian translations, I'll make them.


"Octopus" story has started from a small plugin for Sublime Text editor. Later it will be ported to Atom.


I've started developing "Octopus" on spring-summer 2016, and I've not finished it yet! New functions and features were implemented continuously. Product transforms into a framework.


Now all processes executed automatically and simultaneously for 24/7.  "Octopus" has …


Python - Django Celery - кейс длиною в вечность.

Вкратце: когда добавляешь пачку тасок на Celery worker'ы, случается так, что парочка из них отваливается или засыпает или еще чего. Долго не доходили руки поправить это недоразумение, поэтому я просто рестартовал все воркеры раз в пару дней или прямо перед началом проверки рутины, в общем очень сложно было поймать и воспроизвести тот случай, когда без каких-либо ошибок воркер просто молчал. И наконец дошоли руки запилить кривофикс, время покажет насколько он толковый, суть в следующем: В сразу после момента определения свободного воркера  - запускать app.control.heartbeat() и app.control.ping(timeout=10) и если ответ пришел (в виде [{'alpha@host': {'ok': 'pong'}}]) - значит воркер готов и можно передавать ему таску, пачку тасков, рутину и тп. Если ответ пришел отличным от этого - даем ошибку и ничего не запускаем далее. При плохом раскладе пользователю придется просто перезапустить задачу посредством нажатия кнопочки еще раз, а вот запланированная таска - умрет. Общий вид на код примерно такой: Набросавши …


Python 3 showing progressbar while subprocess.Popen

Have an interesting case I want to share and save for future. One small problem in this system: https://github.com/trianglesis/BMC_TPL_IDE is showing when some process is running and was not hanged up. Sometimes we need to run a huge amount of checks and tests and would be great to know if something hangs before killing it mannually. I used different scenarios and mostly a module pregressbar2, and this is what I finally can compose:

  1. Make worker which will execute job sorf of randomly:
    1. import time
      import random
      print("START SOMETHING")
      for i in range(5):
          sec = random.randint(1, 3)
          print("Sleeping for: %d" % sec)
          print("Making job, line: %d" % i)
      print("END SOMETHING")
  2. Make process executor:
    1. import sys
      import subprocess
      import progressbar
      # Draw spinner:
      bar = progressbar.ProgressBar(max_value=progressbar.UnknownLength)
      # Execute some job with multiple lines on stdout:
      p = subprocess.Popen("C:\Python34\python.exe worker.py", shell=True, stdout=subprocess.PIPE,
      # Lines will be collected in list:
      result = …



Для всех страждущих наконец выкладываю нормальные примеры использования VK Script: https://github.com/triaglesis/vk_execute Там все мои примеры и по работе и просто тестовые. Самый быстрый вот такого плана, без внутреннего парсинга. Как только добавляешь внутрь вк скрипта какой-то проверочный код - КПД резко падает. Мой совет - вк_скрипт только для сбора всего "сырого" - дальше обрабатывать уже на сереверной стороне.

var posts_cnt;
var posts;
var post_list = [];
var offset_posts = Args.global_offset_posts;
offset_posts = parseInt(offset_posts);
// var offset_posts = 0;
var run_count = 0;
var iter_count = 20;
while (iter_count > run_count )
    {posts = API.wall.get(
    offset_posts = offset_posts + 100;
    run_count = run_count + 1;
    posts_cnt = posts.count;
return {"posts_cnt": posts_cnt,
        "offset_posts": offset_posts,
        "posts": post_list};



Django, Apache2, Sublime Text 3 build system and developing process.

At first be sure that you are using this path to run pure apache: http://www.trianglesis.org.ua/django-python-3-4-wamp-apache-2-4-23-pycharm

This topic for those who wants to develop ON THE FLY with python and django and do not want to manually restart dev server each time when code changes AND you don't like built in python web-server and want to run your dev site as it should run on apache.


Sublime Text 3

I use it for fast code changing and writting because PyCharm can't work fine with multiline carrets, for example. Also PyCharm is too heavy when you want just copy&paste some features and see how it work on web. So my PyCharm will be used for debug purposes.

I hope you know what is the "Build system" in Sublime, if no - read this first: http://sublimetext.info/docs/en/reference/build_systems.html

  1. Should run Sublime text 3 "as Administrator"
    1. You can run it once with Shift + Left mouse …