Skip to content

Instantly share code, notes, and snippets.

Gilles Lenfant glenfant

Block or report user

Report or block glenfant

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
@glenfant
glenfant / marshmallow_fr.py
Created May 8, 2018
How I translated marshmallow fields error messages into French
View marshmallow_fr.py
"""
==============
marshmallow_fr
==============
Les fields de marshmallow dont les messages d'erreur sont traduits en Français.
Ces messages d'erreur sont basés sur marshmallow 2.15.1 et il sera peut-être nécessaire de le mettre à jour
au fil des évolutions de marshmallow.
Parametrized marshmallow fields with error messages translated into French.
@glenfant
glenfant / conf.py
Last active May 5, 2017
How to provide a default configuration which individual points may be overriden in a custom configuration file (to improve and explain)
View conf.py
"""
================
euscans.settings
================
Provides settings customization and public configuration object
"""
from argparse import Namespace
import logging.config
@glenfant
glenfant / Vagrantfile
Last active Apr 8, 2017
A Vagrantfile for MacOS or Windows host, making an Ububtu 16.04 playground for the latest Docker (17.03-ce) and Docker-compose 1.12.0
View Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Docker playground for MacOS and Windows
# =======================================
#
# - Installs the latest Docker + Docker-compose
# - Uses faster NFS files sync on Mac OS
# - Uses faster SMB files share on Windows
#
@glenfant
glenfant / testwsgimock.py
Created Feb 3, 2017
How to create a temporary WSGI app suitable to unit tests mocking
View testwsgimock.py
# -*- coding: utf-8 -*-
# If you need to test a REST client, this is a Python 2 recipe that runs a
# simple WSGI app for your tests. Any improvement suggestion is welcome.
# Run this with "python -m unittest testingwsgi"
# Put this in a testing resources module, say tests/resources.py
import os
@glenfant
glenfant / mlsearch.py
Created Jan 16, 2015
Attempt to record a new query as extended REST service in ML 7
View mlsearch.py
# -*- coding: utf-8 -*-
"""
Provided a new XQuery, we record it as extended REST resource in ML 7 server
"""
import httplib
import urlparse
import requests
@glenfant
glenfant / dottedname.py
Created Jan 6, 2015
Turns a dotted name in a string as 'sys.path' into a Python object
View dottedname.py
# -*- coding: utf-8 -*-
"""
==========
dottedname
==========
This module may be used when you need to refer to Python objects from non
Python files. For example, in a configuration file.
Resolve a python dotted name (stolen from zope.dottedname)
@glenfant
glenfant / Vagrantfile
Last active Aug 29, 2015
Vagrantfile for taiga-vagrant that supports OSX AND Linux. Contrib for Windows Welcome. See https://github.com/taigaio/taiga-vagrant/issues/15
View Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
require "./source.rb"
ROOT_PATH = File.dirname(__FILE__)
VAGRANTFILE_API_VERSION = "2"
def configure_extra(config)
end
@glenfant
glenfant / timeoutctxmanager.py
Last active Dec 28, 2015
This is a (Unix only) context manager that cancels the execution of its inner code block when its timeout is gone. Note: deprecated, see my "stopit" third party package.
View timeoutctxmanager.py
# -*- coding: utf-8 -*-
"""
This recipe provides a context manager that stops the execution of its inner
code block after the timeout is gone. This recipe is stolen with some changes
and rewording in a less app centric vocabulary from the "rq" package.
https://github.com/glenfant/rq/blob/master/rq/timeouts.py.
Warnings:
@glenfant
glenfant / pipetestserver.py
Last active Dec 27, 2015
Use a stub HTTP server in unit tests for HTTP client testings (REST, ...)
View pipetestserver.py
# -*- coding: utf-8 -*-
"""\
==============
pipetestserver
==============
This recipe describes how you can create / activate and kill a temporary HTTP
server with a WSGI app to provide unittest resources to a client software,
that's the target of your application.
@glenfant
glenfant / mock_datetime_now.py
Last active Dec 27, 2015
A context manager that enables go quickly in the future or in the past with datetime.datetime.now(). This may be useful in lots of unit tests.
View mock_datetime_now.py
# -*- coding: utf-8 -*-
"""Mock datetime.datetime.now()"""
import contextlib
import datetime
@contextlib.contextmanager
def mock_datetime_now(*args, **kwargs):
"""Context manager for mocking out datetime.datetime.now() in unit tests.
You can’t perform that action at this time.