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 / 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.
@CodeByAidan
CodeByAidan / Concurrency-HTTP-JSON.cr
Last active June 24, 2024 18:24
An example using a GET HTTP call and parsing the result (with concurrency) in JSON via serialization. All using Crystal!
require "http/client"
require "json"
class Geo
include JSON::Serializable
property lat : String
property lng : String
end
class Address
@CodeByAidan
CodeByAidan / Program.cs
Last active June 20, 2024 20:37
Simple 0 external dependency C# script that uses the GitHub API to fetch information about a specific repository
using System;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
#nullable enable
public class GitHubApiClient
{
public async Task<Result<Repository>> GetRepositoryInfoAsync(string owner, string repo)
{
@CodeByAidan
CodeByAidan / fizzbuzzAI.h5
Last active June 19, 2024 15:02
Fizz Buzz with AI. Python script that uses a Keras Sequential model to solve the FizzBuzz problem. It uses a feed-forward neural network, one-hot encoding, and the Adam optimizer. It also includes user input processing and random test generation.
This file has been truncated, but you can view the full file.