Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Harrison marhar

View GitHub Profile
@marhar
marhar / gist:d85afa9d30a0f74bd481
Created Aug 26, 2015
Python: rotating log file
View gist:d85afa9d30a0f74bd481
import logging
import logging.handlers
logf = logging.getLogger('MyLogger')
logf.setLevel(logging.INFO)
handler = logging.handlers.RotatingFileHandler(
'logfile.txt', maxBytes=100*1000*1000, backupCount=5)
logf.addHandler(handler)
logf.info('this is a log message')
@marhar
marhar / ismulticast.py
Created Aug 15, 2015
Python: is this address a multicast address?
View ismulticast.py
def ismulticast(hostname):
"""is this address a multicast address?"""
# -- yes if bits 0-3 are 1110
import socket
import struct
ip=socket.gethostbyname(hostname)
mreq=struct.pack("4sl",socket.inet_aton(ip),socket.INADDR_ANY)
return ord(mreq[0]) & 0xf0 == 0xe0
@marhar
marhar / 3columns.py
Created Aug 15, 2015
python: using zip to pivot
View 3columns.py
a=['a1']
b=['b1','b2','b3']
c=['c1','c2']
print zip(a,b,c)