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.ndiff(file1_lines, file2_lines)
diff …
Simply add the following class to your project. It will be automatically registered at start-up if you use the @EnableAutoConfiguration
annotation :
@ControllerAdvice // Makes this the default behaviour of all controllers
@ConditionalOnProperty(prefix = "app", name = "disable-default-exception-handling")
class GlobalControllerExceptionHandler {
@ExceptionHandler(Exception.class) // Catch any exception
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) // Returns an error code …
Deux lectures complètement décorellées à partager:
Aujourd'hui, pour justifier leurs [les comédiens] droits, on parle d'économie. En 2004, le rapport Guillot remis au ministre de la culture et de la communication, dans l'émotion suscitée par l'annulation du festival d'Avignon, souligne qu'en 2003 "la valeur ajoutée dégagée par le secteur du …
This evening I faced a really annoying bug: while able to exit Family View by entering my PIN in Steam.exe
, I could not do so when trying to access the Steam website.
I simply could not pass the page "Adults, enter your PIN below to exit Family View." Neither …
First, install PHP debugging extensions for gdb
, for example:
debuginfo-install php-5.6.8 # if you use yum
aptitude install php5-dbg # if you use aptitude
Then simply:
php_version=5.6.8
php_script_pid=$(pgrep -f $php_script_name)
curl https://raw.githubusercontent.com/php/php-src/PHP-$php_version/.gdbinit >> ~/.gdbinit
gdb …
The timeit
module is useful for micro benchmarks, but does not allow to measure execution time of large snippets, as it requires the code tested to fit in a string.
Hence, I went looking for a context or decorator-based solution. And I found this bug report commented by Guido van …
I've lost quite some time on this error recently :
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.hibernate.jpa.boot …
Just some handy accessors for the brower console :
var myScope = $('#directive > select.or').scope()
var $rootScope = $('body').scope() // if <body> has the 'ng-app' attribute
var myController = $('#directive > select.or').controller()
var injector = $(document.body).injector()
var myService = injector.get('myServiceName')
And there are 3 handy pre-commit hooks :
- repo: local
hooks …
Pourquoi, mais pourquoi faut-il 3 lignes en Java pour juste extraire un groupe d'une expression régulière qui "match" ???
Matcher matcher = Pattern.compile("o?k(b|i)s+").matcher("kiss");
matcher.matches();
assert matcher.group(1) == "i";
En Python:
assert re.match("o?k(b|i)s+", "kiss").group(1) == "i …
I'd like to introduce you to an awesome git companion : pre-commit
hooks by Yelp.
Git hooks are scripts that git
executes before or after events such as: commit, push, and receive.
Git hooks are a built-in feature, but git
does not offer much support for them: if there is a …
I recently worked on a short website project using Django & Heroku. It was my very time using this Python framework, and I really liked it !
This is a compendium of tips & tricks that I, as a Django beginner, found quite useful :
Django enhanced shell
To install it :
pip install django …
Die shell script, DIE !
In this post, I'll show how easy it ease to convert fragile shell scripts to Python scripts, using sh.py. I'll use as an example a simple script to check your HTML code from the command-line, using the W3C validator.
Now you ask me, why the …
Sometimes, it's useful to print some source code on paper. And PDF is a very common file format, that you can be sure your printer will accept, and that will let you preview the final page layout. But how to quickly perform syntax-coloring and export to PDF ?
I've been experimenting …
Disclaimer: this post was heaviliy inspired by the 2 following gists:
color_log.py
usingtermcolor
recipescolorlog.py
usingcolorama
I loved the simplicity of the first, not having to manipulate any of the logging internal API, but I prefer colorama
over termcolor
.
Without further ado, there is my solution …
In a nutshell:
SUN=$SAUCE_USERNAME; SAK=$SAUCE_ACCESSKEY
curl -u $SUN:$SAAK https://saucelabs.com/rest/v1/$SUN/jobs?format=csv \
| perl -wpe 's/\r$//' \
| xargs -I{} curl -u $SUN:$SAK -X DELETE "https://saucelabs.com/rest/v1/$SUN/jobs/{}"
Pytest
is a very complete test framework for Python. I like how you can write a basic unittest.TestCase
and the py.test
test runner command will inject all its magic at runtime, without you having to directly import
anything: awesome separation of concerns.
This modularity comes at a cost …
Since July 2014, Substack great cross-browsers testing tool testling
has been unavailable.
Today I was looking for an alternative to use with ecovoit, my carpooling search engine. Saucelabs is a very interesting solution, and is free for open-source projects.
Now I found 2 tools to easily launch your Javascript TAP …
Under Windows, CPython is shipped with a very useful py
command.
PEP-397 describes in details its behaviour, and its C implementation can be found in the CPYthon Mercurial repository.
There has already been a lenghty discussion in the "python-ideas" mailing list to write a Linux equivalent. I agree with what …
A month ago, I wanted to automate queries to a website that is using the PHPSESSID cookie to keep track of sessions. I struggled a lot and couldn't find any documentation covering the behaviour I was observing. But yesterday I finally found a solution !
In hope it could help others …
Consider the following Python expression:
print("".join(set("ABCDE")))
What do you think it produces ?
Not necessarily "ABCDE". Right, but you would expect the result to be consistent, isn't it ?
$ for i in {1..3}; do python2.7 -c 'print("".join(set("ABCDE")))'; done
ACBED
ACBED
ACBED
Great !
...
But with …