Skip to content

Instantly share code, notes, and snippets.

View alessandrocucci's full-sized avatar

Alessandro Cucci alessandrocucci

View GitHub Profile
@alessandrocucci
alessandrocucci / revolut.py
Created March 23, 2022 13:31
Giacenza Media Revolut
"""
Script Python per il calcolo della giacenza media di un conto Revolut.
- scaricare la lista movimenti dell'anno da calcolare in CSV
- mettere il file nella stessa cartella di questo script python
- lanciare il comando (default anno precedente):
python revolut.py -d nomefile.csv
NB. Serve Pandas.
"""
@alessandrocucci
alessandrocucci / statistics.py
Created February 23, 2017 08:53
A very basic statistics module.
"""
A very basic statistics module.
This is a summary of statistics module from Python 3 for Python 2.6+ development.
================== =============================================
Function Description
================== =============================================
mean Arithmetic mean (average) of data.
variance Sample variance of data.
@alessandrocucci
alessandrocucci / restapi_talk.py
Last active August 27, 2017 16:10
Source Code for my talk @ PyRE about REST API with Flask & SQLAlchemy
from flask import Flask, jsonify, abort, request
from flask_login import LoginManager, current_user
import json
from flask_sqlalchemy import SQLAlchemy
from flask_sqlalchemy import orm
db = SQLAlchemy()
class Record(db.Model):
@alessandrocucci
alessandrocucci / apibotcodemotion.py
Created November 26, 2016 13:38
Codemotion 2016 Challenge
"""
CODEMOTION 2016, Milan (IT)
Challenge:
- Write a chatbot
- Must provide REST API
- Write the smallest source code possible
- In Python
Required libs:
@alessandrocucci
alessandrocucci / pandas_csv.py
Created November 9, 2016 15:51
Giocando con Pandas
from pandas.io.parsers import read_csv
"""
Esempio base di utilizzo della libreria Pandas per maneggiare file csv Senza
diventare scemi.
Tutta la documentazione è presente a questo indirizzo:
http://pandas.pydata.org/pandas-docs/stable/index.html
"""
# Importo un csv separato da virgole, creando di fatto un DataFrame
@alessandrocucci
alessandrocucci / strategypattern.py
Created September 8, 2016 08:41
Strategy Pattern in Python (v. 2.x, 3.x)
import sys
import types
if sys.version_info[0] > 2: # Python 3+
create_bound_method = types.MethodType
else:
def create_bound_method(func, obj):
return types.MethodType(func, obj, obj.__class__)
class StrategyExample:
"""
Esempio banale di Factory Pattern.
Valido solo in Python 2.x
"""
from abc import ABCMeta, abstractmethod
class AnimaleBase(object):
@alessandrocucci
alessandrocucci / timeit.py
Created July 27, 2015 13:00
Script per misurare il tempo di esecuzione di una funzione
"""Script per misurare il tempo di esecuzione di una funzione
"""
import time
def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
@alessandrocucci
alessandrocucci / Gmail.py
Created May 27, 2015 07:47
Mail script to check unseen messages in every user's mailbox
__author__ = 'Alessandro Cucci'
__email__ = '[email protected]'
__date__ = '26/05/15'
import urllib2
import base64
from xml.dom.minidom import parse
# Valid commands to display author and subject for incoming mails
INPUT = ['yes', 'YES', 'yep', 'YEP', 'y', 'Y']
@alessandrocucci
alessandrocucci / weather.py
Created May 22, 2015 11:26
Meteo info script
#!/usr/bin/env python
__author__ = "Alessandro Cucci"
__license__ = "MIT"
__version__ = "0.0.1"
__email__ = "[email protected]"
__status__ = "Development"
import urllib, json
from datetime import datetime