Skip to content

14th Week of 2022

Computer Science

GNULinux

Alacritty

  • New: Setup remote shell automatically.

    An usefulzsh function is:

    s () {
        infocmp | ssh $@ 'tic -x /dev/stdin'
        ssh $@
    }
    

    Which will setup the shell always before connecting.

dpkg

  • New: Most common commands.

    • dpkg -S (--search): Find package(s) owning file(s).

Git

  • New: Move last n commits to a new branch.

    So you forgot to create a feature branch ah? No problem, let's move the last few unpushed commits to a new branch:

    git checkout -b new_branch # create a new branch from the current one
    git checkout old_branch # go back to the original branch
    git reset --hard HEAD~3 # undo the last 3 commits
    git checkout new_branch # go to the new branch and continue there
    

GTK

  • New: How to change themes.

    GTK is a free and open-source cross-platform widget toolkit for creating graphical user interfaces.

    To change the theme, either use lxapparence or manually edit ~/.config/gtk-3.0/settings.ini. You will be forced to do the second option if the theme is for gtk-3 only.

i3 window manager

  • New: Get pressed key name.

    Some key names are hard to guess, such as XF86AudioRaiseVolume, and you need their name to use them in bindings. You can use xev for that.

LibreOffice

  • New: LibreOffice Calc IF().

    Syntax: IF(Test, Then Value, Otherwise Value).

    Example:

    =IF(A2>500,"High","Low")
    

NeoMutt

  • New: Mailboxes commands.

    • c?<Tab>: (on top of a mailbox) Shows all subdirectories and allows to open them.

neovim

  • New: Edit remote files with SSH.

    Just run:

    nvim scp://user@host//tmp/file
    

    Notice the extra /. You can also specify just a directory to browse it interactively.

  • New: Cherry pick lines to commit.

    tpope/vim-fugitive: fugitive.vim: A Git wrapper so awesome, it should be illegal

    1. Open the git summary with :Git (or :G).
    2. Expand the file which contains the lines you want to stage with > (or = to toggle). This will only show the changed chunks plus some extra lines of context above and below the changed lines.
    3. V to start visual mode and select the lines you want to stage with hjkl.
    4. s to stage the visual selection (or - to toggle)
    5. Repeat 2-4 as needed
    6. cc to commit

OpenLDAP

  • New: Show special entries and attributes in search.

    ldapsearch [...] +
    

Programming

aiohttp

  • New: Pyhton AIOHTTP.

    Basic example:

    import aiohttp
    import asyncio
    
    async def main():
        async with aiohttp.ClientSession() as session:
            async with session.get('http://httpbin.org/get') as resp:
                print(resp.status)
                print(await resp.text())
    
    asyncio.run(main)
    

    Other methods:

    ``python session.put('http://httpbin.org/put', data=b'data') session.delete('http://httpbin.org/delete') session.head('http://httpbin.org/get') session.options('http://httpbin.org/get') session.patch('http://httpbin.org/patch', data=b'data')

  • New: Headers.

    headers = {
        'Accepts': 'application/json',
        'X-API_KEY': 'secret',
    }
    
    async with aiohttp.ClientSession(headers=headers) as session:
        ...
    

Basics

  • New: Enumerate().

    To iterate over a list keys and values use enumerate(). Example:

    some_list = ['a', 'b', 'c']
    for index, value in enumerate(some_list):
      ...
    
  • New: Enum.

    Example:

    from enum import Enum
    
    class Color(Enum):
      RED = 1
      GREEN = 2
      BLUE = 3
    
  • New: Enum examples.

    >>> Color(1)
    <Color.RED: 1>
    >>> Color(3)
    <Color.BLUE: 3>
    
    >>> Color['RED']
    <Color.RED: 1>
    >>> Color['GREEN']
    <Color.GREEN: 2>
    
    >>> member = Color.RED
    >>> member.name
    'RED'
    >>> member.value
    1
    
  • New: Datetime nstance methods.

    • isoformat(): ISO 8601 formatted string.

Logging

  • New: Python logging.

    Basic configuration:

    import logging
    
    logging.basicConfig(
        format='%(asctime)s %(levelname)s %(message)s',
        level=logging.INFO,
        datefmt='%Y-%m-%d %H:%M:%S'
    )
    
    logging.info('Just a random string...')
    

pydantic

  • New: Pydantic types.

    • pydantic.HttpUrl
    • pydantic.color.Color
  • New: Exporting.

    Options:

    • model.json(exclude_none=True)
    • model.dict(exclude_none=True)

Typing

  • New: Awaitable type.

    • Awaitable: Promise/Future.