Notebook.refactor to utils

From gpsaggese/helpers · View interactive version

Notebook.refactor to utils is an AI agent skill from the GitHub repository gpsaggese/helpers. Move or add notebook code to a *_utils.py library file

How to use this skill

Skill file

Goal

in py:percent format

Constraints

Scenarios

Scenario 1: Moving Existing Functions to Utils

Scenario 2: Adding New Code to Utils

Workflow

Identify or Create the Utils File

Lesson94_Information_Theory_utils.py

Organize Code Structure in Utils File

```python

# #############################################################################

# Cell 1: Visual Bin - Population of Marbles

# #############################################################################

def cell1_draw_bin_with_marbles_interactive(...):

...

def _cell1_helper_function(...):

...

# #############################################################################

# Cell 2: Entropy Calculations

# #############################################################################

def cell2_calculate_entropy(...):

...

```

Move or Add Functions

For Moving Functions (Scenario 1):

1. Copy all functions from the notebook to the utils file, without changing code

2. Remove the functions from the notebook

3. Update the notebook cells to call the utils functions

For Adding Functions (Scenario 2):

1. Implement new code directly in the utils file

2. Create caller code in the notebook that imports and uses the functions

3. Add the code in the matching section of the utils file

Update Notebook to Call Utils

```python

import notebook_name_utils as utils

# In code cells:

utils.function_name(...)

```

```python

# Display results of Cell 2 analysis.

utils.cell2_calculate_entropy()

```

Code Reuse

Sync with Jupytext

Responsibility -> ## Utilities vs. Notebook Responsibilities` in

.claude/skills/notebook.rules.md:

```bash

> uvx jupytext --sync <path/to/notebook.py>

```

Conventions

Verification

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.