Skip to content

Instantly share code, notes, and snippets.

@egor83
egor83 / pytest_source.md
Created October 25, 2024 10:24
pytest source problems after running pytests via Docker

I am normally running tests locally against a DB in Docker; I ran tests via Docker once, and since then pytest stopped showing me traceback for the failed tests, only showing > ??? instead.

Running pytest as pytest --vv showed that it tried to find a source code in the wrong path, using path as if it runs inside Docker (even though I was running it locally).

What seems to have happened is the following:

  • running tests via Docker created Python cache (__pycache__/*.pyc) owned by root;
  • re-running tests locally picked up that cached bytecode (either couldn't or didn't try to delete/overwrite it), tried accessing source code with the path hardcoded in cache (that is, with paths as they are in Docker), and failed.

Once I deleted cached files, it started working again.

@egor83
egor83 / LibreOffice Calc Fill Up
Created December 12, 2023 17:18
LibreOffice Calc Fill Up
Ctrl+D fills down the current row from the row above; to make a mirrored function (fill up the current row from the row below),
do the following:
Go to Tools menu > Customize, Keyboard tab
Find "fill up" function (there's a filter field for that), select Ctrl + Shift + D in the list of "Shortcut keys" (I had to
scroll), and select "Modify".
Based on Reddit comment by /u/fullonwrong here:
https://www.reddit.com/r/libreoffice/comments/2dr9of/equivalent_keyboard_shortcut_commands/
@egor83
egor83 / gzip.py
Created December 2, 2022 05:15
Attempting streaming gzip compression.
import zlib
def yield_uncompressed_bytes():
# In a real case, would yield bytes pulled from the filesystem or the network
chunk = b'*' * 10
for _ in range(0, 5):
print('In: ', len(chunk))
yield chunk
@egor83
egor83 / zip.py
Created December 2, 2022 05:03
Trying to write to a compressed zip file
from io import RawIOBase
from zipfile import ZipFile, ZipInfo, ZIP_DEFLATED
class UnseekableStream(RawIOBase):
def __init__(self):
self._buffer = b''
def writable(self):
return True
@egor83
egor83 / ModuleNotFoundError.txt
Created July 2, 2021 08:22
Solving ModuleNotFoundError: No module named 'pip._vendor.six' with pyenv and pipenv
I got an error `ModuleNotFoundError: No module named 'pip._vendor.six'` after trying to run `pipenv install` on a new project.
At first I tried using the solution described here:
https://github.com/pypa/pip/issues/6261#issuecomment-471438784
I was using pyenv, so I did the following:
```
rm -rf /home/user/.pyenv/versions/3.7.5/lib/python3.7/site-packages/pip
# I also had to remove second pip directory, named something like pip-X.Y.Z.dist-info
python -m ensurepip
pip install --upgrade pip
@egor83
egor83 / django_apache_mod_wsgi_deployment
Last active May 13, 2022 12:19
Deploying Django on Apache server with mod_wsgi
Deploying Django on Apache server with mod_wsgi
Per https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/modwsgi/
https://modwsgi.readthedocs.io/en/develop/installation.html
Some things are not immediately obvious, so I'm writing down the detailed list of steps that worked for me.
I started with bare VPS, using Ubuntu 18.04.4. Python 3 (3.6.9) was available out of the box, but not Python 2.
Used the latest mod_wsgi version available (mod_wsgi-4.7.1)
@egor83
egor83 / gist:d020bc64f53a6ae2b1a548a12f7dbf27
Last active June 26, 2017 14:33 — forked from DerZyklop/gist:8551498
All terminal colours
echo -e '
\e[00;30m 00;30m \e[00m \e[02;30m 02;30m \e[00m \e[01;30m 01;30m \e[00m \e[01;40m 01;40m \e[00m
\e[00;31m 00;31m \e[00m \e[02;31m 02;31m \e[00m \e[01;31m 01;31m \e[00m \e[01;41m 01;41m \e[00m
\e[00;32m 00;32m \e[00m \e[02;32m 02;32m \e[00m \e[01;32m 01;32m \e[00m \e[01;42m 01;42m \e[00m
\e[00;33m 00;33m \e[00m \e[02;33m 02;33m \e[00m \e[01;33m 01;33m \e[00m \e[01;43m 01;43m \e[00m
\e[00;34m 00;34m \e[00m \e[02;34m 02;34m \e[00m \e[01;34m 01;34m \e[00m \e[01;44m 01;44m \e[00m
\e[00;35m 00;35m \e[00m \e[02;35m 02;35m \e[00m \e[01;35m 01;35m \e[00m \e[01;45m 01;45m \e[00m
\e[00;36m 00;36m \e[00m \e[02;36m 02;36m \e[00m \e[01;36m 01;36m \e[00m \e[01;46m 01;46m \e[00m
\e[00;90m 00;90m \e[00m \e[02;90m 02;90m \e[00m \e[01;90m 01;90m \e[00m \e[01;100m 01;100m \e[00m
\e[00;91m 00;91m \e[00m \e[02;91m 02;91m \e[00m \e[01;91m 01;91m \e[00m \e[01;101m 01;101m \e[00m
@egor83
egor83 / gist:7413070
Last active March 9, 2020 15:20 — forked from cpatulea/gist:7394412
Find Python string literals that should probably be Unicode
#!/usr/bin/python
import ast, _ast, os
for root, dirs, files in os.walk('.'):
for name in files:
if name.endswith('.py'):
full = os.path.join(root, name)
t = ast.parse(open(full).read())
for n in ast.walk(t):
if isinstance(n, _ast.Str) and not isinstance(n.s, unicode):
@egor83
egor83 / Google_Spreadsheets.py
Last active September 14, 2016 21:01
Working with Google spreadsheets with Python GData API
client = gdata.spreadsheets.client.SpreadsheetsClient()
token.authorize(client)
sps = client.GetSpreadsheets()
print len(sps.entry) # shows how many spreadsheets you have
sprd_key = 'put an appropriate spreadsheet key here'
wss = client.GetWorksheets(sprd_key) # get a list of all worksheets in this spreadsheet, to look around for info in a debugger
ws = client.GetWorksheet(sprd_key, 'od6') # get the first worksheet in a spreadsheet; seems 'od6' is always used as a WS ID of the first worksheet