-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
4,207 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import sys | ||
import argparse | ||
import time | ||
import os | ||
|
||
from io import TextIOWrapper | ||
from socket import gaierror, socket, AF_INET, SOCK_STREAM | ||
from pathlib import Path | ||
|
||
|
||
def clear_console() -> None: | ||
match os.name: | ||
case "nt": | ||
os.system("cls") | ||
case _: | ||
os.system("clear") | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument("host", help="the host to connect to") | ||
parser.add_argument( | ||
"-l", "--log", action="store_true", help="write data to log file" | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
clear_console() | ||
|
||
tcp_socket = socket(AF_INET, SOCK_STREAM, 0) | ||
|
||
try: | ||
tcp_socket.connect((args.host, 8000)) | ||
except (ConnectionRefusedError, TimeoutError): | ||
print(f"Failed to connect to {args.host}:8000") | ||
sys.exit(1) | ||
except gaierror: | ||
print(f"Invalid host: {args.host}") | ||
sys.exit(1) | ||
|
||
log_file: TextIOWrapper = None | ||
|
||
if args.log: | ||
Path("logs").mkdir(exist_ok=True) | ||
timestamp = str(int(time.time())) | ||
log_file = open(f"logs/{timestamp}.txt", "w") | ||
|
||
while True: | ||
try: | ||
raw_data = tcp_socket.recv(0x400) | ||
|
||
if not len(raw_data): | ||
break | ||
|
||
data = raw_data.decode("utf-8") | ||
|
||
if args.log: | ||
log_file.write(data) | ||
|
||
print(data, end="") | ||
except ConnectionResetError: | ||
print("Connection reset by peer") | ||
break | ||
except KeyboardInterrupt: | ||
break | ||
|
||
tcp_socket.close() | ||
|
||
if args.log: | ||
log_file.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import argparse | ||
import re | ||
|
||
from pathlib import Path | ||
|
||
|
||
def read_file(file_path) -> Path | None: | ||
try: | ||
return Path(file_path).read_text(encoding="utf-8") | ||
except FileNotFoundError: | ||
print(f"File '{file_path}' not found.") | ||
|
||
return None | ||
|
||
|
||
MATCH_STRING = r"(love\.\w+\.\w+)\(\)\s+==>\s+\w+\s+-\s+(\d+\.\d+)" | ||
TIME_REGEX = re.compile(MATCH_STRING, re.MULTILINE) | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser(description="Read a file.") | ||
parser.add_argument("file", type=str, help="Path to the file") | ||
parser.add_argument( | ||
"--top", "-t", action="store_true", help="Get top 3 slowest methods" | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
content = read_file(args.file) | ||
|
||
if not content: | ||
print("No content found in the file.") | ||
return | ||
|
||
times = re.findall(TIME_REGEX, content) | ||
|
||
if not times: | ||
print("No times found in the file.") | ||
return | ||
|
||
sorted_times = sorted(times, key=lambda x: float(x[1][:-1]), reverse=True) | ||
|
||
if args.top: | ||
for time in sorted_times[:3]: | ||
method, total_time = time | ||
print(f"- {method}: {total_time}s") | ||
|
||
return | ||
|
||
for time in sorted_times: | ||
method, total_time = time | ||
print(f"- {method}: {total_time}s") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.