Backup (clone) all your own gists

You need to have a personal access token to GitHub. In this script I use my token saved in ~/.github_access_token. Also you need to have the git utility on your system. Install PyGithub package to work with GitHub API pip install PyGithub The gist is actually a git repository. All your gists you can clone as regular repositories into a directory called repos. Script clones gists with names contained the IDs. Also script creates index.json which contains an array of objects describing what you got. ...

<span title='2022-03-13 00:00:00 +0000 UTC'>March 13, 2022</span>

Docker для python. Первые шаги

Если не вдаваться в технические детали Docker ближе всего к VirtualBox, VMware или другим средствам виртуализации. Технические отличия заключаются в других способах изоляции запускаемой гостевой (guest) операционной системы и разделения ресурсов основной (host) операционной системы. Как правило каждый работающий в Docker экземпляр гостевой операционной системы предназначен для запуска одного единственного приложения. При этом задействуется меньше ресурсов, чем при запуске в виртуальной машине. Для этого создается своя файловая система, свои виртуальные сетевые интерфейсы - как бы контейнер внутри которого приложение работает. Docker это программное обеспечение для контейнеризации приложений. ...

<span title='2022-01-04 00:00:00 +0000 UTC'>January 4, 2022</span>

Snippet for printing a subclass tree

Sometimes I needed to figure out the class hierarchy. For this, I wrote a small piece of code to visualize the class tree. def format_output(class_name, prefix, is_last): left_simbol = "└" if is_last else "├" return prefix + left_simbol + "───" + class_name def print_subclass_tree(thisclass, prefix=""): for count, subclass in enumerate(thisclass.__subclasses__(), start=1): is_last = count == len(thisclass.__subclasses__()) print(format_output(subclass.__name__, prefix, is_last)) devide_simbol = "" if is_last else "│" print_subclass_tree(subclass, prefix + devide_simbol + "\t") print_subclass_tree(BaseException) # ============ OUTPUT ================== # >>> print_subclass_tree(BaseException) # ├───Exception # │ ├───TypeError # │ ├───StopAsyncIteration # │ ├───StopIteration # │ ├───ImportError # │ │ ├───ModuleNotFoundError # │ │ └───ZipImportError # ... # ├───SystemExit # └───KeyboardInterrupt # >>> from django.views.generic.base import View # >>> print_subclass_tree(View) # ├───TemplateView # ├───RedirectView # ├───BaseDetailView # │ ├───DetailView # │ ├───BaseDateDetailView # │ │ └───DateDetailView # │ └───BaseDeleteView # │ └───DeleteView # ... # └───JavaScriptCatalog # └───JSONCatalog Link: gist.github.com

<span title='2021-12-09 00:00:00 +0000 UTC'>December 9, 2021</span>

Starting a production Django server

I wrote ansible playbook for starting up a production Django server with PostgreSQL, Gunicorn and Nginx. When I tested the script, I used the Ubuntu Server image from this link. All I needed to install additionally was an ssh server for ansible to work. sudo apt update && sudo apt upgrade sudo apt install openssh-server I used a VirtualBox image and set the network settings to bridge mode. The IP address was obtained via the dhcp protocol. The command to display the ip address is ip addr. ...

<span title='2021-10-15 00:00:00 +0000 UTC'>October 15, 2021</span>

Starting a remote docker development server on DigitalOcean droplet

Thanks Fedor Borshev for awesome tutorial “Как писать код на МОЩНОЙ удалённой машине DigitalOcean”. I repeated Fedor’s experience with Windows + WSL2. Video: Link to ansible playbook for for deploying docker on DO droplet and empty django project for testing: github. Links: [1] Ansible playbook for for deploying docker on DO droplet [2] Youtube-канал “Почему не работает?”

<span title='2021-08-15 00:00:00 +0000 UTC'>August 15, 2021</span>

A dynamic GitHub profile with GitHub Actions

Thanks Yannick Chenot for the article How to Build a Dynamic GitHub Profile with GitHub Actions and PHP! It describes how to set up automatic updating of links to the latest blog posts in the GitHub profile using GitHub Actions. I will not retell the article, and you can read about the profile on GitHub here. Here is my python solution import requests from bs4 import BeautifulSoup url = "https://vostbur.github.io" main_page = BeautifulSoup(requests.get(url).content, "html.parser") content = f"### Last posts from [blog]({url}):\n\n" for article_div in main_page.find_all("div", {"class": "mb-4"}): article_url = article_div.find("a", href=True) content += f" - [{article_url.text}]({article_url['href']})\n" with open("README.md", "w", encoding="utf-8") as f: f.write(content) Yaml file for GitHub Actions ...

<span title='2021-07-22 00:00:00 +0000 UTC'>July 22, 2021</span>

Deploying the django app on the DigitalOcean App Platform

For deploying Django apps, I tried PaaS such as Heroku and Pythonanywhere. It’s the turn of the DigitalOcean App Platform. And so far, this is the easiest and fastest way to deploy a Django app in production. There is awesome guide on how to do this on DigitalOcean’s tutorials. For testing, I wrote a small application that generates a configuration snippet for configuring ssh on cisco devices. For simplicity, I didn’t use a database and static content. For such an application, in fact, there is no need for a server side, just JavaScript is enough :) ...

<span title='2021-07-21 00:00:00 +0000 UTC'>July 21, 2021</span>

The best APIs for solving geospatial tasks

In mapquest.com I have found out the best APIs for working with maps and geopositions in my opinion. For example, I wrote a small script to navigate between cities. That is the result for the route from Bryansk to Moscow. The API has many request parameters. JSON response contains a lot of data: Links: [1] developer.mapquest.com [2] Example of using the API

<span title='2021-07-18 00:00:00 +0000 UTC'>July 18, 2021</span>

Setup a basic workflow using GitHub Actions with Docker

In the continuation of the post “Creating dockerized Django app with VSCode”, I updated the source code to work with GitHub Actions. Setup a basic workflow using GitHub Actions Add to the requirements.txt file the following line to check with linter: flake8>=3.9.2,<3.10 Create a new file at .github/workflows/cd.yml and fill it with the following contents: --- name: Code checks on: push: branches: [ master ] pull_request: branches: [ master ] jobs: test: name: Test runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Test run: docker-compose run --rm . sh -c "python manage.py test" lint: name: Lint runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Lint run: docker-compose run --rm . sh -c "flake8" To add a cool badge I updated README.md with the following link: ...

<span title='2021-06-13 00:00:00 +0000 UTC'>June 13, 2021</span>

Creating dockerized Django app with VSCode

Thanks to Mark Winterbottom for the interesting videos and the idea for this post. Creating a Django project Start by creating a new directory for your project (eg: vscode-django-docker), and open it in VSCode. mkdir vscode-django-docker cd vscode-django-docker git init code . Then, add a .gitignore for your project. You can use template for Python provided by GitHub or generate on gitignore.io. Now let’s create a Django project by running the one-line-command below ...

<span title='2021-06-12 00:00:00 +0000 UTC'>June 12, 2021</span>