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
  • some college located in northeast usa
  • 11:56 (UTC -04:00)
View GitHub Profile
@CodeByAidan
CodeByAidan / get-path-clipboard-quoted.ps1
Created July 17, 2024 12:36
Copy the current path into your clipboard in a one-liner with PowerShell.
Set-Clipboard -Value ("`"" + (Get-Location).Path + "`"")
# "C:\Windows"
@CodeByAidan
CodeByAidan / Microsoft.PowerShell_profile.ps1
Created July 15, 2024 20:58
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 Ensure-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 July 15, 2024 18:02
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 / wahgwandelilah.vb
Created July 8, 2024 19:10
i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love vba i love…
Public Function Similarity(ByVal String1 As String, _
ByVal String2 As String, _
Optional ByRef RetMatch As String, _
Optional min_match = 1) As Single
Dim b1() As Byte, b2() As Byte
Dim lngLen1 As Long, lngLen2 As Long
Dim lngResult As Long
If UCase(String1) = UCase(String2) Then
@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
Created July 1, 2024 18:23
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 June 27, 2024 15:44
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],