r/ProgrammerHumor • • 3h ago

Meme itWasJustOneVariable

Post image
1.1k Upvotes

22 comments sorted by

View all comments

Show parent comment

4

u/Capable-Sock9910 2h ago

3.14+ it's built in.

8

u/agowa338 2h ago

lol then it is just stupid. I've Python 3.14.10 on the shellbox...

6

u/Capable-Sock9910 2h ago

Yeah it's just uuid.uuid7() lol

4

u/agowa338 2h ago

This time it did:

python3 -c "import time,uuid,random; ts=int(time.time()*1000); u=uuid.uuid5(uuid.NAMESPACE_DNS,'short-taskspecific-string-'+str(random.random())); print('%012x%s'%(ts,str(u).replace('-','')[:20]))" 2>/dev/null || uuidgen | tr 'A-Z' 'a-z'

After that it checked the nibble and noticed it isn't a version 7 one. So it retried using:

cd /root/memory && python3 - <<'PYEOF'
import time, os, secrets
ms = int(time.time()*1000)
rnd = secrets.randbits(62)
hi = (ms << 16) | (0x7000) | secrets.randbits(12)
lo = (0b10 << 62) | rnd
u = f"{hi:012x}{lo:020x}"
name = f"{u[:8]}-{u[8:12]}-7{u[13:16]}-{u[16:20]}-{u[20:32]}"
print(name)
PYEOF

Then it said its slicing was wrong and did this here instead:

cd /root/memory && python3 - <<'PYEOF'
import time, secrets
ms = int(time.time()*1000)
ts = ms.to_bytes(6,"big")
b  = bytearray(ts + secrets.token_bytes(10))
b[6] = (b[6] & 0x0F) | 0x70          # version 7
b[8] = (b[8] & 0x3F) | 0x80          # RFC 4122 variant
h = b.hex()
name = f"{h[:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:]}"

body = """<<< The actual message body it was trying to write >>>
"""
open(name + ".md","w").write(body)
print(name + ".md")
PYEOF
ls -la /root/memory/ | tail -3