Friday, 20 June 2025

Transfer Jupyter Notebook into a text file

!pip install ipynbname
import json
import nbformat
from nbformat import read, write
import os
import ipynbname
def export_notebook_to_txt():
    # Get the current notebook name
    notebook_filename = ipynbname.name()
    
    # Get the full path to the notebook
    notebook_path = ipynbname.path()
    
    # Read the notebook
    with open(notebook_path, 'r', encoding='utf-8') as nb_file:
        notebook = read(nb_file, as_version=4)
    
    # Prepare content for TXT file
    notebook_content = []
    code_cell_count = 0
    for cell in notebook.cells:
        if cell.cell_type == 'code':
            code_cell_count += 1
            # cell_content = f'# [{code_cell_count}]\n'
            cell_content = cell.source
        elif cell.cell_type == 'markdown':
            cell_content = '# [MD]\n'
            cell_content += '# ' + cell.source.replace('\n', '\n# ')
        notebook_content.append(cell_content)
    # Join all cell contents
    full_content = '\n\n'.join(notebook_content)
    
    # Save to TXT file
    txt_filename = f'{notebook_filename.split(".")[0]}_content.txt'
    with open(txt_filename, 'w', encoding='utf-8') as txt_file:
        txt_file.write(full_content)
    return f"Notebook content has been exported to {txt_filename}"
# Run the function
export_notebook_to_txt()

Sunday, 4 August 2024

Docker Сheatsheet

1. Get inside a container: docker exec -it <mattermost_container_name> /bin/bash

2. <comes later>

Thursday, 1 August 2024

XWiki render MathJax without extensions

Go to https://WIKI.YOURSITE.COM/bin/admin/XWiki/XWikiPreferences?editor=globaladmin&section=Presentation and add the following to "HTTP META INFO" header at the beginning:

<script type="text/javascript">
  MathJax = {
    tex: {
      inlineMath: [['$', '$'], ['\\(', '\\)']],
      displayMath: [['$$', '$$'], ['\\[', '\\]']]
    },
    options: {
      skipHtmlTags: ['script', 'noscript', 'style', 'textarea', 'pre']
    },
    startup: {
      ready: function() {
        MathJax.startup.defaultReady();
        MathJax.typesetPromise();
      }
    }
  };
</script>
<script async="" id="MathJax-script" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" type="text/javascript">
</script>

Sunday, 21 July 2024

Git fix all "missing" renames

To continue the previous epopee: we shall interactively detect all the occurrences of the missed renames in a given git repo, and let user choose if he wants to make a potential rename into real rename.

Wednesday, 17 July 2024

Git fix the "missed" rename

In git, there are no renames. It uses "heuristics" to detect files been deleted-and-added that are "actually" renamed. The "good practice" is to never mix these "renames" with file modifications, else git will loose the track of "renames" and thus history navigation for these files will become a serious pain. But sometimes you "forget" about these "great" practices. The script to fix an accidental loss of real rename below is to the resque.

Monday, 25 September 2023

WIN32_LEAN_AND_MEAN and DuckDB

This keeps striking me every other year when building something from sources.

Got a ton of windows.h-related errors when compiling C++ sources is a typical sign.

The correct way would be to define WIN32_LEAN_AND_MEAN when building:

git clone git@github.com:duckdb/duckdb.git --branch v0.8.1 --single-branch
cd duckdb
python scripts/amalgamation.py
md build
cd build
cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Debug -DAMALGAMATION_BUILD=ON -D CMAKE_CXX_FLAGS="/D WIN32_LEAN_AND_MEAN" ..
cmake --build . --config Debug

Wednesday, 6 September 2023