Skip to content

Instantly share code, notes, and snippets.

View martync's full-sized avatar

Martyn CLEMENT martync

View GitHub Profile
taxe_carburant = 0.9
tarif_baril = 110
litre_par_baril = 159
# 2010
prix_litre = (tarif_baril + tarif_baril * taxe_carburant) / litre_par_baril
# 2011
@martync
martync / cli.py
Last active March 18, 2019 10:18
# coding: utf-8
"""
Client TCP
----------
Exécute un client TCP qui envoie des message de statistiques
et de demande de configuration sur le serveur passé en paramètres.
@martync
martync / run.py
Created December 17, 2019 10:00
Parse arguments from CLI
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"action",
help="Choose an action to execute",
nargs="?",
@martync
martync / .travis.yml
Created December 19, 2019 15:02
Travis
# 1 - Se créer un compte sur https://travis-ci.com/
# 2 - Ajouter votre répo à Travis
# 3 - Ajouter ce fichier à votre répo puis commit+push
language: python
python:
- 3.5
- 3.6
before_install:
- pip install -U pytest
@martync
martync / Animals.md
Last active January 29, 2020 11:44
Animals

Classe Animal : classe parente

3 sous-classe:

  • Cat
  • Snail
  • Snake

Attributs de class :

  • hair_type (str)
@martync
martync / vehicules.md
Last active February 3, 2020 08:57
Classes - véhicules

Creer les classes suivantes :

  • Voiture
  • Camion
  • Scooter

Chaque véhicule devra définir une vitesse maximum et une capacité d'essence maximum :

  • Voiture : 130 kmh / 50L
  • Camion : 90 kmh / 100L
  • Scooter : 50 kmh / 5L
@martync
martync / tryexcept.md
Created February 3, 2020 12:15
Try Except

Utilisation de block try-except générale

Ecrire une application de calcul d'amortissement d'un emprunt. L'application demandera la saisie :

  • du montant total de l'emprunt
  • de la durée en année

L'application affichera le montant amorti chaque année (montant total / durée)

Vous devrez capturer 2 erreurs :

@martync
martync / aggregate_tags.py
Created April 29, 2013 09:10
Django aggregation in template filters.
from django import template
from django.db.models import Sum, Avg, Max, Min, Count
register = template.Library()
@register.filter
def sum(queryset, field):
return queryset.aggregate(sum_value=Sum(field)).get('sum_value')