Skip to content

Instantly share code, notes, and snippets.

View Stoops-ML's full-sized avatar

Daniel Stoops Stoops-ML

  • Omnisys
  • Israel
View GitHub Profile
@Stoops-ML
Stoops-ML / pyenv_alt.md
Created October 24, 2023 06:51
Alternative to pyenv for Windows

Simple pyenv Alternative for Windows

pyenv for Windows is a useful tool. However, my experience is that it doesn't play nice with tox on many machines and thus can't be used when creating Python packages.

An alternative is to replace pyenv with PowerShell shortcuts. The following can be placed in the user's profile for PowerShell to give some of the pyenv funcationallity. It assumes the user is using posh-git.

# posh-git
Import-Module posh-git
$GitPromptSettings.DefaultPromptPrefix.Text = '$(&{If($env:POETRY_ACTIVE -ne 1) {"($env:vpy) "} Else {""}})'
@Stoops-ML
Stoops-ML / reorder_python_imports_recursive.md
Last active September 12, 2023 06:31
reorder-python-imports

Recursively execute reorder-python-imports

The author of reorder-python-imports has no intention of implementing a recursive flag to the package; for example, asottile/reorder-python-imports#76.

The author suggests to run the package through pre-commit, pre-commit try-repo https://github.com/asottile/reorder-python-imports --all-files, which is overly time-consuming.

A better method is to use PowerShell: Get-ChildItem . -recurse -Filter *.py | Foreach-Object {reorder-python-imports.exe $_.FullName}.

If using git: Get-ChildItem $(git rev-parse --show-toplevel) -recurse -Filter *.py | Foreach-Object {reorder-python-imports.exe $_.FullName}.

@Stoops-ML
Stoops-ML / download_extensions.py
Last active May 11, 2025 11:20
Download VS Code extensions with Python for computers without internet access.
import threading
import re
import subprocess
import urllib.request
from pathlib import Path
from typing import Union
import tempfile
def download_file(url: str, file_path: Path, lock: threading.Lock) -> None:
@Stoops-ML
Stoops-ML / pyenv_poetry.md
Last active June 22, 2023 19:10
Pyenv-win and Poetry

Pyenv-win and Poetry

On my Windows machine pyenv and poetry don't play nicely together. When spawning a Poetry shell I get cmd as opposed to PowerShell.

This seems to be because pyenv-win is downloading a Microsoft Store version of Python, shown by pyenv requiring python instead of py in the shell to run Python.

My current work-around is to run poetry shell and from the spawned cmd open PowerShell using pwsh.exe. This returns a shell with the Poetry environment activated in PowerShell.

You then get all the power of PowerShell. See here on how to prettify the Poetry prompt.

def interpolation_table_to_regular_grid(table: np.ndarray) -> Tuple[List[np.ndarray], np.ndarray]:
"""
Convert an interpolation table to a regular grid with data.
The grid and data outputs can than be used with the numpy/scipy interpolation libraries.
:param table: interpolation table
:return: interpolation grid, interpolation data
"""
grid = [np.unique(table[:, i]) for i in range(table.shape[1] - 1)]
grid_size = [axis.size for axis in grid]
data = table[:, -1].reshape(grid_size)
from typing import List
class Employee:
def __init__(self, first_name, last_name, ID_num):
self.first_name = first_name
self.last_name = last_name
self. _ID_num = ID_num
def change_last_name(self, new_name):