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 float_spec(fill, align, sign, width, separator, precision): | |
if len(fill) > 1: | |
raise ValueError('The fill character can only contain 1 character.') | |
if align not in ['left', 'right', 'center', 'padded']: | |
raise ValueError('{} is not an allowed alignment.'.format(align)) | |
if sign not in ['+', '-', ' ']: | |
raise ValueError('{} is not a valid sign.'.format(sign)) |
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
chain = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, | |
31, 37, 41, 43, 47, 53, 59, 61, 67, 71, | |
73, 79, 83, 89, 97, 101, 103, 107, 109, 113, | |
127, 131, 137, 139, 149, 151, 157, 163, 167, 173, | |
179, 181, 191, 193, 197, 199, 211, 223, 227, 229, | |
233, 239, 241, 251, 257, 263, 269, 271, 277, 281, | |
283, 293, 307, 311, 313, 317, 331, 337, 347, 349, | |
353, 359, 367, 373, 379, 383, 389, 397, 401, 409, | |
419, 421, 431, 433, 439, 443, 449, 457, 461, 463, | |
467, 479, 487, 491, 499, 503, 509, 521, 523, 541, |
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
''' | |
c:\local\dev>python ghget.py -h | |
usage: ghget.py [-h] -u USER -r REPO [-b BRANCH] [-s SUB] [-p PATH] [-v] | |
GitHub repository downloader. | |
optional arguments: | |
-h, --help show this help message and exit | |
-u USER, --user USER github user (required) | |
-r REPO, --repo REPO github repository (required) |
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
import cProfile | |
from functools import wraps | |
from time import time | |
def benchmark(iterations=10000): | |
def wrapper(function): | |
@wraps(function) | |
def func(*args, **kwargs): |
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 fractions import gcd | |
from random import randrange | |
PRIMES_LE_31 = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31) | |
PRIMONIAL_31 = 200560490130 | |
def invmul(x, mod): | |
if mod <= 0: | |
raise ValueError('Modulus must be greater than zero.') |
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 solovay_strassen(n, k=10): | |
if n == 2: | |
return True | |
if not n & 1: | |
return False | |
def legendre(a, p): | |
if p < 2: | |
raise ValueError('p must not be < 2') | |
if (a == 0) or (a == 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 miller_rabin(n, k=10): | |
if n == 2: | |
return True | |
if not n & 1: | |
return False | |
def check(a, s, d, n): | |
x = pow(a, d, n) | |
if x == 1: | |
return True |
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 fermat(n): | |
if n == 2: | |
return True | |
if not n & 1: | |
return False | |
return pow(2, n-1, n) == 1 | |
# benchmark of 10000 iterations of fermat(100**10-1); Which is not prime. | |
# 10000 calls, 21141 per second. |
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 pyechonest import config | |
from pyechonest.song import Song | |
# Loading Bangarang by Skrillex... | |
song = Song('id:rdio-US:track:t14313937') | |
song = Song('id:spotify-WW:track:6VRhkROS2SZHGlp0pxndbJ') | |
song = Song('TRVOJIZ13A9CFBB670') |
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
When going to /search/artist/<query_string> using the documents below you get: | |
/search/artist/m - this returns both Macklemore and Against Me! | |
/search/artist/a - this returns both Against Me! and AWOLNATION | |
/search/artist/ma - this returns only Macklemore | |
/search/artist/aw - this returns only AWOLNATION | |
/search/artist/me - this returns only Against Me! | |
Adding 'AWOLNATION' to models.Artist produces: |
NewerOlder