Skip to content

Instantly share code, notes, and snippets.

View Bryant-Yang's full-sized avatar

Yang Bo Bryant-Yang

View GitHub Profile
@oysstu
oysstu / crc16.py
Last active June 12, 2024 13:30
Implementation of crc16 (CRC-16-CCITT) in python
def crc16(data: bytes, poly=0x8408):
'''
CRC-16-CCITT Algorithm
'''
data = bytearray(data)
crc = 0xFFFF
for b in data:
cur_byte = 0xFF & b
for _ in range(0, 8):
if (crc & 0x0001) ^ (cur_byte & 0x0001):
@atupal
atupal / select_input.py
Created June 26, 2013 06:36
Keyboard input with timeout in Python
import sys, select
print "You have ten seconds to answer!"
i, o, e = select.select( [sys.stdin], [], [], 10 )
if (i):
print "You said", sys.stdin.readline().strip()
else:
print "You said nothing!"