This file contains 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 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 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 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: |
This file contains 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
package com.bnlucas.app.config; | |
import com.codahale.metrics.MetricRegistry; | |
import com.bnlucas.components.ldap.LdapClient; | |
import com.bnlucas.app.config.liquibase.AsyncSpringLiquibase; | |
import com.bnlucas.app.domain.AppAuditorAware; | |
import com.bnlucas.springbootextras.config.Constants; | |
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module; | |
import com.zaxxer.hikari.HikariDataSource; | |
import liquibase.integration.spring.SpringLiquibase; |
This file contains 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 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
-------------------------------------------------------------------------------- | |
BaseHash vs Hashbrown | |
testing instantiation and hashing combined | |
base: 62 | |
length: 171 | |
value: 3154851373153015827738309232812515645550893040441169750950287100081801 | |
7098580981494840912925603132017160147302934098705114421342560722423313 |
This file contains 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 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 time | |
import webbrowser | |
import click | |
from pymouse import PyMouse | |
from pykeyboard import PyKeyboard | |
m = PyMouse() |
This file contains 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, |
NewerOlder