Compare commits

...

6 Commits

Author SHA1 Message Date
eca51af5ea Fix 2025-03-17 17:52:01 +01:00
30ecc9b87c fuck 2025-03-17 17:50:48 +01:00
5dbf86164a fixed bug 2025-02-07 17:26:05 +01:00
84f36247a8 Added a much needed README 2025-02-03 21:07:15 +01:00
06f92a3228 Added flatcher 2025-02-03 21:07:08 +01:00
cecde4478d fixed path 2025-01-12 19:01:17 +01:00
4 changed files with 103 additions and 10 deletions

57
README.md Normal file
View File

@ -0,0 +1,57 @@
# Coding Tools
Tools that I wrote to help me code faster and more efficiently.
All of these require `python>=3.6`.
## [Ucompile](ucompile)
Pronounced "you compile", stands for "University Compiler". It is a simple script that compiles and runs programs in one line. It also automatically takes all `.in` files in the directory and feeds them to the program. It is useful for competitive programming and for testing programs with multiple test cases.
Currently supports:
- C (`.c`)
- Python (`.py`) (with Python 3 and PyPy3)
- Java (`.java`)
- Haskell (`.hs`)
Optional arguments:
- `-o` checks the output of the program against the `.out` files in the directory
- `-v, --verbose` prints the output of the program
- `-a` uses an alternative compiler (e.g. `mvn` instead of `javac`)
- `-t, --tests` specifies a test case folder (default is `.`, the current directory)
- `-T, --time` prints the time taken to run the program
The program is integrated with [temmies](https://github.com/Code-For-Groningen/temmies) for automatic [Themis](https://themis.housing.rug.nl/) submission.
## [unifytex](unifytex)
is a script designed to automate the process of generating separate LaTeX include files for `.tex` files in a directory, making it easier to manage large LaTeX projects. It recursively scans a specified directory and creates consolidated `.tex` files that include all the LaTeX files within each subdirectory.
(EXAMPLE) If the directory structure is:
```
/project
├── section1
│ ├── intro.tex
│ ├── methods.tex
├── section2
│ ├── results.tex
│ ├── discussion.tex
```
Running:
```bash
python3 unifytex.py /project
```
Will create:
```
/project/consolidated
├── section1.tex (contains \input{section1/intro.tex} and \input{section1/methods.tex})
├── section2.tex (contains \input{section2/results.tex} and \input{section2/discussion.tex})
```
This allows you to include an entire section in your main LaTeX document with:
```latex
\input{consolidated/section1.tex}
```
## [flatcher](flatcher)
Flask + Catcher = Flatcher. A simple script that runs a Flask server and catches all requests to a specified port, detailing the request method, path, and headers. Useful for debugging and testing webhooks.
> [!IMPORTANT]
> This script requires Flask to be installed. You can install it with `pip install Flask`.

19
flatcher Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/python
from flask import Flask, request
app = Flask(__name__)
@app.route('/', defaults={'path': ''}, methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
@app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
def capture_request(path):
"""
This route captures all requests, regardless of method or path.
"""
print(f"Request Path: {request.path}")
print(f"Request Method: {request.method}")
print(f"Request Headers: {dict(request.headers)}")
print(f"Request Body: {request.get_data(as_text=True)}")
return "Request captured and printed to the console!", 200
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)

View File

@ -13,7 +13,7 @@ def check_dependencies() -> None:
for command in commands: for command in commands:
if os.system(f"which {command} > /dev/null") != 0: if os.system(f"which {command} > /dev/null") != 0:
print(f"{Fore.ORANGE}WARNING: {command} not found{Style.RESET_ALL}") print(f"{Fore.RED}WARNING: {command} not found{Style.RESET_ALL}")
return return
@ -100,10 +100,18 @@ def run_input_cases(program, args) -> bool:
print("❌") print("❌")
passed = False passed = False
# green expected output and red program output # green expected output and red program output
print(f"{Fore.GREEN}Expected output:{Style.RESET_ALL}") # print(f"{Fore.GREEN}Expected output:{Style.RESET_ALL}")
print(expected_output) # print(expected_output)
print(f"{Fore.RED}Program output:{Style.RESET_ALL}") # print(f"{Fore.RED}Program output:{Style.RESET_ALL}")
print(program_output.strip()) # print(program_output.strip())
# print a diff
print(f"{Fore.YELLOW}Diff:{Style.RESET_ALL}")
# temporary file to store program output
with open("temp", "w") as f:
f.write(program_output)
os.system(f"diff -u {out_file} - < temp")
os.remove("temp")
else: else:
print( print(
f"{Fore.YELLOW}Expected output file not found; cannot compare outputs.{Style.RESET_ALL}" f"{Fore.YELLOW}Expected output file not found; cannot compare outputs.{Style.RESET_ALL}"
@ -152,10 +160,15 @@ def haskell_compile(file_name, args):
def c_compile(file_name, args): def c_compile(file_name, args):
# Style the code in Meijster's way # Style the code in Meijster's way
os.system("astyle -A2s2cxgk3W3xbj " + file_name) # os.system("astyle -A2s2cxgk3W3xbj " + file_name)
os.system( # If you want
"gcc -Wall -pedantic --std=c99 -g -o program -lm -Wno-unused-result " + file_name
) # stop if compilation fails
if os.system(
"gcc -Wall -pedantic --std=c99 -g -o program -pthread -lm -Wno-unused-result " + file_name
):
return False
run_input_cases("./program", args) run_input_cases("./program", args)
return return

View File

@ -23,7 +23,11 @@ def dynamic_includes(folder_path):
f.write("% Autogenerated by unifytex (git.confest.im/boyan_k/Coding_Tools/)\n") f.write("% Autogenerated by unifytex (git.confest.im/boyan_k/Coding_Tools/)\n")
for file in sorted(files): for file in sorted(files):
if file.endswith(".tex"): if file.endswith(".tex"):
relative_path = os.path.relpath(os.path.join(root, file), folder_path) relative_path = os.path.relpath(
os.path.join(root, file),
os.path.dirname(os.path.abspath(folder_path))
)
f.write(f"\\input{{{relative_path}}}\n") f.write(f"\\input{{{relative_path}}}\n")
print(f"Generated {output_file}") print(f"Generated {output_file}")