Skip to content

Instantly share code, notes, and snippets.

View Purrrpley's full-sized avatar

Purrrpley Purrrpley

View GitHub Profile
@Purrrpley
Purrrpley / random_hex.py
Last active August 16, 2022 00:42
Random Hex
import random
def get_random_hex(length):
return hex(random.getrandbits(length*4))[2:].zfill(length)
# >>> print(get_random_hex(8))
# 062e08db
@Purrrpley
Purrrpley / caesar_cipher.py
Last active August 16, 2022 00:43
Encrypt and Decrypt Caesar Ciphers
def cipher(string: str, offset: int) -> str:
result = ''
for char in string:
if 'a' <= char <= 'z':
start, end = 'a', 'z'
elif 'A' <= char <= 'Z':
start, end = 'A', 'Z'
else:
start, end = char, char
@Purrrpley
Purrrpley / assumption_sort.py
Created December 18, 2021 08:56
An O(1) sorting algorithm
def assumption_sort(array):
"""An O(1) sorting algorithm
Sorts in O(1) time. Sorts and returns the input array assuming it is already
sorted - if it is not then output of this function is an implementation
detail and is left undefined.
"""
return array
def despamify(text: str, threshold=5) -> tuple[bool, str]:
last_char = ""
repeat_count = 0
despammed = False
output = ""
for char in text:
if char == last_char:
repeat_count += 1
else: