Skip to content

Instantly share code, notes, and snippets.

View juusimaa's full-sized avatar

Jouni Uusimaa juusimaa

View GitHub Profile
@juusimaa
juusimaa / CalculateMd5
Created June 23, 2013 19:34
Python (3.x) function to calculate MD5 checksum for given file.
def calculateMD5(filename, block_size=2**20):
"""Returns MD% checksum for given file.
"""
import hashlib
md5 = hashlib.md5()
try:
file = open(filename, 'rb')
while True:
data = file.read(block_size)
@juusimaa
juusimaa / DeepClone
Created June 24, 2013 05:57
Extension method for deep cloning serializable objects.
public static T DeepClone<T>(this T a)
{
using (var stream = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(stream, a);
stream.Position = 0;
return (T)formatter.Deserialize(stream);
}
}