In the middle of the desert you can say anything you want
Stumbled yet again1 on mentions of IPython and decided to look into it, prev. assumption being that it’s the same or almost the same thing as Jupyter Notebook. (Also the i in ipdb stands for IPython-enabled, apparently).
It’s not., it’s a separate interactive superset of the Python cli that’s runnable by itself through python3 -m IPython.
Which in turn feels like a better / more interactive shell that can also do magic commands (%xxx) that I’ve seen in Google Colab / Jupyter; additionally understands bash stuff as-is and does other cool stuff. Definitely worth looking into.
ALSO the same article1 mentions a way of using IPython inside ipdb, quoting:
ipdb> from IPython import embed
ipdb> embed() # drop into an IPython session.
# Any variables you define or modify here
# will not affect program execution
To run a program with ipdb without editing the source and dropping in an ipdb prompt when if it breaks from shell:
python3 -m ipdb script.py
Took another look at the official docu 26.2. pdb — The Python Debugger — Python 2.7.18 documentation:
p prints the expression following, pp pretty-prints it.Pressing u / d moves you through the individual frames of the stack.
Also TODO look into using it to run stuff and debug automatically on fail, without editing the source code.1
An Inverted index - Wikipedia is a mapping from content to its location/name, as opposed to the usual case of name-to-content. One use is searching.
This is part two of 211209-1354 Python testing basics with poetry and pytest. Fixtures scopes work similarly to the various setup/teardown functions of unittest, can be per module/class/etc.
@pytest.mark.xfail(reason="Reason why it's supposed to fail")
def test_...
For a specific exception, you assert that it raises that exception type and then can do asserts on the exception that is raised.
def test_whatever():
with pytest.raises(Exception) as excinfo:
raise Exception("oh no")
assert str(excinfo.value) == "oh no"
Regex also works (example directly from pytest.raises() API Reference
>>> with pytest.raises(ValueError, match=r'must be \d+$'):
... raise ValueError("value must be 42")
## Services (skipped, see below)
### Creating fixtures that get used automatically
```python
@pytest.fixture(autouse=True)
def skip_servicetest(request, run_services):
if request....
pytest.skip("skipped because X")
pyfakefs creates a fake filesystem that gets used transparently.
from pyfakefs.fake_filesystem import FakeFilesystem
@pytest.fixture
def common_fs(fs: FakeFilesystem):
fs.create_dir(Path("/tmp/common"))
fs.create_file("/tmp/common")
def test_filesystem_fixture(common_filesystem):
assert os.path.exists("/tmp/common")
assert os.path.exists("/tmp/not_there") == False
A development approach from TDD.
Tests should be:
3A is a common pattern for structuring tests.
In a test this would look like this:
string = "ABc"
result = string.upper()
assert result == "ABC"
import this
A coworker reminded be of this gem; quoting him:
The order is important. My favourite one is ’explicit is better than implciit'
Had a big repo, wanted to clone only some folders.
The setup below automatically fetched the subfolders I added to the sparse-checkout set.
git clone --filter=blob:none --no-checkout --branch main ssh://git@me.me/my/repo.git
cd myrepo
git sparse-checkout init --cone
git sparse-checkout set "activitywatch" "friends" ".task" ".timewarrior"
https://gohugo.io/tools/search/
It boils down to creating an index (json) then using something to search in it client side
Once an index is built, Lunr seems the way to do with this: https://lunrjs.com/docs/lunr.Query.html#~Clause
It seems flexible enough, including ability to search inside taxonomies.
~/.dotfiles for stow to work# essentials
sudo apt install cowsay fortune-mod
sudo apt install vim-gtk3 # for clipboard support
# wm clipboard
sudo apt install i3
sudo apt installxdotool maim xclip zenity
# misc
sudo apt install jq tldr silversearcher-ag rofi xscreensaver
sudo apt install blueman
sudo apt install tree stow
sudo apt install fish
sudo apt install taskwarrior timewarrior
sudo apt install arandr, autorandr
# if needed ensurepip
sudo apt install python3.12-venv
sudo apt install git git-lfs
sudo apt install tig
sudo apt install pavucontrol
#sudo apt install kitty
sudo apt install alacritty
sudo apt install htop
sudo apt install ncal # cal command
uv task installgem install friendsbrew install hugobrew install go-taskbrew install asciiquariumenpx pagefind (for hugo)chsh /usr/bin/fishtlp if it’s a laptop~/.fonts should work, subdirectories possible
fc-cache -v tells you which dirs it goes throughfc-cache -f installssudo apt install fonts-firacodealias cal="ncal -w -A1 -M" # week starts on monday, 1 months from now, show weeks
From SO1, if both are JSON serializable objects, you can use json:
from json import loads, dumps
from collections import OrderedDict
def to_dict(input_ordered_dict):
return loads(dumps(input_ordered_dict))
If you mess up config.py and restart qtile and most of your keybindings aren’t working, if you’re lucky you still have a terminal open. From it, you can fix config.py, then restart via qtile shell -> restart().