Skip to content

Instantly share code, notes, and snippets.

Martyn CLEMENT martync

Block or report user

Report or block martync

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View .travis.yml
# 1 - Se créer un compte sur
# 2 - Ajouter votre répo à Travis
# 3 - Ajouter ce fichier à votre répo puis commit+push
language: python
- 3.5
- 3.6
- pip install -U pytest
martync /
Created Dec 17, 2019
Parse arguments from CLI
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser()
help="Choose an action to execute",
taxe_carburant = 0.9
tarif_baril = 110
litre_par_baril = 159
# 2010
prix_litre = (tarif_baril + tarif_baril * taxe_carburant) / litre_par_baril
# 2011
# 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 /
Last active Dec 28, 2018
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 /
Created Jun 21, 2017 — forked from aaronkeck/
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
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 /
Last active Jul 3, 2018
Memoize Django model's method.
import functools
def memoize_django_model_method(obj):
def memoizer(*args, **kwargs):
# Get the model instance
instance = args[0]
martync /
Created Oct 16, 2013
When testing a django application, sometime you just want to see what's happening on your html content. That does the trick.
import time
from datetime import datetime
from subprocess import call
def show_in_browser(response):
Write the response content into a temporary HTML file and
open it into your default browser.
martync /
Created Apr 29, 2013
Django aggregation in template filters.
from django import template
from django.db.models import Sum, Avg, Max, Min, Count
register = template.Library()
def sum(queryset, field):
return queryset.aggregate(sum_value=Sum(field)).get('sum_value')
martync / refresh_page.js
Created Apr 18, 2013
Ask the user to refresh the page after a countdown;
View refresh_page.js
function refresh_after(seconds){
if (seconds<=0){
alert('The page has expired, click OK to reload.')
document.location.href = document.location.href;
setTimeout(refresh_after, 1000, [seconds])
You can’t perform that action at this time.