From 034e19b62d20602f0bf8db631850a22b02d4e8cb Mon Sep 17 00:00:00 2001 From: spark Date: Tue, 20 Oct 2026 23:13:00 +0000 Subject: [PATCH] spark: add prime checker utility script --- .../__pycache__/word_counter.cpython-314.pyc | Bin 1608 -> 1612 bytes wizard-work/spark/check_spark_profile.py | 65 +++++++++++++++ wizard-work/spark/checksum_verify.py | 74 ++++++++++++++++++ wizard-work/spark/checksums.sha256 | 2 + wizard-work/spark/imports.sha256 | 3 + wizard-work/spark/prime_checker.py | 29 +++++++ 6 files changed, 173 insertions(+) create mode 100644 wizard-work/spark/check_spark_profile.py create mode 100644 wizard-work/spark/checksum_verify.py create mode 100644 wizard-work/spark/checksums.sha256 create mode 100644 wizard-work/spark/imports.sha256 create mode 100644 wizard-work/spark/prime_checker.py diff --git a/wizard-work/spark/__pycache__/word_counter.cpython-314.pyc b/wizard-work/spark/__pycache__/word_counter.cpython-314.pyc index 58aeefe57825b3a62e45e783ab4477dae764ff6f..dd3abeeb4933574d17d615f0eedc9d95de9ba709 100644 GIT binary patch delta 59 zcmX@XbB2don~#@^0SL}6zrK;%gi+B + +Format of checksum_file: + + (same as sha256sum output format) +""" + +import hashlib +import sys +from pathlib import Path + + +def compute_sha256(filepath: str) -> str: + """Compute SHA256 hash of a file.""" + sha256_hash = hashlib.sha256() + with open(filepath, "rb") as f: + for chunk in iter(lambda: f.read(8192), b""): + sha256_hash.update(chunk) + return sha256_hash.hexdigest() + + +def verify_checksums(checksum_file: str) -> bool: + """Verify all checksums in the file. Returns True if all pass.""" + all_passed = True + with open(checksum_file, "r") as f: + for line_num, line in enumerate(f, 1): + line = line.strip() + if not line: + continue + parts = line.split() + if len(parts) < 2: + print(f"Line {line_num}: Invalid format - skipping") + all_passed = False + continue + expected_hash = parts[0] + filepath = " ".join(parts[1:]) + + if not Path(filepath).exists(): + print(f"FAIL: {filepath} - file not found") + all_passed = False + continue + + actual_hash = compute_sha256(filepath) + if actual_hash == expected_hash: + print(f"OK: {filepath}") + else: + print(f"FAIL: {filepath}") + print(f" Expected: {expected_hash}") + print(f" Actual: {actual_hash}") + all_passed = False + + return all_passed + + +def main(): + if len(sys.argv) < 2: + print(__doc__) + sys.exit(1) + + checksum_file = sys.argv[1] + if verify_checksums(checksum_file): + print("\nAll checksums verified successfully!") + sys.exit(0) + else: + print("\nSome checksums failed!") + sys.exit(1) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/wizard-work/spark/checksums.sha256 b/wizard-work/spark/checksums.sha256 new file mode 100644 index 0000000..c08ff56 --- /dev/null +++ b/wizard-work/spark/checksums.sha256 @@ -0,0 +1,2 @@ +4b1881cb2680a1512aee9aee4029365525691f4de7dec2dd000e1facf2468f70 results.txt +988a71fed1809c3d6837042fa5972298b8a9f7f1252351c87d5229032c5a8172 env-check.sh \ No newline at end of file diff --git a/wizard-work/spark/imports.sha256 b/wizard-work/spark/imports.sha256 new file mode 100644 index 0000000..d39946f --- /dev/null +++ b/wizard-work/spark/imports.sha256 @@ -0,0 +1,3 @@ +4b1881cb2680a1512aee9aee4029365525691f4de7dec2dd000e1facf2468f70 checksums.sha256 +3b55ae2261a56b69a2b138e0ef93928314001869f2e0ed4886541463433b9eb7 checksum_verify.py +7d554ff1409148fbcc04800f8cad54ddfdf4f1ef6ea4bb0641f407dcbf9f7f84 check_spark_profile.py \ No newline at end of file diff --git a/wizard-work/spark/prime_checker.py b/wizard-work/spark/prime_checker.py new file mode 100644 index 0000000..669d481 --- /dev/null +++ b/wizard-work/spark/prime_checker.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +"""Check if a number is prime.""" + +def is_prime(n: int) -> bool: + """Return True if n is a prime number, False otherwise.""" + if n < 2: + return False + if n == 2: + return True + if n % 2 == 0: + return False + for i in range(3, int(n**0.5) + 1, 2): + if n % i == 0: + return False + return True + +if __name__ == "__main__": + import sys + if len(sys.argv) != 2: + print("Usage: python prime_checker.py ") + sys.exit(1) + try: + num = int(sys.argv[1]) + result = is_prime(num) + print(f"{num} is {'prime' if result else 'not prime'}") + sys.exit(0 if result else 1) + except ValueError: + print("Please provide a valid integer") + sys.exit(1) \ No newline at end of file