I’ve encountered this rather profane yet tricky problem while testing a method: class MyClass : def __method (self) -> str: pass def test () with patch . object(MyClass, "__method" ) as _: pass pytest E AttributeError: <class 'MyClass'> does not have the attribute '__method' A llm pointed to the name mangling cause. Changing __method to _MyClass__method fixes the error: def test () with…
I found this code 1 to display the wireless status in the modeline. A first attempt led to nothing i.e. nothing was shown in my modeline. I had to modify the regex in order to match the output of /proc/net/wireless : diff --git a/wireless.el b/wireless.el index 55ec7fc..e08f864 100644 --- a/wireless.el +++ b/wireless.el @@ -55,7 +55,7 @@ :group 'wireless) (defcustom wireless-procfile-regexp - "^[…
In addition to this blogpost – whom focuses on chrome but on chromium, I had to run the following command to get rid of the chromium tick: sudo sed -i 's/chromium.desktop;//' /usr/share/applications/mimeinfo.cache
For starters, you want to write brother in ancient greek. Type adelfos to get an understanding of what’s happening. Set the input method to greek-babel: M-x set-input-method greek-babel . 1 Type adelfos again. The last typing of “adelfos” results in αδελφοσ. So far so good. However, αδελφοσ is wrong. It should be ἀδελφός. To be specific, we’re missing diacritics on a…
I’m testing a script against a live database. Accessing the db is slow and the test iterates trough all rows each time. Since I’m gradually increasing rows on each test run, I need only some, but not all rows. Problem: How can I avoid loading all rows but only fetch some ? Solution : Use yield Takeaway: Memorize the word yield as alias for fetch some. Why words matter is beautifully…
Emacs provides an incredible python developer experience. One of it many features is the ability to run pytest. However, I spent a reasonable amount of time, figuring out why M-x python-test-one was ignoring my pytest log level settings in pyproject.toml . Whatever I set in pyproject.toml, M-x python-test-one was printing out any level e.g. logger.INFO("do not show in test") pyproject.toml [tool .…
Haven’t found a short concise example covering pytest whilst focussing the patched json method of a mocked async session, hence this snippet. First install pytest-asyncio . pipenv install -d pytest-asyncio Now use it as highlighted. from unittest.mock import patch, AsyncMock import aiohttp import pytest async def request_async (): async with aiohttp . ClientSession(headers = {}) as session:…
Presuming a working python layer , following settings will provide autocompletion. e.g. typing Mymodel.ob will suggest Mymodel.objects for completion. yay basedpyright ~/.spacemacs.d/init.el (defun dotspacemacs/user-config () (use-package lsp-pyright :ensure t :custom (lsp-pyright-langserver-command "basedpyright" ) :hook (python-mode . (lambda () (require 'lsp-pyright ) (lsp)))) ) ...…
Links in Emacs org mode allow arbitrary emacs-lisp execution. As a result, we can run any shell command, such as your favorite movie player : [[ elisp:(async-shell-command "mplayer /tmp/lecture.mp4") ][ linktitle ]] Arguments work too. e.g. play the movie from a particular position. This can come in handy when learning materials contain valuable information scattered throughout movies: [[…
I’m quite fond of keeping my code formatted. For example I use yapf to format python code. Sometimes I want particular regions not to be formatted . In particular I want rows to stay rows but one line. The solution is to indicate such regions for the formatter Without indication, the buffer is formatted from this: rows = [ ( 'john' , 'acme' ), ( 'jane' , 'acme' ) ] to that: rows = [( 'john'…
Only by chance, I noticed a failed systemd service. It’s a rather crucial service, namely my backup . I’ve decided to get notified by email in such circumstances. The solution consists of three parts: The actual backup service unit A unit status mail service A python email script On failure, the actual service triggers the email service which in turn triggers the email script. The %h…
Table of Contents Problems Solution What happens How it works By chance, I stumbled over an excellent article 1 about labeling code blocks in hugo. Roger’s article answers a major part of a question 2 of mine: How to visually distinguish between blocks of source code and result Problems There’s no not enough visual difference between the blocks of code and result print( "foo" ) foo The…
Given your image-dired tags have similar beginnings e.g 0.jpg;foo 1.jpg;foo: Now all you enter – in order to mark – images tagged with foo but not foo: , is this: M-x image-dired-mark-tagged-files foo$ Note the dollar sign suffix Why is such profane regex noteworthy? See how image-dired-dired.el preliminary establishes the tag collection: "\\(^[^;\n]+\\);\\(.*\\)"
Table of Contents Create an arbitrary bucket name Create the bucket Delete public access block Create a policy to allow public read access on the bucket Apply the policy to the bucket Create an example file Upload the example file to our bucket [Assert] Download the file using wget Delete all files in the bucket Delete the bucket Given is an application requiring public network storage. I’ve…
After a recent cleanup of treemacs projects, I wanted to add again a known project: ~/src/django Yet M-x treemacs-add-project returned (wrong-type-argument hash-table-p nil) Debugging with M-x debug-on-error gave away a suspicious gethash call: Debugger entered--Lisp error: (wrong-type-argument hash-table-p nil) gethash("/home/ra/src/django/crm" nil nil)…
While preparing to share this post on LinkedIn, I noticed something’s missing. The preview didn’t show an image or description. Apparently there’s a special so-called Open Graph protocol that solves this problem. From the protocol’s introduction: The Open Graph protocol enables any web page to become a rich object in a social graph. For instance, this is used on Facebook to…
Table of Contents Directory path and completeness config.toml Usage of the icons with ox-hugo shortcodes in content Conclusion 👋 I followed this concise blog post 1 about embedding font awesome in hugo. Of course, I expected everything to work flawlessly in my environment as well. And of course, this presumption was wrong again. Neither simply adding {{< fa bath >}} to the footer key in…
Table of Contents A minimal python project Installing the package in a virtual environment using pipenv with python 3.8 Review the installation in perspective of pipenv and python 3.8 Run something from the cli Review our current (cli) project’s state How can I start a python project the proper way? Extensible, with tests, as library and cli application, in a virtual environment and with an…
Given is this pullrequest https://github.com/joeyespo/pytest-watch/pull/108 pipenv install -d \ git+https://github.com/joeyespo/pytest-watch.git@refs/pull/108/head#egg = pytest-watch The -d flag installs the package in the Pipfile’s [dev-packages] section The #egg=pytest-watch suffix changes the pytest-watch Pipfile from "*" to {ref = "refs/pull/108/head", git =…
I manage my images using emacs dired, specifically image-dired. I found myself repeatedly marking images in order to paste their filepaths into various shell scripts for further manipulation. This article presents a convenient way to automate image manipulation tasks using a Bash script and Emacs Dired mode. It presents an approach to creating a Bash script that resizes images, applies padding and…
Edit the python script Keep a terminal open running the watch script e.g. $ sh watch.sh See the rendered result Each time you save the python script , the watch script gets notified and re-executes. I’m using feh (note the highlighted line in the watch script) to see the rendered result, since it refreshes automatically. #/tmp/blender_mini_example.py import bpy # Delete the default cube objs…
Given is a ledger file containing imported bank transactions we want to ignore. Let’s take a pending transaction for example. It has a merely formal character but no mathematical impact. Thus we want transactions having the word pending in the payee line not taken into account from ledger. 2012-03-10 KFC **pending** Expenses:Food $20.00 Assets:Cash 2012-03-10 KFC Expenses:Food $20.00…
#Content of ~/tmp/file.dat 2099/02/07 * acme Expenses:Groceries $ 1 Assets:Cash 2089/11/07 * foobar Expenses:Groceries $ 4 Assets:Cash I want – from the account Assets:Cash and from the latest transaction (acme) – only the date. I need the date formatted as Year-Month-Day . ledger -f ~/tmp/file.dat reg \ Assets:Cash \ --tail 1 \ --format %D \ --date-format %Y-%m-%d 2099-11-07
Process all your email contacts using mu and python. mu-cfind returns all contacts: mu cfind Excerpt from the returned results ... Newsletter Museum Tinguely infos@tinguely.ch ... Script import subprocess from collections import namedtuple # fetch raw input query = "mu cfind" subprocess . check_output((query), shell = True ) . splitlines() runQuery = subprocess . check_output((query), shell = True…
Table of Contents Abstract Goal Manual process briefly explained Script - Step by step Complete script Abstract Each time I buy something and pay it later, my expenses and liabilities increase . In this blog post I’m using the example of the reservation of a tennis court. Once a year, the club sends an invoice for every reservation made. In order to reflect this in my finances, I note each…
I wasn’t able to export my contacts from my iphone (iOS 11). Thus I mailed each contact to myself using an alias e.g. john.doe+contact@example.com . I’m using mu (mail indexer/searcher) version 1.6.4 for my emails. Everything else happens below: Extract vcf file from email contacts = ~/tmp/iPhoneContacts rm -r $contacts mkdir $contacts cd $contacts foundEmails = $( mu find to:$myemail…
Using emacs org and babel 1 , I want to quickly note ideas in python. Now usually I start scripting up to a certain level of complexity / exhaustion which inevitably leads me to setup a complete python project folder in order to get proper unit testing. Following setup allows me to stay in org mode and unit test. All together. (defun ndk/org-babel-evaluate-test-block-from-code-block ()…
Table of Contents Mermaid-cli Mermaid for org mode Usage Problem solving Being able to explain something with your words only prevails. For those other cases, here’s a way to do it with diagrams in emacs org mode. Figure 1: Gantt Diagram Figure 1 was generated from this text: #+name : gantt_diagram #+BEGIN_SRC mermaid :file /tmp/gantt.png gantt dateFormat YYYY-MM-DD title Acme Project Plan…
Using blender, I need to test multiple settings for my painting references e.g. lighting, material or the complete location. It all started with that minimal working example to render the sphere above. # /tmp/blender/blender_mini_example.py import bpy import time import os # Initialize variables used to print the rendered picture dir_path = os . path . dirname(os . path . realpath(__file__))…
Amongst others, I run this script as part of my tests after a system update. #Initialize variables input = test/site/content-org/screenshot-subtree-export-example.org output = test/site/content/writing-hugo-blog-in-org-subtree-export.md cd /tmp # Cleanup rm -r ox-hugo # Clone latest repository git clone git@github.com:kaushalmodi/ox-hugo.git cd ox-hugo # Make change in org file sed -i…
Goal of this method is the non-invasive annotation of pictures in LaTeX/pdf. Thus all annotations are written in LaTeX. The source picture 1 remains untouched. Figure 1: Source picture Figure 2: Help grid enabled #+EXPORT_LATEX_HEADER: \usepackage[background=black,text=white,arrow=red]{callouts} 1 2 3 4 5 6 7 8 9 10 11 12 13 \begin {annotate} { \includegraphics [width=0.8\textwidth]…
Say I want to write about the count of my system’s processors at the time of my writing. Or my current location’s weather or stock shares or …use your imagination. Now I do it like that: > At this very moment I’m writing this text on a machine with 4 processors. Verbatim: At this very moment I'm writing this text on a machine with src_bash{cat /proc/cpuinfo | grep…
Say you open any python file containing an import. Your IDE is spacemacs and pyright . You might encounter this error: [Pyright] Import "anymodule" could not be resolved In order to get rid of this error, hit: , F a This launches lsp-workspaces-folders-add which requires you to enter the project’s path e.g. ~/tmp/mypython/ as workspace. I had only ~/tmp/ in the lsp-workspaces and thought it…
So I want to compare if two dates are equal. I therefore input two dates and in return expect the comparison’s outcome as a bool. Usually I would: Write the function Print it’s result until I’m happy with it #somecode.py from datetime import datetime def compare_two_dates (date,otherdate): return date == otherdate date = datetime . now() . date() otherdate = datetime( 1900 , 12 ,…
Amongst others, I run this script as part of my tests after a system update. cd /tmp #Cleanup rm -r ox-hugo #Clone latest repository git clone git@github.com:kaushalmodi/ox-hugo.git cd ox-hugo #Make change in org file sed -i "s/\(Kaushal\)/The awesome \1/" test/site/content-org/screenshot-subtree-export-example.org #Simulate the export from org to markdown make md1 ORG_FILE =…
Table of Contents Motivation How to understand this post Script ingredients Modules Urls Process overview Visit the ISP’s login page Login Get the consumption values Logout Complete script Usage Conclusion Motivation I recently caught myself repeatedly checking my internet consumption balance. A perfect case for a script and an accompanying tutorial. For the sake of this tutorial’s…
Table of Contents Motivation Requirements Create the test Run the test Check folders and files Go offline Run the test again - offline Go back online Conclusion Motivation While testing code against online sources like websites or APIs I often find myself waiting for their responses. Furthermore it feels strange to knock on anyone’s door every couple of seconds just to test what I’m…
This script takes a screenshot of a website. It does so headless with Firefox. A backup is taken before doing anything. It deletes traces left during the process. Backup exec 2>& 1 orig = /home/ra/.mozilla/firefox backup = /home/ra/tmp/firefox_backup rm -rf $backup mkdir -p $backup cp -r $orig $backup : Create the test profile which firefox >/dev/null 2>& 1 && firefox --version which firefox…
Table of Contents Create a mount point List devices Backup & print current fstab Add the device to fstab Change device’s permission Test Cleanup Troubleshooting I need to persistently permit all users read/write access to a USB drive Create a mount point mkdir /mnt/usb500 List devices lsblk -o NAME,FSTYPE,LABEL NAME FSTYPE LABEL sda └─sda1 ext4 usb500gb mmcblk0 ├─mmcblk0p1 vfat boot…
Table of Contents Install the necessary packages Find the event iPhone connected Catch the event iPhone connected Create the trigger iPhone connected Create the action Backup iPhone Restart and reload all actors (not the iPhone though) Monitor the backup process This is a follow-up on Connect an iPhone to a Raspi . Install the necessary packages Find the event iPhone connected Connect your iPhone:…
Each time I change the monitor I have to zoom in or out firefox. Here’s how to set it via script: Figure 1: Large Figure 2: Small Locate the appropriate file ls /home/*/.mozilla/firefox/*/prefs.js Locate the appropriate parameter grep layout.css.devPixelsPerPx /home/*/.mozilla/firefox/*/prefs.js Large screen: Set the zoom #!/usr/bin/env bash factor = 2.5 if grep 'layout.css.devPixelsPerPx'…
Table of Contents Unlock your iPhone Connect and login into your raspi Update - Retrieve new lists of packages Upgrade - Perform an upgrade Install the necessary packages Connect the iPhone with the raspi via USB Accept the trust dialog on the iPhone Pair the phone Accept another trust dialog the on the iPhone Create a mount folder Mount the iPhone Approve success Summary of all commands to…
Table of Contents Install package Approve the connection Get a list of devices: Get a list of all device specific options: Scan a test file Scan productively Skipping empty pages Alias the command Install package sudo apt install sane-utils -y Approve the connection Enable the scanner by opening the scanner’s lid sudo sane-find-scanner -q found USB scanner (vendor=0x04c5 [Fujitsu],…
Figure 1: Screencast showing flameshot in action Setup Enable the org layer in your .spacemacs dotspacemacs-configuration-layers dotspacemacs-configuration-layers ' (org) Install flameshot sudo pacman -S flameshot Add the line below to your .spacemacs custom-set-variables (custom-set-variables ' (org-download-screenshot-method "flameshot gui --raw > %s" )) Usage While being in your org buffer:…
Table of Contents Goals Setup Workflow (Spacemacs) Goals Figure 1: Printed sample.pdf In order to get the same printout as in figure 1 above, both includepdf lines starting at line 37 here must be uncommented. Use emacs 1 org mode Compose a new letter with a few keystrokes Manage letters like e-mails Setup Change letter meta variables through a lco file The 2 koma manual at p.484 displays a nice…
Table of Contents Setup ox-hugo Create a new github repo via web front-end Clone the new repository Setup Hugo in our new repository Create the new hugo site Download a theme and add it as git sub-module Create the org content folder Create a minimal org file / web page Start the hugo server Browse to our local site Export our org file to hugo Note how hugo immediately rebuilds the site Check the…