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 / most-typescript-thing-ive-wrote.ts
Created April 29, 2024 15:26
most typescript thing i've wrote, will update when things get worse
type Category = {
title: string;
items: Array<{ name: string }>;
};
type Config = {
categories: Record<string, Category>;
};
function isCategory(obj: unknown): obj is Category {
@CodeByAidan
CodeByAidan / EnumMetaExample.py
Last active April 24, 2024 17:14
An example using EnumMeta, with EASE!
>>> from enum import EnumMeta, Enum
>>> Color3 = EnumMeta('Color3', (Enum,), (_ := EnumMeta.__prepare__(
... 'Color3', (Enum,),)) and any(map(_.__setitem__, *(zip(*{
... 'RED': 1,
... 'GREEN': 2,
... 'BLUE': 3,
... }.items())))) or _
... )
>>> print(Color3(1)) # or without print(): <Color3.RED: 1>
Color3.RED
@CodeByAidan
CodeByAidan / wordwrap.py
Last active April 15, 2024 20:19
Wordwrap text to a specified line length. Takes a string or file-like object as input and returns the wrapped text.
"""
Wordwrap text to a specified line length.
Takes a string or file-like object as input and returns the wrapped text.
"""
import re
from typing import IO, Union
def wordwrap(text_or_file: Union[str, IO], max_line_length: int = 80) -> str:
@CodeByAidan
CodeByAidan / 1.py
Last active April 15, 2024 19:27
String to BrainF**k in 2 different versions! Python execution recorded with https://rextester.com/, BrainF**k execution/steps recorded with https://minond.xyz/brainfuck/
def StrToBrf(v: str) -> str:
result = []
current = 0
for ch in v:
target = ord(ch)
diff = target - current
if diff > 0:
result.append('+' * diff)
elif diff < 0:
result.append('-' * abs(diff))
@CodeByAidan
CodeByAidan / json-sys-design.tcl
Created April 15, 2024 19:10
System architecture sample for a system, builds a simple JSON string
set interface INTERFACE_AX
set streams 4
set bandwidth BANDWIDTH_ADAPT
set vstaCount 1
set vstaConfig {{"interface_": "$interface", "txAtten": 0, "streams": $streams, "bandwidth": "$bandwidth"}}
set vstaConfig [subst -nocommands -nobackslashes $vstaConfig]
set vsta_array [lrepeat $vstaCount $vstaConfig]
set vsta_array [join $vsta_array ", "]
puts $vsta_array
@CodeByAidan
CodeByAidan / !WordBomb.py
Last active March 19, 2024 00:53
A simple script to open notepad and type words that contain a given letter. Closes notepad when user wants to stop, without saving the file. Template for a future bot for a wordbomb style game.
"""
WordBomb.py
~~~~~~~~~~~
A simple script to open notepad and type words that contain a given letter.
Closes notepad when user wants to stop, without saving the file.
Requirements:
- Python 3.8 or higher
- pyautogui (python3 -m pip install pyautogui)
@CodeByAidan
CodeByAidan / mouse-jiggle-keyboard-stroke-minfiied.ps1
Last active April 3, 2024 21:05
turns off when you move your mouse
Add-Type -assemblyName System.Windows.Forms;$a=@(1..100);$chars="abc";while($true){$c=[System.Windows.Forms.Cursor]::Position;Start-Sleep -Seconds 5;if($c -eq $([System.Windows.Forms.Cursor]::Position)){$randomX=$a|Get-Random;$randomY=$a|Get-Random;$newPosition=New-Object System.Drawing.Point($randomX,$randomY);[System.Windows.Forms.Cursor]::Position=$newPosition;$randomChar=($chars.ToCharArray()|Get-Random -Count $chars.Length)-join"";[System.Windows.Forms.SendKeys]::SendWait($randomChar);$backspaces="{0}"-f('{BACKSPACE}'*$randomChar.Length);[System.Windows.Forms.SendKeys]::SendWait($backspaces)}}
@CodeByAidan
CodeByAidan / js-file-import-fixer.cjs
Created March 14, 2024 18:28
Fixes transpiled JavaScript files from tsc (TypeScript Compiler), with ERR_MODULE_NOT_FOUND error! Simply change out the dirPath to your path of JavaScript files, for me in my TypeScript project it's dist/js.
/* eslint-disable @typescript-eslint/no-var-requires */
/**
* @fileoverview
* This script is used to fix the import paths in the JS files in the dist directory.
* It is used to fix the import paths in the JS files after the build process for tsc.
* That way you can then run `node dist/index.js` and the imports will work as expected!
* It is recursive, so it will fix all JS files in the directory and its subdirectories.
* e.g.
* import { someFunction } from '../../someModule';
* will be replaced with
@CodeByAidan
CodeByAidan / tree.sh
Created March 14, 2024 13:45
find and sed only to reproduce the tree command in Linux
find . -print | sed -e "s;[^/]*/;|____;g;s;____|; |;g"
@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 {} \;