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 / parse_json_post.go
Created Aug 19, 2014
Parse a JSON http POST in GoLang
View parse_json_post.go
package main
import (
"encoding/json"
"fmt"
"net/http"
)
type test_struct struct {
Test string
@andreagrandi
andreagrandi / settings.py
Last active Oct 11, 2021
Sending emails from Django during development without using a real SMTP server. Python comes with a very basic and integrated SMTP server. To start it just open a terminal and type: python -m smtpd -n -c DebuggingServer localhost:1025 Then configure your settings.py using the following parameters. You will see the email directly in the terminal …
View settings.py
if DEBUG:
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = 'testing@example.com'
@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 / user_manual.md
Last active Sep 8, 2020
Andrea Grandi's User Manual: learn how to work with me!
View user_manual.md

Andrea Grandi User Manual

This is my user manual. If we are working together (or planning to), please read it carefully. You will learn how to deal with me productively and avoid misunderstandings.

My style

  • I need to understand why I'm doing something
  • I love working as a part of a team, not as an individual
  • I love pair programming
  • I like to have a very basic working version first and iterate on it
@andreagrandi
andreagrandi / gdata_read.py
Last active Oct 30, 2019
Read a Google Docs spreadsheet document from Python.
View gdata_read.py
# Copyright (c) 2013, Andrea Grandi and individual contributors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1) Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2) Redistributions in binary form must reproduce the above copyright notice,
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'