Skip to content

Instantly share code, notes, and snippets.

@mstrongdev
mstrongdev / While_Tests.py
Last active December 25, 2015 11:09
A quick performance test between the "while(True) and break" method of control flow logic and the "while(conditional)" method.
import timeit
def while_var():
count = 1000
while(count > 0):
count -= 1
def while_break():
count = 1000
while(1):
@mstrongdev
mstrongdev / ROType.py
Created January 17, 2014 08:05
A Python metaclass that allows for easy creation of 'public' static 'read-only' properties by storing '_' prefixed members on the metaclass. Inspired by http://stackoverflow.com/q/1735434/1385101
class ROType(type):
def __new__(mcl, classname, bases, classdict):
class UniqueROType (mcl):
pass
def getAttrFromMetaclass(attr):
return lambda cls: getattr(cls.__metaclass__, attr, None)
for attr, value in classdict.items():
if not hasattr(value, '__call__') and attr.startswith('_') and not attr.startswith('__'):