Easy way to backup your VS Code settings

I have quite a lot VS Code settings and extensions which took my a long time to set-up. Besides that I wanted to sync my settings between computers and finally found out this is possible.

Github or Microsoft accounts are supported!

This is a simple code preview how to use ChainMap to combine multiple config files into one with precedence. Attaching also Jupyter Notebook.

from collections import ChainMap
from pprint import pprint
local_config = {
"user": "localuser",
"pass": "localpass",
"host": "localhost"
}
global_config = {
"user": "globaluser",
"pass": "globalpass",
"host": "globalhost",
"timeout": 15
}
config = ChainMap(local_config, global_config)
pprint(config)
for k,v in config.items():
print(f"{k}:{v}")

Sometimes you need to initialize dictionary before you use it, for this reason you can use dict() subclass defaultdict(). This is how you would do it normally.

# counter for cars by vendor
cars = dict()
if 'ferrari' not in cars:
cars['ferrari'] = 1
else:
cars['ferrari'] += 1

but with default dict this scenario is far easier

# counter for cars by vendor
from collections import defaultdict
cars = defaultdict(int)
cars['ferrari'] += 1

Always remember that defaultdict takes as parameter callable (function) not default value.

I am preparing course for Python beginners and I was thinking how to do something they can try on their own computers quickly and immediately see results.

I would like to use Google Colab but when you want to present some results you usually want some graphical way for it containing images etc. And what is a better tip than HTML.

Here is a quick tip how to use HTML in your Jupyter Notebook.

from IPython.core.display import display, HTMLdisplay(HTML('<h1>Hello, world!</h1>'))
Google Colab and HTML in Output