Compare commits
6 Commits
5e34464718
...
master
Author | SHA1 | Date | |
---|---|---|---|
eca51af5ea | |||
30ecc9b87c | |||
5dbf86164a | |||
84f36247a8 | |||
06f92a3228 | |||
cecde4478d |
57
README.md
Normal file
57
README.md
Normal 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
19
flatcher
Executable 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)
|
31
ucompile
31
ucompile
@ -13,7 +13,7 @@ def check_dependencies() -> None:
|
||||
|
||||
for command in commands:
|
||||
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
|
||||
|
||||
|
||||
@ -100,10 +100,18 @@ def run_input_cases(program, args) -> bool:
|
||||
print("❌")
|
||||
passed = False
|
||||
# green expected output and red program output
|
||||
print(f"{Fore.GREEN}Expected output:{Style.RESET_ALL}")
|
||||
print(expected_output)
|
||||
print(f"{Fore.RED}Program output:{Style.RESET_ALL}")
|
||||
print(program_output.strip())
|
||||
# print(f"{Fore.GREEN}Expected output:{Style.RESET_ALL}")
|
||||
# print(expected_output)
|
||||
# print(f"{Fore.RED}Program output:{Style.RESET_ALL}")
|
||||
# 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:
|
||||
print(
|
||||
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):
|
||||
# Style the code in Meijster's way
|
||||
os.system("astyle -A2s2cxgk3W3xbj " + file_name)
|
||||
os.system(
|
||||
"gcc -Wall -pedantic --std=c99 -g -o program -lm -Wno-unused-result " + file_name
|
||||
)
|
||||
# os.system("astyle -A2s2cxgk3W3xbj " + file_name)
|
||||
# If you want
|
||||
|
||||
# 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)
|
||||
return
|
||||
|
||||
|
6
unifytex
6
unifytex
@ -23,7 +23,11 @@ def dynamic_includes(folder_path):
|
||||
f.write("% Autogenerated by unifytex (git.confest.im/boyan_k/Coding_Tools/)\n")
|
||||
for file in sorted(files):
|
||||
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")
|
||||
|
||||
print(f"Generated {output_file}")
|
||||
|
Reference in New Issue
Block a user