Skip to content

Instantly share code, notes, and snippets.

@marhar
marhar / 3columns.py
Created August 15, 2015 06:52
python: using zip to pivot
a=['a1']
b=['b1','b2','b3']
c=['c1','c2']
print zip(a,b,c)
@marhar
marhar / ismulticast.py
Created August 15, 2015 06:58
Python: is this address a multicast address?
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 / gist:d85afa9d30a0f74bd481
Created August 26, 2015 05:08
Python: rotating log file
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 / gist:ca9a15d32aa6673ca6c14f729f4c59fd
Created March 17, 2024 22:04
plotting keras model fitting statistics
# model.fit(img_iter,
# epochs=10,
# steps_per_epoch=len(x_train)/batch_size, # Run same number of steps we would if we were not using a generator.
# validation_data=(x_valid, y_valid))
import matplotlib.pyplot as plt
# Plotting the training loss
plt.plot(model.history.history['loss'], label='Training Loss')