Skip to content

Instantly share code, notes, and snippets.

View arpanetus's full-sized avatar
🐃

Omar Änwar arpanetus

🐃
View GitHub Profile
@arpanetus
arpanetus / rsa.py
Created December 6, 2017 05:45
A simple RSA implementation in Python
'''
620031587
Net-Centric Computing Assignment
Part A - RSA Encryption
'''
import random
'''
@arpanetus
arpanetus / NaiveRSA.py
Created December 6, 2017 05:49 — forked from thomdixon/NaiveRSA.py
Naive implementation of the RSA cryptosystem
import os
import random
class NaiveRSA(object):
_small_primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,
101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,
181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,
271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,
373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,
463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,
import falcon
import logging
logger = logging.getLogger(__name__)
logger.addHandler(logging.FileHandler('test.log'))
logger.setLevel(logging.INFO)
class ResponseLoggerMiddleware(object):
def process_response(self, req, resp):
logger.info('{0} {1} {2}'.format(req.method, req.relative_uri, resp.status[:3]))

I wanted to be able to detect when Dark mode was turned on or off in my Go program so I can swap icons in my tray app on Windows so I wrote this.
When Dark Mode is turned on or off, it writes to a pair of registry keys, both of which Windows allows you to set independently in Settings > Personalization > Colors.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize  

SystemUsesLightTheme  DWORD 0 or 1 // Changes the taskbar and system tray color  
AppsUseLightTheme     DWORD 0 or 1 // Changes app colors  

Mine is a tray app, so I am monitoring the first one. I did not want to just periodically poll the registry key and I wanted to be able to react immediately when the registry key is changed, so I am using the win32 function RegNotifyChangeKeyValue in advapi32.dll to tell the OS to notify my app so I can swap out the icon for a color-appropriate one.
I start the monitor function in main, which loads the RegNotifyChangeKeyValue function from advapi32 and starts a gorouti