Julien Palard

Python Developer and Trainer

Articles by Julien Palard

Covariance and Contravariance in C#3

A short introduction to Covariance and Contravariance in C# 3 preparing you to an article about that in C# 4. So what is covariance? Covariance is basically using a method which returns something derived from the expected type. An exemple? It's safe to have a method returning a cat when …

echo and backslash-escaped caracters / new lines: how to write portable scripts ?

While writing shell scripts you are using a lot of echo but did you think about portability of this simple statement? Can you say what will be diplayed, without testing, on your shell, the following tests:

echo \n \c '\n' '\c' "\n" "\c"
echo -e \n \c '\n' '\c' "\n …

emacs: Highlighting errors for c, python, and other languages

This is a deprecated article about flymake, you should check for flycheck instead.

Hi! Today we'll see how to highlight syntax errors in emacs, with exemples for C and Python. First you should learn about flymake-mode In a nutshell Flymake is a minor mode to perform on the fly checks …

Emacs: replace tabs with spaces

When you want to replace tab with spaces or vice versa don't use M-% (query-replace) but M-x tabify or M-x untabify. They work on the current selection so if you want it to be applied to a whole buffer, try C-x h (mark-whole-buffer) before to select the whole buffer.

emacs: standard input is not a TTY

Did you ever tried something like :

$ find -name '*.c' | xargs emacs
or
$ grep -rl snmp . | xargs emacs

and got the error "emacs: standard input is not a tty" ? That's normal, as the stdin for emacs is here the pipe, not your tty, you need a workaround to leave the normal …

Exclude directories from recursive grep

How often are you using grep in subversionned folders like that:

grep -rni foobar . | grep -v .svn

Upgrade to grep 2.5.3 and use (alias it ?)

grep -rni --exclude-dir .svn foobar .

(or ... stop using SVN !!!)

How to check if a string is valid utf-8

Every day (at least) I'm facing a problem: how to check if a string is valid in utf-8 ? So I wrote a little C program, that I put on my github. Just be aware that pure ASCII is valid UTF-8 and that's not a bug: my program is checking if …

Howto invoke an event via reflection

Why this article ? Because of this note found on the MSDN's EventInfo page:

EventInfo is not intended to be used to raise events. An object raises events as dictated by its internal state.

Let's try to raise an event with reflection ... Firstly, let's search, but not in GetEvent, in GetField …

Integrating google bookmarks in google chrome

As every developer, you have 42 computers, 8 browsers, and spend a lot of time asking why Google Chrome does not integrate Google Bookmarks? Here is a solution: First add the "Add to Google Bookmarks" bookmarklet from here http://www.google.com/support/chrome/bin/answer.py?hl=en&answer …

Javascript Foncteur

I just discovered, this morning, how to create a Visitor in Javascript: A visitor is an objet who can be used like a function:

var my_foncteur = new A_Foncteur();
my_foncteur.can_have_methods(42);
my_foncteur("Can be called like a function");

Implementing it in C++ is extremly easy, using operator overloading, so overloading …