Skip to content

Instantly share code, notes, and snippets.

@Synthetica9
Created April 3, 2015 05:33
Show Gist options
  • Save Synthetica9/f94ff9c42e007fe6f24f to your computer and use it in GitHub Desktop.
Save Synthetica9/f94ff9c42e007fe6f24f to your computer and use it in GitHub Desktop.
Dependency of the old version
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <[email protected]> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return. Synthetica
# ----------------------------------------------------------------------------
import operator
__author__ = 'patrick'
DEBUG = False
def chunks(l, n):
#http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python
if n < 1:
n = 1
return [l[i:i + n] for i in range(0, len(l), n)]
def product(*items):
if items:
return reduce(operator.mul, items)
else:
return 1
def flag(*args, **kwargs):
if DEBUG:
if (not args) and (not kwargs):
print '[D] Flag raised!'
for i in args:
print '[D]', i
for i in kwargs:
print '[D]', i, ':', kwargs[i]
return True #TODO: Put all flag calls in assert statements
def profile(command, repeats=None):
import cProfile
if repeats is None:
print command
cProfile.run(command)
else:
query = 'for i in range({r}): {c}'.format(r=repeats, c=command)
print query
cProfile.run('for i in range({r}): {c}'.format(r=repeats, c=command))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment