Skip to content

March of 2022

Computer Science

GNULinux

  • New: Download only the audio in MP3.

    youtube-dl --extract-audio --audio-format mp3 [url]
    

demicode

  • New: Get BIOS version.

    dmidecode -t bios -q
    

Git

  • New: Show commit information.

    To see the information of a particular commit use:

    git show <revhash>
    

neovim

  • New: Vim-surround shortcuts.

    • ysiw": Surround the word under the cursor with double quotes.
    • csiw"': Change the quotes surrounding the word under the cursor from double quotes to single quotes.
    • ds': Delete the single quotes surrounding the word under the cursor.
    • ysi)": Surround the text inside parentheses with double quotes.
    • cs)]: Change the parentheses surrounding the text inside parentheses to square brackets.

PostgreSQL

  • New: Get the 20 slowest queries.

    SELECT substring(query, 1, 50) AS short_query,
                  round(total_time::numeric, 2) AS total_time,
                  calls,
                  round(mean_time::numeric, 2) AS mean,
                  round((100 * total_time / sum(total_time::numeric) OVER ())::numeric, 2) AS percentage_cpu
    FROM  pg_stat_statements
    ORDER BY total_time DESC
    LIMIT 20;
    
  • New: Count NULL values.

    SELECT COUNT(*) FROM table WHERE column IS NULL;
    
    COUNT only conseiders non null values so use COUNT(*) (which counts the row) instead of COUNT(column) because the later would always return 0 since the filter gets only the null values of column.

Programming

basics

  • Reorganization: Renamed file.
  • New: Recursively log object.

    If you console.log() an object, only the first levels of it will be shown. To recursively log the whole object, use:

    console.dir(yourObject, { depth: null });
    
  • New: Map a dictionary to a dictionary.

    Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, v["someKey"]]));
    
  • New: Enum.

    There is no Enum in JavaScript but you can use:

    Object.freeze({ Apple: 0, Banana: 1, Cherry: 2});
    

Python

  • New: Adjust default plot size.

    Try running %matplotlib notebook after the imports.

pydantic

  • New: Logging.

    To add custom log messages to the uvicorn output, the dirty way, get the logger called uvicorn:

    logger = logging.getLogger("uvicorn")
    

Theory

Algorithms

  • New: Add union-find data structure definition and algorithms.

    In computer science, a disjoint-set data structure, also called a union–find data structure or merge–find set, is a data structure that stores a collection of disjoint (non-overlapping) sets.

    It can be used to store the connected components of an undirected graph.

    An example could be:

    0   1---2   3---4
    
    5---6   7   8   9
    
    • N is the number of nodes. Equals to 10 in the example.

    The data structure should support the following operations:

    • initialize(): Set the initial state of the graph.
    • find(p, q): Are nodes p and q connected?
    • union(p,q): Connect nodes p and q.

Other

  • New: Array find method.

    .find(): returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned. E.g., array1.find(element => element > 10).

  • New: Iterate keys and values.

    for (const [key, value] of Object.entries(object)) {
      console.log(key, value);
    }