Skip to content

Instantly share code, notes, and snippets.

View CodeByAidan's full-sized avatar
💻
new semester 🔥🔥🔥

aidan CodeByAidan

💻
new semester 🔥🔥🔥
View GitHub Profile
@CodeByAidan
CodeByAidan / make_shell_scripts_executable.sh
Created March 10, 2024 19:28
Quickly make all shell script files executable within a directory. With this gist, you can easily share the command to make all shell script files executable within a specific directory. It's a handy utility for enhancing productivity and managing shell scripts effectively.
find /path/to/your/directory -type f -name '*.sh' -exec chmod +x {} \;
@CodeByAidan
CodeByAidan / .clang-format
Created March 10, 2024 03:51
my true clang format guide. behold. (for C++ and clang-format 16+)
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: false
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
@CodeByAidan
CodeByAidan / SupressOutput.py
Created March 4, 2024 19:09
A context manager that suppresses stdout and stderr using contextlib in Python.
import contextlib
from typing import Any, Generator
@contextlib.contextmanager
def suppress_stdout_stderr() -> Generator[None, Any, None]:
"""
A context manager that redirects stdout and stderr to /dev/null
"""
with open("/dev/null", "w", encoding="utf-8") as null:
with contextlib.redirect_stdout(null), contextlib.redirect_stderr(null):
@CodeByAidan
CodeByAidan / GenerateFileContents.bat
Last active March 19, 2024 22:20
(.bat, .py, .sh, .ps1) - This script generates a file that contains the contents of all files in a directory and its subdirectories. Great tool for using with ChatGPT - so you can export all your files quickly and paste it over! Powershell version is the most customized for now.
:: GenerateFileContents.bat
:: ~~~~~~~~~~~~~~~~~~~~~~~~
:: Description:
:: This script generates a file that contains the contents of all files in a directory and its subdirectories.
::
:: Parameters:
:: 1. Directory path to search for files in (i.e. "D:\Other\Java Projects\luhnalgorithm\src\main\java\com")
:: 2. Output file path (i.e. "D:\Other\Java Projects\luhnalgorithm\filecontents.txt")
:: 3. File extensions to look for (i.e. "java" or "java txt" or "java txt csv")
::
@CodeByAidan
CodeByAidan / _fib.asm
Last active February 21, 2024 15:19
fibonacci sequence in 64-bit Linux (Debian distro) assembly, fixed compile errors (integrates with a C library)!! (Works with Debian WSL on Windows!)
; -----------------------------------------------------------------------------
; A 64-bit Linux application that writes the first 90 Fibonacci numbers. To
; assemble and run:
;
; nasm -f elf64 _fib.asm && gcc _fib.o -no-pie -o a.out && ./a.out
; -----------------------------------------------------------------------------
global main
extern printf
@CodeByAidan
CodeByAidan / pdf_server.py
Created February 14, 2024 18:17
A simple HTTP server that serves a single PDF file.
"""
A simple HTTP server that serves a single PDF file.
This script creates a basic HTTP server that serves a single PDF file to clients.
The server listens on port 8000 by default and serves the specified PDF file.
Clients can access the PDF file by visiting the server's IP address.
Usage:
python3 server.py
"""
@CodeByAidan
CodeByAidan / mypy.ini
Last active February 27, 2024 21:47
Personal mypy config! Includes EVERY DEFAULT OPTION!
[mypy]
; The mypy configurations below are my personal preferences.
check_untyped_defs = True
disallow_any_generics = True
disallow_any_unimported = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_decorators = True
disallow_untyped_defs = True
ignore_missing_imports = True
@CodeByAidan
CodeByAidan / Print_Attributes.py
Last active February 7, 2024 00:15
Recursively prints the attributes of an object.
def print_attributes(obj: object, indent: int = 0) -> None:
"""
Recursively prints the attributes of an object.
Args:
obj (object): The object to print the attributes of.
indent (int, optional): The number of spaces to indent the output. Defaults to 0.
Returns:
None
@CodeByAidan
CodeByAidan / Stack.py
Last active February 7, 2024 00:17
Stack Implemention using Generics in mypy/Python with typing lib. Python 3.10+ required.
"""
A simple stack implementation using Generics.
This is a simple stack implementation using Generics. It is based on the
example from the Python docs:
https://docs.python.org/3/library/typing.html#user-defined-generic-types
"""
from typing import TypeVar, Generic
@CodeByAidan
CodeByAidan / RGB_tuple_to_hexadecimal.py
Last active January 24, 2024 15:17
Convert an RGB tuple to a hexadecimal color code in Python.
def _rgb_to_hexadecimal(
rgb: tuple, include_prefix: bool = False, lowercase: bool = False
) -> str:
"""
Convert an RGB tuple to a hexadecimal color code.
Args:
rgb (tuple): The RGB tuple representing the color components.
include_prefix (bool, optional): Whether to include the '#' prefix in the hexadecimal color code. Defaults to False.
lowercase (bool, optional): Whether to use lowercase letters in the hexadecimal color code. Defaults to False.