Skip to content

Instantly share code, notes, and snippets.

View CodeByAidan's full-sized avatar
💻
i love HPC/DL

Aidan CodeByAidan

💻
i love HPC/DL
View GitHub Profile
@CodeByAidan
CodeByAidan / Microsoft.PowerShell_profile.ps1
Last active July 29, 2024 12:41
little sexy script I made to stop having fnm (Fast Node Manager - https://github.com/Schniz/fnm) from not being detected by the Path on PowerShell - just reinstalls it! You can do this same kinda thing with anything! This script is part of my $PROFILE
function Test-Fnm {
if (-not (Get-Command fnm -ErrorAction SilentlyContinue)) {
$flagFile = "$env:TEMP\fnm_installing.flag"
if (-not (Test-Path $flagFile)) {
New-Item -Path $flagFile -ItemType File | Out-Null
try {
Start-Process powershell -ArgumentList "-NoProfile -Command `"winget install Schniz.fnm; Remove-Item -Path $flagFile`"" -WindowStyle Hidden
$maxRetries = 12 # wait up to 60 seconds (12 * 5)
$retry = 0
while (-not (Get-Command fnm -ErrorAction SilentlyContinue) -and $retry -lt $maxRetries) {
@CodeByAidan
CodeByAidan / log_variables_in_function.py
Created July 15, 2024 19:13
Decorator that prints the variables in a function (being wrapped) values as they change. Pretty nifty.
import sys
from functools import wraps
from typing import Any, Callable, Optional, TypeVar
F = TypeVar("F", bound=Callable[..., Any])
def log_variables(func: F) -> F:
@wraps(func)
def wrapper(*args: Any, **kwargs: Any) -> Any:
def tracer(frame, event, arg) -> Optional[Callable]:
@CodeByAidan
CodeByAidan / log_variables_in_recursion.py
Last active August 13, 2025 12:43
One of the most painful code I've wrote, a decorator to log variables in a function every time they set/get. Notice the recursion part 😔
from functools import wraps
from typing import Any, Callable, TypeVar
F = TypeVar("F", bound=Callable[..., Any])
def log_variables(func: F) -> F:
@wraps(func)
def wrapper(*args, **kwargs) -> Any:
if not hasattr(wrapper, "initialized"):
@CodeByAidan
CodeByAidan / colors.py
Created July 8, 2024 19:21
who needs colorama when you have static typing and factories?
from __future__ import annotations
from typing import ClassVar, Type, TypedDict, Unpack, cast
from pydantic import BaseModel, Field, create_model, model_validator
class ColorData(TypedDict):
black: str
red: str
@CodeByAidan
CodeByAidan / DataFrameStore.py
Created July 2, 2024 13:16
Preserve any size DataFrame, load/save - FAST!
from typing import Optional, TypeGuard
import pandas as pd
from pandas import DataFrame
class DataFrameStore:
"""
A class to store and manage a DataFrame, with the ability to save and load it to
and from a file in Feather format.
@CodeByAidan
CodeByAidan / quiz.py
Last active August 1, 2024 02:32
just some example quiz using model inheritance with @ override from typing in Python 3.12
import random
from dataclasses import dataclass
from string import ascii_lowercase
from typing import override
@dataclass
class Question:
prompt: str
answer: str
@CodeByAidan
CodeByAidan / _remove-docstrings-comments.py
Last active December 2, 2025 19:47
Simple script using ast, astor, and black to remove docstrings and comments from any python file.
import ast
import astor # `pip install astor`
from black import FileMode, format_str # `pip install black`
class DocstringRemover(ast.NodeTransformer):
def visit(self, node: ast.AST) -> ast.AST:
if isinstance(node, (ast.FunctionDef, ast.ClassDef, ast.Module)):
if (
@CodeByAidan
CodeByAidan / __sets.py
Last active June 27, 2024 13:25
Ordered Set implementation in Python
import collections
import itertools
from collections import abc
from typing import Any, Dict, Iterable, Iterator, Optional, Tuple
_sentinel = object()
def _merge_in(
target: Dict[Any, Any],
@CodeByAidan
CodeByAidan / set_execute_permission.sh
Created June 26, 2024 14:27
This script sets execute permissions for all .sh files in the current directory (not subdirectories)
#!/bin/bash
find . -maxdepth 1 -type f -name "*.sh" -exec chmod 755 {} \;
@CodeByAidan
CodeByAidan / url-in-string.ipynb
Created June 25, 2024 19:43
Check for URL in a String - 5 algorithms compared. - https://www.geeksforgeeks.org/python-check-url-string/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.