[FR] Problème de maths de la lady du lac

Dans le numéro 171 du magazine tangente, page 47, un intéressant petit problème mathématique est posé au lecteur. Une jeune femme était en vacances au bord du lac Circulaire, un grand plan d’eau artificiel ainsi nommé pour sa forme circulaire précise. Pour échapper à un soupirant envahissant qui la…

[EN] Command history in a Python 3 virtualenv

Due to a long standing bug, no history file will be kept of the commands you enter in an interactive shell when using a Python 3 virtualenv. I found out a simple workaround. Simply put the following in your ~/.pythonrc : import atexit, os, readline, sys if sys.version_info >…

[EN] Retrieving a file version (git commit & tag) based on its hash

Today, I did some tests on a server where an old version of our project was deployed. At some point, I needed to identify which version of the code was there, and I wrote a pretty shell function to figure this out. Yeah, I know what your thinking : there must…

[EN] A Python iterator to list all UTF8 characters

Last week, I made up a basic TCP server in Python, to receive log lines. To split log lines, I used the ascii line feed ascii character : \n aka 0xa in hexadecimal. But then I wondered : could this byte appear elsewhere in the UTF8-encoded strings of text I was sending…

[FR] Intro à Python & les frameworks web

Le mois dernier j'ai rapidement présenté le language Python et les frameworks web existants à mon équipe à Voyages-Sncf.com. Les slides sont accessibles ici, ainsi que les sources Markdown pour Reveal.js. Iframes non supportées. Cliquez sur le lien dans le paragraphe au-dessus pour accéder directement aux slides. Il…

[FR] Show me a hero

Depuis une dizaine d'années, j'ai cette petite idée dans un tiroir. Une série télé qui présenterait le quotidien de politiciens, présentés comme des super héros. Peut-être en insérrant des passages où ils se verraient les uns les autres en justaucorps et collans multicolores. Ou alors par un habile jeu de…

[EN] Display Chuck Norris facts when you git pull !

...in just one command : cd path/to/your/git/repo cat <<EOF >.git/hooks/pre-rebase #!/bin/sh echo -n \$'\x1b[36m' # start coloration (cyan) curl -s https://raw.githubusercontent.com/jenkinsci/chucknorris-plugin/master/src/main/java/hudson/plugins/chucknorris/FactGenerator.java | sed '1,/FACTS = {/d;s/…

[EN] Useful short Python decorator to convert generators into lists

Python generators are awesome. Why ? their syntax is simple an concise they lazily generate values and hence are very memory efficient bonus point: since Python 3 you can chain them with yield from Their drawback ? They can be iterated only once, and they hide the iterable length. I took an…

[EN] New release for genealogic-d3

A year ago, I built a small JS lib using D3.js to visualize JSON-defined genealogy trees. At the beginning of the year, I added a new feature using flex-calendar and moment-ferie-fr : a birthday calendar using the same JSON genealogy definition and miniature images. I added this calendar to the…

[EN] pre-commit under Windows

First, lets mention Git Bash (aka msysgit) : the old version was a PITA to extend with additional packages (e.g. adding common C libs like libxml), and the new one (renamed Git for Windows), is based on MSYS2, but does not include a package manager. Hence, we were left with…

[EN] TIL zip files can contain comments

... and the standard UNIX tool zipinfo cannot display them ! So here is Python one-liner to extract them, and other useful meta informations: python -c "import json, sys, zipfile; json.dump([{k: str(getattr(i, k)) for k in zipfile.ZipInfo.__slots__} for i in zipfile.ZipFile(sys.argv[1]).infolist(…

[EN] Generating SRI hashes with grunt-usemin

I'm not really crazy about Yeoman's grunt-usemin : I find painful the way it enforces a unique pipeline, with its preliminary useminPrepare task and :generated targets. But on the project I'm working on, we made the choice to use it early on, and we're sticking with it for now. And this…

[EN] Colored diff output with Python

Say you are generating a colored diff output with the standard difflib Python package: diff = difflib.ndiff(file1_lines, file2_lines) print('\n'.join(diff)) Now, I'll show you how to write a simple color_diff function that you can use to color your diff like this: diff = difflib.…