Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home... permanently!

Andrea Grandi andreagrandi

🏠
Working from home... permanently!
View GitHub Profile
View mnist_example.py
from keras.datasets import mnist
from keras import models
from keras import layers
from keras.utils import to_categorical
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
network = models.Sequential()
network.add(layers.Dense(512, activation='relu', input_shape=(28 * 28,)))
View keybase.md

Keybase proof

I hereby claim:

  • I am andreagrandi on github.
  • I am andreagrandi (https://keybase.io/andreagrandi) on keybase.
  • I have a public key ASClZLE2JRXY3NdFfmpwO-4yEwrmRL45_zVUR6heAwiKWgo

To claim this, I am signing this object:

View keybase.md

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@andreagrandi
andreagrandi / website_migration_notes.txt
Last active Jul 2, 2017
Step by step notes to migrate andreagrandi.it to a static website
View website_migration_notes.txt
- create andreagrandi.it repository on GitHub
- clone andreagrandi.it repository locally
- copy files from andreagrandi.co.uk repository to andreagrandi.it one
- change extras/CNAME content to: www.andreagrandi.it
- change SITEURL in publishconf.py to: https://www.andreagrandi.it
- change DISQUS_SITENAME to ‘andrea-grandi-it’
- get a new GitHub token from https://github.com/settings/tokens
- activate TravisCI for repository andreagrandi.it
- run travis encrypt GH_TOKEN=……… from inside andreagrandi.it repository
- copy the generated value to .travis.yml
@andreagrandi
andreagrandi / microchristmas.py
Created Dec 14, 2016
Microbit Christmas Tree
View microchristmas.py
from microbit import *
image_1 = Image.XMAS
image_2 = Image.HAPPY
status = 'OFF'
while True:
if button_a.is_pressed():
status = 'ON'
@andreagrandi
andreagrandi / permissions.py
Created Sep 30, 2016
IsAdminOrReadOnly is a custom Django Rest Framework permission class that allows Admin users to POST and anonymous to GET
View permissions.py
from rest_framework.permissions import BasePermission, SAFE_METHODS
class IsAdminOrReadOnly(BasePermission):
def has_permission(self, request, view):
if request.method in SAFE_METHODS:
return True
else:
return request.user.is_staff
@andreagrandi
andreagrandi / merge_spammers_list.py
Created May 25, 2016
Merge Jason Cartwright spammer list with spammy-recruiters one
View merge_spammers_list.py
#!/usr/bin/python
spammy_recruiters = []
jason_recruiters = []
with open('spammers.txt', 'r') as f:
spammers = f.readlines()
for domain in spammers:
spammy_recruiters.append(domain.replace(' OR \n', '').replace('\n', ''))
View simple_accelerometer_microbit.py
from microbit import *
while True:
reading = accelerometer.get_x()
if reading > 20:
display.show("R")
elif reading < -20:
display.show("L")
else:
display.show("-")
@andreagrandi
andreagrandi / random_names.py
Created Mar 18, 2016
Get random name from a list on microbit
View random_names.py
from microbit import *
import random
names = [
"Mary", "Yolanda", "Damien", "Alia",
"Kushal", "Mei Xiu", "Zoltan"]
display.scroll(random.choice(names))
@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)
You can’t perform that action at this time.