August 11, 2021

How to Surround Highlighted Text With a Custom Snippet

In order to mark strings as “translatable” in Flask via Flask-WTF, you need to apply a special syntax. This means, e.g. in a Jinja template a string like Conference has to be transformed into {{ _('Conference') }}. This is a very tedious work, so I created a shortcut for it. Add the following lines to your keybindings.json: "key": "ctrl+shift+alt+0", "command": "editor.action.insertSnippet", "when": "editorHasSelection || editorHasMultipleSelections", "args": { "snippet": "{{ _('${TM_SELECTED_TEXT}') }}" } I used “ctrl+shift+alt+0” as on keyboard with a German layout the closing curly brace is on the same key as the 0....

April 27, 2021

How to Globally Gitignore Configuration Files

Until today, I did not make up my mind about what to do with configuration files, created by e.g. VS Code. Certainly, I do not want to commit them, but putting it into every’s repository .gitignore file is also cumbersome - and sometimes it is not possible. I always do a git add -u to avoid accidentally adding a venv or similar, so it did not really matter. Except… ❯ ....

March 26, 2021

How to Avoid Vscode From Causing High Cpu Load When You Have Directories With Many Files

Once I opened this one project, CPU load went through the roof and just did not stop. There is not much source code in the repository, but a lot of build artifacts get generated by it. I am using VS Code now for quite a while, and especially for this one repository, and I never noticed problems, until recently. As most of the time extensions are the cause for problems, the VS Code team even provides a kind of bisecting mechanism to help find faulty plugins....

January 29, 2021

How to Count Number of Selected Lines in Vscode

Today I wrote a CSV export with many, many columns, where in my Python code each column was calculated on a single line. So, in order to get the number of columns, I selected all related lines and in the status bar I saw the number of all selected chars! wat? solutions After some searching on Google and StackOverflow I came to the conclusion… Either a) you have to install an outdated plugin...

November 18, 2020

How to Delete Complete Lines With Search Replace

For many years now, I had been using Jetbrain’s IntelliJ Idea Ultimate happily also for my Python development. Due to “legacy issues”, I had to apply many # noinspection annotations to my source code. Now, that I switched to VS Code, I want to get rid of actually 821 # noinspection annotations :-) A simple search for # noinspection.* and a replacement with basically nothing would work, but that would leave behind many blank lines....

June 6, 2020

How to Deactivate Auto Import in Pylance

Unfortunately, the auto-import feature in PyLance surprised me with random imports. e.g. with from unittest.case import expectedFailure just when I typed assert result == expected. Luckily, the developers listened to the users, and with version 2020.8.0 this “feature” is optional. In order to deactivate it, set the following option to false: python.analysis.autoImportCompletions Thank you, Savannah!

April 11, 2020

How to Replace the Old With the New Decorator Syntax for Zope's Security Declarations

Zope’s security architecture is built upon security declarations, which scope can be either a method, several methods or even a complete class. Until recently you usually declared the security for a method like this… from AccessControl import getSecurityManager class Suggestions(SomeBaseClass): security = ClassSecurityInfo() security.declareProtected("View", "all_suggestions") def all_suggestions(): ... Then, when accessing this method, e.g. the logged in user’s role or group was checked against the security declaration. One big disadvantage was that you could easily introduce typos....