Skip to content

Instantly share code, notes, and snippets.

@lordsutch
lordsutch / test_bitmask.py
Created July 25, 2019 16:57
Bitmask testing routine for Python 3.6+
# Copyright (C) 2019 Chris Lawrence
# You may freely modify, copy, and reuse this software under the terms of the MIT License.
def test_bitmask(value: int, mask: str) -> bool:
mask = mask.replace("_", "")
testval: int = 1
for bit in reversed(mask):
if bit == '1' and not (value & testval):
return False
elif bit == '0' and (value & testval):
@lordsutch
lordsutch / randcaps.py
Created April 6, 2022 23:53
Randomly capitalize some text so you can be l33t on social media
#!/usr/bin/env python3
import argparse
import random
import sys
DEFAULT_PERCENTAGE = 40
def randcaps(text: str, percentage: float = DEFAULT_PERCENTAGE) -> str: