Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home... permanently!

Andrea Grandi andreagrandi

🏠
Working from home... permanently!
View GitHub Profile
@andreagrandi
andreagrandi / make_me_happy_microbit.py
Created Mar 13, 2016
Make microbit happy pressing button A or make it die pressing B
View make_me_happy_microbit.py
from microbit import *
while True:
if button_a.is_pressed():
display.show(Image.HAPPY)
elif button_b.is_pressed():
break
else:
display.show(Image.SAD)
@andreagrandi
andreagrandi / hello_pycon_microbit.py
Created Mar 11, 2016
Hello world example in MicroPython
View hello_pycon_microbit.py
from microbit import display
# This text will scroll on the 5x5 matrix display
display.scroll('Hello PyCon Italy')
@andreagrandi
andreagrandi / dontshakeme.py
Created Feb 27, 2016
DontShakeMe is an example written in Python that uses microbit accelerometer
View dontshakeme.py
# 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:
@andreagrandi
andreagrandi / microbit_light_sensor.py
Created Feb 7, 2016
Display a Sun or a Moon on the BBC micro:bit display, depending on the value read from the light sensor
View microbit_light_sensor.py
import microbit as m
SUN_IMAGE = m.Image(
"90909\n"
"09990\n"
"99999\n"
"09990\n"
"90909")
MOON_IMAGE = m.Image(
"99900\n"
@andreagrandi
andreagrandi / microbit_buttons.py
Created Feb 7, 2016
BBC micro:bit example that scroll "A" or "B" depending which button is pressed
View microbit_buttons.py
import microbit
while True:
if microbit.button_a.is_pressed() and microbit.button_b.is_pressed():
microbit.display.scroll("AB")
break
elif microbit.button_a.is_pressed():
microbit.display.scroll("A")
elif microbit.button_b.is_pressed():
microbit.display.scroll("B")
@andreagrandi
andreagrandi / mb_accel_happysad.py
Created Jan 25, 2016
MicroBit accelerometer example: show an happy face if kept straight or a sad one if bended
View mb_accel_happysad.py
import microbit as m
SENSITIVITY = 250
while (True):
x = m.accelerometer.get_x()
if abs(x) < SENSITIVITY:
m.display.show(m.Image.HAPPY)
else:
@andreagrandi
andreagrandi / andreagrandi
Last active Dec 6, 2015
Nginx configuration file for andreagrandi.it
View andreagrandi
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;
}
View lambda_map_list_comprehension.py
# 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)
View Recruiter Domains
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
@andreagrandi
andreagrandi / memoize.py
Created Jun 14, 2015
Python memoize decorator: cache values already calculated
View memoize.py
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