During working on a Python project some .pyc files in __pycache__ directories appeared. Those files are just compiled version of code already in repo. It’s junk and it’s a good practice to get rid of it.

To remove it run command:

find . -name "*.pyc" -exec git rm {} \;

And add .gitignore file from here. Next time you commit changes git will automatically remove these files as well as another types of files listed in .gitignore file.

You can easily test your REST API using Flask client. To access Flask test client use method test_client() on your app module:

from app import appclient = app.test_client()

Flask test client allows to work with it through context manager using operator with.

Send GET query

with app.test_client() as c:
rv = c.get('/users', json={})
print('status: ', rv.status_code)

We can get JSON from response:

json_data = rv.get_json()

Let’s send POST query with some parameters:

with app.test_client() as c:
rv = c.post('/auth/signin/local', json={
'email': '<some email>', 'password': '<some password>'
print('status: ' , rv.status_code)

Send PUT query:

token = <some…

If you use Windows Linux Subsystem (WLS) under Windows you can meet such a situation when file .bashrc is not sourced when loading WLS terminal.

Thus terminal in WLS is not colored and aliases, env variables are not available.

That could be caused by rewriting instructions in ~/.bash_profile file.

To fix it edit file ~/.bash_profile and add following lines:

if [[ -f ~/.bashrc ]] ; then
. ~/.bashrc

Solution is found here.

OpenMesh is a very powerful library for processing 3D meshes. It provides a wide range of operations for meshes (like creating vertices and faces, manipulation with texture mapping of vertices) and moreover includes handful functions for iterating over adjacent vertices and faces in mesh. OpenMesh has Python version which can be used for fast implementation.

Here I will show how to work with 3D meshes using Python bindings of OpenMesh library.

Install it using pip:

pip install openmesh

Let’s write a simple test app using openmesh module

import openmesh as om
import numpy as np

Create mesh object

mesh =…

There are two awesome Linux commands providing a great flexibility in manipulating with text files: awk and sed. These commands sadly are not so popular and widely highlighted as another Linux commands. Let’s see what we can do with these commands.


Print all line containing string

awk '/mtllib/' test.txt

Print line number for lines containing substring

awk '/mtllib/ {print NR, $1, $2}' test.txt

Print fifth line

awk 'NR==5 {print}' test.txt

Print number of lines in file

awk 'END {print NR}'

Interesting trick: compare output of two commands awk using command diff

awk '{print $3}' f1.txt | sort -u > out1…

There is a great library OpenMesh for working with 3D meshes which has Python version.

I had a problem with saving texture coordinates in obj file. I use Python version of OpenMesh for manipulating with texture coordinates in 3D mesh stored in obj file and save the result mesh using method write_mesh. When I open the resultant obj file there is no texture coordinates information, only list of vertices and faces.

Let’s say we have following code

mesh = om.TriMesh()

# create vertices
vh0 = mesh.add_vertex([0, 1, 0])
vh1 = mesh.add_vertex([1, 0, 0])

mesh.set_texcoord2D(vh1, [0.24, 0.4])

And we write…

When apply Hole closing filter in Meshlab duplicate vertices can occur.

I have told about this filter in this post. Here we will see what problems can occur due to the presence of duplicate vertices in obj file and how we can fix it using MeshLab.

Let’s test on simple example. Create obj file with following content

v 0 0 0 v 1 0 0 v 0 1 0 v 1 1 0 f 0 1 2 f 1 2 3…

Common problem with 3D meshes is incomplete surface with holes. That could be caused by imperfect reconstruction algorithm or low quality in depth sensor.

We can easily repair surfaces of mesh in Meshlab program. Meshlab includes special filter for filling holes in 3D meshes.

First open Meshlab. Then import mesh: File > Import Mesh.

Here is an example of mesh with holes

Now apply filter. Open Filters > Remeshing, Simplification … > Close Holes

We can easily profile functions in Python using line_profiler package. This package profiling functions simply using decorator around these functions.

First Install package:

pip install line_profiler

And add decorator @profile around function

def fact(n):
if n == 0: return 1
elif n == 1: return 1

Then use profiler. First create dump file for out test.py

kernprof --line-by-line test.py

This command will create file test.py.lprof

Now run profiler

python -m line_profiler test.py.lprof


Timer unit: 1e-06 sTotal time: 1e-05 s
File: test.py
Function: fact at line 1
Line # Hits Time Per Hit % Time Line Contents ==============================================================…

Sometimes when run PyTorch model with GPU on Kaggle we get error “RuntimeError: CUDA out of memory. Tried to allocate …”

Clear memory with command:


Check CUDA memory

!pip install GPUtil
from GPUtil import showUtilization as gpu_usage


| ID | GPU | MEM |
| 0 | 0% | 0% |

Privalov Vladimir

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store