Notebooks

  • Python Notebook
    • tools
      • Colabs

        Colab is a web-based Notebook service that requires no setup to use and provides free access to computing resources, including GPUs and TPUs. Colab is especially well suited to machine learning, data science, and education (e.g. to lean python, JAX, Tensorflow, Pytorch…).

      • Marimo

        Marimo - Reactive notebook for Python

        Marimo is an open source Python-based notebook environment that makes working with data more interactive and intuitive. It supports both Python scripts and notebooks, allowing for seamless version control through Git.

        Marimo’s standout feature is its reactive UI, where changes in one part of the notebook automatically update other dependent parts, making it ideal for real-time data exploration.

        It is easy to use with plenty of features for advanced users. For example, it can be used to create interactive tools like embedding visualizers.

      • opennb - to open Jupyter notebooks from GitHub repositories

My Notebooks

Notebook Viewer

  • a simple way to share Jupyter Notebooks:
  • update notebooks
    • create a virtual env
      python3 -m venv my-env-jupyter
      source my-env-jupyter/bin/activate
      deactivate          # how to leave/exit/deactivate
      source deactivate   # if this doesn't work, try
      
    • convert notebooks to html
      • source my-env-jupyter/bin/activate
        cd docs/algorithms-data-structures/notebooks/files
        jupyter nbconvert --to html *.ipynb
        mv *.html ../html/
        
      • further info
        • convert notebooks to other formats
          • # nbconvert
            # convert notebooks to other formats
            # https://nbconvert.readthedocs.io/en/latest/
            jupyter nbconvert --to html mynotebook.ipynb
            jupyter nbconvert --to markdown mynotebook.ipynb
            jupyter nbconvert --to pdf mynotebook.ipynb
            
        • installation
          • pip3 install --upgrade --force-reinstall jupyter
            pip3 install --upgrade --force-reinstall notebook
            pip3 install --upgrade --force-reinstall ipython_genutils
            # the ‘Templates’ folder is not included in version 6.0.0
            pip3 install --upgrade --force-reinstall nbconvert==5.6.1
            
    • diff notebooks
      # rename all the `.ipynb` files to `-old.ipynb`
      for x in *.ipynb; do
        t=$(echo $x | sed 's/\.ipynb$//');
        o="$t-old.ipynb"
        mv $x $o  && echo "moved $x -> $o"
      done
      
      # compare if file content is equal
      # ../../../../my-env-jupyter/bin/nbdiff
      # ../../../../my-env-jupyter/bin/nbdiff-web
      for x in *-old.ipynb; do
        aux=$(echo $x | sed 's/\-old\.ipynb$//');
        n="$aux.ipynb"
      
        if [ -f $x ] && [ -f $n ]; then
          xMD5=$(cksum $x | cut -f1 -d" ")
          nMD5=$(cksum $n | cut -f1 -d" ")
      
          if [ "$xMD5" -eq "$nMD5" ]; then
            echo "they're equal: $x / $n";
          else
            echo "they're different: $x / $n";
            ../../../../my-env-jupyter/bin/nbdiff-web $x $n >/dev/null 2>&1 &
          fi
        else
          echo "nothing to compare: $x / $n";
        fi
      done
      
      • installation
        # tools for diffing and merging of Jupyter notebooks.
        # https://github.com/jupyter/nbdime
        # https://nbdime.readthedocs.io/en/latest/
        pip3 install nbdime==4.0.1
        # https://github.com/jupyter/nbdime/issues/749
        pip3 install 'jupyter-server==2.12.5'
        
      • playground
        # creating samples for testing
        touch a.txt b.txt c.txt d.txt e.txt
        
        # looping through `ls` results in bash shell script
        for f in *.txt; do
          echo "File -> $f"
        done
        
        # remove file extension
        for x in *.txt; do
          t=$(echo $x | sed 's/\.txt$//');
          echo "moved $x -> $t"
        done
        
        # rename all the `.txt` files to `-old.txt`
        for x in *.txt; do
          t=$(echo $x | sed 's/\.txt$//');
          o="$t-old.txt"
          mv $x $o  && echo "moved $x -> $o"
        done
        
        # find . -name "*.txt" -exec cksum {} \;
        # compare if file content is equal
        # ../../../../my-env-jupyter/bin/nbdiff
        # ../../../../my-env-jupyter/bin/nbdiff-web
        for x in *-old.txt; do
          aux=$(echo $x | sed 's/\-old\.txt$//');
          n="$aux.txt"
        
          if [ -f $x ] && [ -f $n ]; then
            xMD5=$(cksum $x | cut -f1 -d" ")
            nMD5=$(cksum $n | cut -f1 -d" ")
        
            if [ "$xMD5" -eq "$nMD5" ]; then
              echo "they're equal: $x / $n";
            else
              echo "they're different: $x / $n";
              ../../../../my-env-jupyter/bin/nbdiff-web $x $n >/dev/null 2>&1 &
            fi
        
          fi
        done
        # -eq: equal
        # -ne: not equal
        # -lt: less than
        # -le: less than or equal
        # -gt: greater than
        # -ge: greater than or equal