Skip to content

Instantly share code, notes, and snippets.

@yashsavani
Last active September 14, 2022 20:51
Show Gist options
  • Save yashsavani/4b93b5b38b31ecdcd4b3d2ae22e71e8c to your computer and use it in GitHub Desktop.
Save yashsavani/4b93b5b38b31ecdcd4b3d2ae22e71e8c to your computer and use it in GitHub Desktop.
Useful code snippets for everyday life
# Code to test myself on powers of 2 from 2^1 to 2^11
# 2^[0-3,10] (easy), 2^4 = 4^2 = 16, 2^5 = 32 (3+2=5), 2^6 = 64 ("6"4), 2^7 = 128 (8-1=7), 2^8 = 256 (2+6=8), 2^9 = 2^(10-1) = 512
[("-"*20).join((lambda x: (f"{x:3d}",str(1<<x)))(random.randint(1,11))) for _ in range(100)]
# Code to test myself on hex and binary for nibbles
# 0-4,7,8 (easy), 5 = 0b101 (10>>1), 6 = 0b110 (4+2), 9 = 0b1001 (8+1), 10 = 0xa (characters look similar), 11 = 0xb (stem of b char),
# 12 = 0xc (the hook of the 2 is similar to c) = 0b1100 (8+4), 13 = 0xd (three somewhat = dee) = 0x1101 (01 similar to d),
# 14 = 0xe (four + e = free) = 0b1110 = (0xf-0x1), 15 = 0xf ("F"ive) = 0b1111
[(lambda x: f"{x:>3d}"+"-"*20+hex(x)+"-"*20+bin(x))(random.randint(1,15)) for _ in range(100)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment