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
# DontShakeMe - Andrea Grandi (2016) | |
# License: MIT | |
from microbit import display, Image, accelerometer, sleep | |
# display an happy face by default | |
display.show(Image.HAPPY) | |
# if you shake the device, you make microbit sad | |
while 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
import microbit as m | |
SUN_IMAGE = m.Image( | |
"90909\n" | |
"09990\n" | |
"99999\n" | |
"09990\n" | |
"90909") | |
MOON_IMAGE = m.Image( | |
"99900\n" |
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 microbit as m | |
SENSITIVITY = 250 | |
while (True): | |
x = m.accelerometer.get_x() | |
if abs(x) < SENSITIVITY: | |
m.display.show(m.Image.HAPPY) | |
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
server { | |
listen 80 default_server; | |
listen [::]:80 default_server ipv6only=on; | |
server_name andreagrandi.it www.andreagrandi.it; | |
# Redirect all requests to HTTPS. | |
return 301 https://$host$request_uri; | |
} |
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
# Define a lambda function that takes a number and double it | |
d = lambda x: x * 2 | |
# Create a list containing: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
l1 = [x for x in xrange(10)] | |
# Method #1 using map(...) | |
# output: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] | |
print map(d, l1) |
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
2kpeople.co.uk | |
3aaa.co.uk | |
24-7recruitment.net | |
199rec.co.uk | |
365rec.com | |
aatomrecruitment.com | |
abrs.com | |
agendarecruitment.co.uk | |
andiamo-group.com | |
applauseit.co.uk |
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 memoize(function): | |
cache = {} | |
def decorated_function(*args): | |
if args in cache: | |
return cache[args] | |
else: | |
val = function(*args) | |
cache[args] = val | |
return val | |
return decorated_function |
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 is_list_circular(l): | |
slower = l | |
faster = l.get_next() | |
while True: | |
# if faster pointer finds a None element | |
# then the list is not circular | |
if (faster is None) or (faster.get_next() is None): | |
return False | |
# if faster element catch up with the slower |
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
n = 'MCMXCVII' # 1997 | |
def roman_to_decimal(n): | |
roman_map = {'M': 1000, 'D': 500, 'C': 100, 'L': 50, 'X': 10, 'V': 5, 'I': 1} | |
result = 0 | |
for i,c in enumerate(n): | |
num = roman_map[c] | |
if result == 0: |