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

Friday, 1 September 2023

Friday, 9 June 2023

Color coding for Visual Studio

https://marketplace.visualstudio.com/items?itemName=ryzngard.Carnation2022020
https://studiostyl.es/schemes/notepad2-c
https://studiostyl.es/schemes/search?q=notepad
https://studiostyl.es/schemes/github-light-for-notepad

Monday, 22 May 2023

Saturday, 20 May 2023

Windows startup locations

Shell:startup
Shell:common startup
%ProgramData%\Microsoft\Windows\Start Menu\Programs\StartUp
%appdata%\Microsoft\Windows\Start Menu\Programs\Startup


Friday, 12 May 2023

Favourite .style.yapf

[style]
based_on_style = pep8
column_limit = 100
indent_width = 4
allow_split_before_dict_value = false
split_before_named_assigns = false
split_before_closing_bracket = true
split_before_first_argument = false
split_before_expression_after_opening_paren = false
split_arguments_when_comma_terminated = true
COALESCE_BRACKETS = true
DEDENT_CLOSING_BRACKETS = true
INDENT_CLOSING_BRACKETS = false
JOIN_MULTIPLE_LINES = true
SPLIT_ALL_TOP_LEVEL_COMMA_SEPARATED_VALUES = false
SPLIT_COMPLEX_COMPREHENSION = true
SPLIT_ALL_COMMA_SEPARATED_VALUES = false
EACH_DICT_ENTRY_ON_SEPARATE_LINE = false
BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION = 1

Wednesday, 8 February 2023

PyCall in Julia to work on Windows with Anaconda

Julia ships its own Miniconda distro and uses to it by default. It actually tries to install this distro, and fails in my case. It fails to many other people too. It cannot know you already have another Python setup available. Help it with the following, when building PyCall. Note that you need to build PyCall manually before using it, or you'll get ERROR: LoadError: PyCall not properly installed. Please run Pkg.build("PyCall").

In Julia prompt, execute:

import Pkg
ENV["PYTHON"] = raw"C:\Users\YOUR_USER\anaconda3\python.exe"
Pkg.build("PyCall")

Tuesday, 7 February 2023

Jupyter Lab shortcut, dir listing in a current folder

Make a regular shortcut in a directory where you want Jupyter Lab to open with this target:

C:\WINDOWS\system32\cmd.exe /K "call %HOMEDRIVE%%HOMEPATH%\Anaconda3\Scripts\activate.bat & call jupyter lab && exit"

Set "Start in" as %cd%, and "Run" as Minimized. Done!




Saturday, 5 November 2022

Download entire website with wget or httrack

Before I used to run HTTrack (Windows, GUI version), but most of the time it wasn't what I wanted.

Here is a complete wget solution:

wget -r --no-parent --mirror --page-requisites --adjust-extension --convert-links --continue -e robots=off  https://www.website.com/

UPD: Yet, after a while, that was still isn't what I wanted :) I needed to crawl all pages which only belong to this website's domain PLUS the files like PDF the website references which are outside of site's domain. WGET won't give you this. HTTRACK in its CONSOLE incarnation, however, does. Here is the solution:

httrack --near -u2 -p7 https://YOUR_SITE

Note, it's GUI version won't do! Moreover, I found no switch in its GUI where these flags could be activated, same as no place to add cmd prompt flags manually.

Saturday, 29 October 2022

Download a youtube playlist

 Put ffmpeg.exe and yt-dlp (latest versions) to the folder where files to be downloaded.

The following command will download a playlist ${YOUR_PLAYLIST} in a subfolder with its reference name, enumerating the videos as they are ordered in the list, and assigning their names to the files. Numeration will start with 01 and with the oldest video. We need this to be able to keep the numeration later when we update the contents. The file archive.txt is needed to track the update and only download what hasn't been downloaded yet.

yt-dlp --format "bestvideo[height<=4k]+bestaudio/best" https://www.youtube.com/${YOUR_PLAYLIST} --embed-thumbnail --add-metadata --parse-metadata "description:(?s)(?P<webpage_url>.+)" --playlist-reverse --download-archive _archive --write-auto-sub --sub-langs "en,ru" -o "%%(playlist_index)s - %%(title)s - %%(id)s.%%(ext)s" --compat-option playlist-index


Wednesday, 29 June 2022

Simple solution for ThinkPad TrackPoint drift

TL;DR: To get rid of the drift, replace your TrackPoint cap with a fresh one that really fits your laptop model. Get a pack of caps on Amazon or ebay (P/N 4XH0L55146 might be a fit). Even if you own a brand-new laptop and have never changed the red cap yourself, try changing it, as the manufacturer might have confused the parts or use the cap which are slightly misaligned.

I'm a heavy IBM/Lenovo ThinkPad-s user over a span of the last 15 years: T61, x120e, W520 2x, T430s, T460p, x1, and lastly – x1 Extreme. The only one which had a famous TrackPoint drift is x1 Extreme. I've been using it since September 2018 – almost 4 years by now, and though I really liked it, the drift made my experience vastly unfortunate. I've actually abandoned using TrackPoint, so painful this was. I've made many attempts to fix it (more on this later).

Thus, it was even more to my surprise that I've found a very simple solution to a TrackPoint drift problem.

Wednesday, 4 August 2021

Downloading a GitHub pull request

 Adopted from here.

git clone --depth 1 git@github.com:org/repo.git
cd repo
git fetch origin branch_name:branch_name
git checkout branch_name