comsci-tools 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: comsci-tools
3
+ Version: 0.1.0
4
+ Summary: A comprehensive utility toolkit for Computer Science students and developers.
5
+ Author: Chatchai Naktae
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+
9
+ # comsci-tools
10
+
11
+ A comprehensive utility toolkit designed to make the lives of Computer Science students and developers easier. Whether you are calculating GPA, converting number bases for Digital Logic class, or generating secure passwords, this package has you covered!
12
+
13
+ ## Installation
14
+
15
+ You can easily install this package via pip:
16
+
17
+ ```bash
18
+ pip install comsci-tools
19
+ ```
20
+
21
+ ## Quick Start & Examples
22
+
23
+ Here are some real-world examples of how to use the modules included in this package:
24
+
25
+ ### 1. Base Converter (Digital Logic & Architecture)
26
+ Perfect for computer science math and architecture calculations.
27
+
28
+ ```python
29
+ from comsci_tools import dec_to_bin, dec_to_hex
30
+
31
+ print(dec_to_bin(255)) # Output: 11111111
32
+ print(dec_to_hex(255)) # Output: FF
33
+ ```
34
+
35
+ ### 2. Academic Tools
36
+ Easily calculate your exact GPA using standard university formats.
37
+
38
+ ```python
39
+ from comsci_tools import gpa_calculator
40
+
41
+ # Format: [(Grade Point, Credits), ...]
42
+ my_grades = [
43
+ (4.0, 3), # Programming (A)
44
+ (3.5, 3), # Mathematics (B+)
45
+ (3.0, 3) # English (B)
46
+ ]
47
+ print(f"My GPA is: {gpa_calculator(my_grades)}")
48
+ # Output: My GPA is: 3.5
49
+ ```
50
+
51
+ ### 3. Web Development Tools (HTML/CSS)
52
+ Quickly convert RGB colors to HEX codes for web design.
53
+
54
+ ```python
55
+ from comsci_tools import rgb_to_hex
56
+
57
+ color = rgb_to_hex(255, 99, 71)
58
+ print(f"Tomato color hex: {color}")
59
+ # Output: Tomato color hex: #FF6347
60
+ ```
61
+
62
+ ### 4. Cryptography & Security
63
+ Generate secure passwords or use basic encryption.
64
+
65
+ ```python
66
+ from comsci_tools import generate_password, hash_md5
67
+
68
+ # Generate a 16-character secure password
69
+ print(generate_password(16))
70
+
71
+ # Hash a string using MD5
72
+ print(hash_md5("my_secret_data"))
73
+ ```
74
+
75
+ ## Available Modules Included
76
+ This package contains 10 powerful modules:
77
+ 1. `logic`: Base conversions (Bin, Oct, Hex)
78
+ 2. `academic`: Grading and GPA calculations
79
+ 3. `crypto`: Hashing and basic encryption
80
+ 4. `storage`: Byte conversions and download time estimation
81
+ 5. `color`: RGB and HEX color tools
82
+ 6. `randomizer`: Password generators and coin flips
83
+ 7. `time_utils`: Timestamps and formatting
84
+ 8. `network`: Local IP fetching
85
+ 9. `file_ops`: File extension extraction
86
+ 10. `utils`: Cross-platform console clearing
@@ -0,0 +1,78 @@
1
+ # comsci-tools
2
+
3
+ A comprehensive utility toolkit designed to make the lives of Computer Science students and developers easier. Whether you are calculating GPA, converting number bases for Digital Logic class, or generating secure passwords, this package has you covered!
4
+
5
+ ## Installation
6
+
7
+ You can easily install this package via pip:
8
+
9
+ ```bash
10
+ pip install comsci-tools
11
+ ```
12
+
13
+ ## Quick Start & Examples
14
+
15
+ Here are some real-world examples of how to use the modules included in this package:
16
+
17
+ ### 1. Base Converter (Digital Logic & Architecture)
18
+ Perfect for computer science math and architecture calculations.
19
+
20
+ ```python
21
+ from comsci_tools import dec_to_bin, dec_to_hex
22
+
23
+ print(dec_to_bin(255)) # Output: 11111111
24
+ print(dec_to_hex(255)) # Output: FF
25
+ ```
26
+
27
+ ### 2. Academic Tools
28
+ Easily calculate your exact GPA using standard university formats.
29
+
30
+ ```python
31
+ from comsci_tools import gpa_calculator
32
+
33
+ # Format: [(Grade Point, Credits), ...]
34
+ my_grades = [
35
+ (4.0, 3), # Programming (A)
36
+ (3.5, 3), # Mathematics (B+)
37
+ (3.0, 3) # English (B)
38
+ ]
39
+ print(f"My GPA is: {gpa_calculator(my_grades)}")
40
+ # Output: My GPA is: 3.5
41
+ ```
42
+
43
+ ### 3. Web Development Tools (HTML/CSS)
44
+ Quickly convert RGB colors to HEX codes for web design.
45
+
46
+ ```python
47
+ from comsci_tools import rgb_to_hex
48
+
49
+ color = rgb_to_hex(255, 99, 71)
50
+ print(f"Tomato color hex: {color}")
51
+ # Output: Tomato color hex: #FF6347
52
+ ```
53
+
54
+ ### 4. Cryptography & Security
55
+ Generate secure passwords or use basic encryption.
56
+
57
+ ```python
58
+ from comsci_tools import generate_password, hash_md5
59
+
60
+ # Generate a 16-character secure password
61
+ print(generate_password(16))
62
+
63
+ # Hash a string using MD5
64
+ print(hash_md5("my_secret_data"))
65
+ ```
66
+
67
+ ## Available Modules Included
68
+ This package contains 10 powerful modules:
69
+ 1. `logic`: Base conversions (Bin, Oct, Hex)
70
+ 2. `academic`: Grading and GPA calculations
71
+ 3. `crypto`: Hashing and basic encryption
72
+ 4. `storage`: Byte conversions and download time estimation
73
+ 5. `color`: RGB and HEX color tools
74
+ 6. `randomizer`: Password generators and coin flips
75
+ 7. `time_utils`: Timestamps and formatting
76
+ 8. `network`: Local IP fetching
77
+ 9. `file_ops`: File extension extraction
78
+ 10. `utils`: Cross-platform console clearing
@@ -0,0 +1,16 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "comsci-tools"
7
+ version = "0.1.0"
8
+ authors = [
9
+ { name="Chatchai Naktae" },
10
+ ]
11
+ description = "A comprehensive utility toolkit for Computer Science students and developers."
12
+ readme = "README.md"
13
+ requires-python = ">=3.8"
14
+
15
+ [tool.setuptools.packages.find]
16
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,31 @@
1
+ # 1. Logic & Math
2
+ from .logic import dec_to_bin, dec_to_hex, base_converter
3
+
4
+ # 2. Academic tools
5
+ from .academic import calculate_grade, gpa_calculator
6
+
7
+ # 3. Utilities
8
+ from .utils import clear_console
9
+
10
+ # 4. Cryptography
11
+ from .crypto import encrypt_caesar, hash_md5
12
+
13
+ # 5. Storage
14
+ from .storage import convert_bytes, calculate_download_time
15
+
16
+ # 6. Color (Web/UI)
17
+ from .color import rgb_to_hex, hex_to_rgb
18
+
19
+ # 7. Randomizer
20
+ from .randomizer import generate_password, coin_flip
21
+
22
+ # 8. Time Utils
23
+ from .time_utils import get_current_timestamp, format_seconds
24
+
25
+ # 9. Network
26
+ from .network import get_local_ip
27
+
28
+ # 10. File Operations
29
+ from .file_ops import get_file_extension
30
+
31
+ __version__ = "0.1.0"
@@ -0,0 +1,20 @@
1
+ def calculate_grade(score: float) -> str:
2
+ """Standard Thai University grading system."""
3
+ if score >= 80: return "A"
4
+ if score >= 75: return "B+"
5
+ if score >= 70: return "B"
6
+ if score >= 65: return "C+"
7
+ if score >= 60: return "C"
8
+ if score >= 55: return "D+"
9
+ if score >= 50: return "D"
10
+ return "F"
11
+
12
+ def gpa_calculator(grades_with_credits: list) -> float:
13
+ """
14
+ Calculate GPA.
15
+ Input: [(grade_point, credit), (grade_point, credit)]
16
+ Example: [(4.0, 3), (3.5, 3)]
17
+ """
18
+ total_points = sum(g * c for g, c in grades_with_credits)
19
+ total_credits = sum(c for g, c in grades_with_credits)
20
+ return round(total_points / total_credits, 2)
@@ -0,0 +1,14 @@
1
+ def rgb_to_hex(r: int, g: int, b: int) -> str:
2
+ """Convert RGB values to a HEX color code."""
3
+ # Ensure values are within 0-255 range
4
+ r = max(0, min(255, r))
5
+ g = max(0, min(255, g))
6
+ b = max(0, min(255, b))
7
+ return f"#{r:02X}{g:02X}{b:02X}"
8
+
9
+ def hex_to_rgb(hex_code: str) -> tuple:
10
+ """Convert HEX color code to RGB tuple."""
11
+ hex_code = hex_code.lstrip('#')
12
+ if len(hex_code) != 6:
13
+ raise ValueError("HEX code must be 6 characters long")
14
+ return tuple(int(hex_code[i:i+2], 16) for i in (0, 2, 4))
@@ -0,0 +1,19 @@
1
+ import hashlib
2
+
3
+ def encrypt_caesar(text: str, shift: int) -> str:
4
+ """Encrypt text using basic Caesar Cipher."""
5
+ result = ""
6
+ for char in text:
7
+ if char.isalpha():
8
+ # Check if uppercase or lowercase
9
+ ascii_offset = 65 if char.isupper() else 97
10
+ # Shift character and wrap around alphabet
11
+ result += chr((ord(char) - ascii_offset + shift) % 26 + ascii_offset)
12
+ else:
13
+ result += char
14
+ return result
15
+
16
+ def hash_md5(text: str) -> str:
17
+ """Convert string text to an MD5 hash string."""
18
+ # Encode text to bytes, then hash, then return as hex string
19
+ return hashlib.md5(text.encode()).hexdigest()
@@ -0,0 +1,6 @@
1
+ import os
2
+
3
+ def get_file_extension(filename: str) -> str:
4
+ """Extract the extension from a filename (e.g., '.txt')."""
5
+ _, extension = os.path.splitext(filename)
6
+ return extension.lower()
@@ -0,0 +1,17 @@
1
+ def dec_to_bin(number: int) -> str:
2
+ """Convert decimal to binary string."""
3
+ return bin(number).replace("0b", "")
4
+
5
+ def dec_to_hex(number: int) -> str:
6
+ """Convert decimal to uppercase hexadecimal string."""
7
+ return hex(number).replace("0x", "").upper()
8
+
9
+ def base_converter(number_str: str, from_base: int, to_base: int) -> str:
10
+ """Convert any base to any base (Basic version)."""
11
+ # Step 1: Convert input to decimal
12
+ decimal_num = int(number_str, from_base)
13
+ # Step 2: Convert decimal to target base
14
+ if to_base == 2: return bin(decimal_num).replace("0b", "")
15
+ if to_base == 8: return oct(decimal_num).replace("0o", "")
16
+ if to_base == 16: return hex(decimal_num).replace("0x", "").upper()
17
+ return str(decimal_num)
@@ -0,0 +1,13 @@
1
+ import socket
2
+
3
+ def get_local_ip() -> str:
4
+ """Get the local IP address of the current machine."""
5
+ try:
6
+ # Create a dummy socket to find the local IP
7
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
8
+ s.connect(("8.8.8.8", 80))
9
+ ip = s.getsockname()[0]
10
+ s.close()
11
+ return ip
12
+ except Exception:
13
+ return "127.0.0.1"
@@ -0,0 +1,15 @@
1
+ import random
2
+ import string
3
+
4
+ def generate_password(length: int = 12) -> str:
5
+ """Generate a secure random password."""
6
+ if length < 4:
7
+ raise ValueError("Password length must be at least 4")
8
+
9
+ characters = string.ascii_letters + string.digits + string.punctuation
10
+ # Ensure at least one of each type is theoretically possible
11
+ return ''.join(random.choice(characters) for _ in range(length))
12
+
13
+ def coin_flip() -> str:
14
+ """Simulate a 50/50 coin flip."""
15
+ return random.choice(["Heads", "Tails"])
@@ -0,0 +1,18 @@
1
+ def convert_bytes(size_in_bytes: float) -> str:
2
+ """Convert raw bytes to human-readable format (KB, MB, GB, TB)."""
3
+ for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
4
+ if size_in_bytes < 1024.0:
5
+ return f"{round(size_in_bytes, 2)} {unit}"
6
+ # Divide by exact 1024 for computer science standard
7
+ size_in_bytes /= 1024.0
8
+ return f"{round(size_in_bytes, 2)} PB"
9
+
10
+ def calculate_download_time(file_size_mb: float, speed_mbps: float) -> float:
11
+ """
12
+ Calculate exact download time in seconds.
13
+ Note: Internet speed is in Megabits (Mb), File size is in Megabytes (MB).
14
+ """
15
+ # 1 Byte = 8 bits, so we divide speed by 8 to match MB
16
+ speed_mb_per_sec = speed_mbps / 8.0
17
+ time_seconds = file_size_mb / speed_mb_per_sec
18
+ return round(time_seconds, 2)
@@ -0,0 +1,12 @@
1
+ import time
2
+
3
+ def get_current_timestamp() -> int:
4
+ """Get the current Unix timestamp in seconds."""
5
+ return int(time.time())
6
+
7
+ def format_seconds(seconds: int) -> str:
8
+ """Convert raw seconds into HH:MM:SS format."""
9
+ hours = seconds // 3600
10
+ minutes = (seconds % 3600) // 60
11
+ secs = seconds % 60
12
+ return f"{hours:02d}:{minutes:02d}:{secs:02d}"
@@ -0,0 +1,9 @@
1
+ import os
2
+ import platform
3
+
4
+ def clear_console():
5
+ """Clears the terminal screen regardless of OS."""
6
+ if platform.system() == "Windows":
7
+ os.system("cls")
8
+ else:
9
+ os.system("clear")
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: comsci-tools
3
+ Version: 0.1.0
4
+ Summary: A comprehensive utility toolkit for Computer Science students and developers.
5
+ Author: Chatchai Naktae
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+
9
+ # comsci-tools
10
+
11
+ A comprehensive utility toolkit designed to make the lives of Computer Science students and developers easier. Whether you are calculating GPA, converting number bases for Digital Logic class, or generating secure passwords, this package has you covered!
12
+
13
+ ## Installation
14
+
15
+ You can easily install this package via pip:
16
+
17
+ ```bash
18
+ pip install comsci-tools
19
+ ```
20
+
21
+ ## Quick Start & Examples
22
+
23
+ Here are some real-world examples of how to use the modules included in this package:
24
+
25
+ ### 1. Base Converter (Digital Logic & Architecture)
26
+ Perfect for computer science math and architecture calculations.
27
+
28
+ ```python
29
+ from comsci_tools import dec_to_bin, dec_to_hex
30
+
31
+ print(dec_to_bin(255)) # Output: 11111111
32
+ print(dec_to_hex(255)) # Output: FF
33
+ ```
34
+
35
+ ### 2. Academic Tools
36
+ Easily calculate your exact GPA using standard university formats.
37
+
38
+ ```python
39
+ from comsci_tools import gpa_calculator
40
+
41
+ # Format: [(Grade Point, Credits), ...]
42
+ my_grades = [
43
+ (4.0, 3), # Programming (A)
44
+ (3.5, 3), # Mathematics (B+)
45
+ (3.0, 3) # English (B)
46
+ ]
47
+ print(f"My GPA is: {gpa_calculator(my_grades)}")
48
+ # Output: My GPA is: 3.5
49
+ ```
50
+
51
+ ### 3. Web Development Tools (HTML/CSS)
52
+ Quickly convert RGB colors to HEX codes for web design.
53
+
54
+ ```python
55
+ from comsci_tools import rgb_to_hex
56
+
57
+ color = rgb_to_hex(255, 99, 71)
58
+ print(f"Tomato color hex: {color}")
59
+ # Output: Tomato color hex: #FF6347
60
+ ```
61
+
62
+ ### 4. Cryptography & Security
63
+ Generate secure passwords or use basic encryption.
64
+
65
+ ```python
66
+ from comsci_tools import generate_password, hash_md5
67
+
68
+ # Generate a 16-character secure password
69
+ print(generate_password(16))
70
+
71
+ # Hash a string using MD5
72
+ print(hash_md5("my_secret_data"))
73
+ ```
74
+
75
+ ## Available Modules Included
76
+ This package contains 10 powerful modules:
77
+ 1. `logic`: Base conversions (Bin, Oct, Hex)
78
+ 2. `academic`: Grading and GPA calculations
79
+ 3. `crypto`: Hashing and basic encryption
80
+ 4. `storage`: Byte conversions and download time estimation
81
+ 5. `color`: RGB and HEX color tools
82
+ 6. `randomizer`: Password generators and coin flips
83
+ 7. `time_utils`: Timestamps and formatting
84
+ 8. `network`: Local IP fetching
85
+ 9. `file_ops`: File extension extraction
86
+ 10. `utils`: Cross-platform console clearing
@@ -0,0 +1,18 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/comsci_tools/__init__.py
4
+ src/comsci_tools/academic.py
5
+ src/comsci_tools/color.py
6
+ src/comsci_tools/crypto.py
7
+ src/comsci_tools/file_ops.py
8
+ src/comsci_tools/logic.py
9
+ src/comsci_tools/network.py
10
+ src/comsci_tools/randomizer.py
11
+ src/comsci_tools/storage.py
12
+ src/comsci_tools/time_utils.py
13
+ src/comsci_tools/utils.py
14
+ src/comsci_tools.egg-info/PKG-INFO
15
+ src/comsci_tools.egg-info/SOURCES.txt
16
+ src/comsci_tools.egg-info/dependency_links.txt
17
+ src/comsci_tools.egg-info/top_level.txt
18
+ tests/test_main.py
@@ -0,0 +1 @@
1
+ comsci_tools
@@ -0,0 +1,36 @@
1
+ import comsci_tools as tools
2
+
3
+ print("=== ComSci Tools Test Run ===")
4
+
5
+ # 1. Test Base Converter (Digital Logic)
6
+ decimal_number = 255
7
+ binary_result = tools.dec_to_bin(decimal_number)
8
+ hex_result = tools.dec_to_hex(decimal_number)
9
+ print(f"\n[1] Logic Test: {decimal_number} in Binary is {binary_result}, in Hex is {hex_result}")
10
+
11
+ # 2. Test GPA Calculator (Academic)
12
+ # Format: [(Grade Point, Credits)]
13
+ my_grades = [
14
+ (4.0, 3), # Programming (A)
15
+ (3.5, 3), # Mathematics (B+)
16
+ (3.0, 3) # English (B)
17
+ ]
18
+ gpa = tools.gpa_calculator(my_grades)
19
+ print(f"\n[2] Academic Test: My calculated GPA is {gpa}")
20
+
21
+ # 3. Test RGB to HEX Converter (Web Development)
22
+ r, g, b = 255, 99, 71
23
+ hex_color = tools.rgb_to_hex(r, g, b)
24
+ print(f"\n[3] Color Test: RGB({r}, {g}, {b}) is HEX {hex_color}")
25
+
26
+ # 4. Test Password Generator (Security)
27
+ secure_pass = tools.generate_password(16)
28
+ print(f"\n[4] Security Test: Generated 16-char Password -> {secure_pass}")
29
+
30
+ # 5. Test Download Time Calculator (Storage & Network)
31
+ file_size = 1024.0 # 1024 MB (1 GB)
32
+ internet_speed = 500.0 # 500 Mbps
33
+ download_time = tools.calculate_download_time(file_size, internet_speed)
34
+ print(f"\n[5] Network Test: Time to download {file_size}MB at {internet_speed}Mbps is {download_time} seconds")
35
+
36
+ print("\n=============================")