Skip to content

Instantly share code, notes, and snippets.

View andreagrandi's full-sized avatar
🏠
Working from home... permanently!

Andrea Grandi andreagrandi

🏠
Working from home... permanently!
View GitHub Profile
#!/bin/bash
# This script is necessary to remove the annotations block from each Markdown file.
# These annotations are being written by iA Writer and are not necessary for the website.
# Define the directory to start searching from. Adjust this to your specific folder.
START_DIR="content"
# Process each Markdown file in the specified directory and its subfolders.
find "$START_DIR" -type f -name "*.md" | while read -r file; do
echo "Processing: $file"
@andreagrandi
andreagrandi / pelican2hugo.py
Last active February 11, 2024 09:28
Python script to migrate posts from Pelican to Hugo
# Migration script from Pelican to Hugo
import os, re, shutil
from pathlib import Path
INPUT_FOLDER = "content"
OUTPUT_FOLDER = "content-hugo"
# Custom sort key function
def sort_key(path):
# Extract the base filename without the extension
@andreagrandi
andreagrandi / .zshrc
Last active December 10, 2021 10:02
Configuration for .bashrc/.zshrc for pyenv and pyenv-virtualenv
# Install dependencies first:
# brew install pyenv
# brew install pyenv-virtualenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
@andreagrandi
andreagrandi / user_manual.md
Last active September 8, 2020 11:58
Andrea Grandi's User Manual: learn how to work with me!

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 / mnist_example.py
Created May 13, 2018 20:05
Simple MNIST example
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,)))

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:

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@andreagrandi
andreagrandi / website_migration_notes.txt
Last active July 2, 2017 09:00
Step by step notes to migrate andreagrandi.it to a static website
- 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 December 14, 2016 21:58
Microbit Christmas Tree
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 September 30, 2016 09:49
IsAdminOrReadOnly is a custom Django Rest Framework permission class that allows Admin users to POST and anonymous to GET
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