Category : dry

I am working on a codebase where many functions expected either an integer or a list of integers as the input. We’d like to support both if possible. This is leading to a lot of duplicated code, and an occasional bug when that code is missing. def get_usernames(userIds:list[int])->pd.DataFrame: if isinstance(userIds, int): userIds=[userIds] … def get_settings(userIds:list[int])->pd.DataFrame: ..

Read more

I created a simple XOR program for fun on python which takes a message and encrypts it against a running key cipher. The code is shown below: #Key sox = bin(int.from_bytes(‘FABRICATING’.encode(), ‘big’)) #Plaintext Message box = bin(int.from_bytes(‘PEACEMAKERS’.encode(), ‘big’)) #XORing if sox[0] == box[0]: dox0 = 0 else: dox0 = 1 if sox[2] == box[2]: dox1 ..

Read more