onsdag 19 december 2012

Python is_prime using Miller-Rabin

from random import randrange

def is_prime(n, trials=6):
    """ Miller-Rabin probabilistic prime test.
    if n < 2:
        return False
    i = 0
    while i < trials:
        a = randrange(1, n)
        if pow(a, n-1, n) != 1: # (a**(n-1)) % n
            return False
    return True

# or as a tiny-font-one-liner

def is_prime(n, trials=6):
    return n >= 2 and (trials == 0 or (pow(randrange(1, n), n-1, n) == 1 and is_prime(n, trials - 1)))

onsdag 12 december 2012

uboot pogoplug netconsole

I used this tip to set up my pogoplug to send the uBoot prompt
via udp to my laptop
(see: Use netconsole to troubleshoot uBoot without a serial cable

Now, to get the boot prompt from pogoplug ( to my laptop (
I do (on my laptop)

ifconfig en0 alias

to set an ip alias (remove with -alias), and then

nc -lu 6666 & nc -u 6666

to communicate with the pogoplug.