Last active
July 28, 2021 08:04
-
-
Save Mic92/2e7c31fbce1e08bdf5d34b2eec83ae3f to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import pdb | |
import os | |
from tempfile import TemporaryDirectory | |
def format_bytes(size): | |
# 2**10 = 1024 | |
power = 2 ** 10 | |
n = 0 | |
unit = {0: "", 1: "KB", 2: "MB", 3: "GB", 4: "TB", 5: "PT"} | |
while size > power: | |
size /= power | |
n += 1 | |
return f"{size:0.1f} {unit[n]}" | |
def inspect_num(n: int): | |
print(f"hex {hex(n)}") | |
print(f"bin {bin(n)}") | |
print(f"dec {n}") | |
print(f"oct {oct(n)}") | |
print(f"unit {format_bytes(n)}") | |
def i(n: int): | |
return inspect_num(n) | |
with TemporaryDirectory() as d: | |
os.chdir(d) | |
with open(".pdbrc", "w") as f: | |
f.write("alias i inspect_num(%1)\n") | |
breakpoint() | |
"bincalc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment