Skip to content

Instantly share code, notes, and snippets.

View martync's full-sized avatar

Martyn CLEMENT martync

View GitHub Profile
@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 / 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 / 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 / .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 / 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="?",
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 / scores.py
Last active December 28, 2018 13:08
Scores du jeu
scores = [
{
"start_date": "2018-12-13 08:39:11.539570",
"end_date": "2018-12-13 08:40:06.429570",
"winner": 1
},
{
"start_date": "2018-12-13 10:28:45.539570",
"end_date": "2018-12-13 10:28:56.228670",
"winner": 2
@martync
martync / model_merge.py
Created June 21, 2017 08:55 — forked from aaronkeck/model_merge.py
Django Model Merge
from django.db import transaction
from django.db.models import Model
from django.contrib.contenttypes.generic import GenericForeignKey
from django.apps import apps
@transaction.atomic
def merge_model_objects(primary_object, alias_objects=None, keep_old=False):
"""
Use this function to merge model objects (i.e. Users, Organizations, Polls,
@martync
martync / memoize.py
Last active July 3, 2018 09:37
Memoize Django model's method.
import functools
def memoize_django_model_method(obj):
@functools.wraps(obj)
def memoizer(*args, **kwargs):
# Get the model instance
instance = args[0]