This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from operator import mul | |
def euler8(digits, n=4): | |
i = 0 | |
_max = 0 | |
while i <= len(digits)-n: | |
_r = reduce(mul, [int(x) for x in digits[i:i+n]]) | |
if _r > _max: | |
_max = _r | |
i += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def genprimes(upto): | |
primes = {} | |
q = 2 | |
i = 0 | |
while i < upto: | |
if q not in primes: | |
yield q | |
i += 1 | |
primes[q*q] = [q] | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def retry_task(name, max_retries=3, ignore_result=True, queue="celery", countdown=10, exceptions=[]): | |
""" | |
This decorator allows you to retry a celery task if it raised an exception of type defined in <exceptions>. | |
Tasks are also wrapped by a commit_on_success decorator to avoid incomplete data in the database. | |
arguments are : | |
name: The name of the task | |
max_retries: The number of retries before giving up [default: 3] | |
ignore_result: Should celery ignores the result [default: True] | |
queue: The queue name [default: "celery"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function randomRange(lowerBound, upperBound){ | |
return lowerBound + Math.random() * (upperBound-lowerBound); | |
} | |
function draw() { | |
var canvas = document.getElementById("canvas"); | |
var c = canvas.getContext("2d"); | |
function drawBranch(l, direction) { | |
c.save(); | |
c.fillRect(-1, 0, 2, -l); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NullProxy(object): | |
"""Pretend you have a model object with three attributes: | |
class Person(object): | |
name = String(40) | |
age = Integer() | |
email = Email() | |
And have a sub-class adding extra attributes: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str = 'a string' | |
binary_representation = ''.join([bin(ord(c))[2:].zfill(8) for c in str]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str = '01001000011000010111000001110000011110010010000001001110011001010111011100100000010110010110010101100001011100100111001100100001' | |
print ''.join([chr(int(str[i:i+8],2)) for i in range(len(str)) if i % 8 ==0]) |