Generating Random Sequences (part I)

29/09/2009

Every once in a while, we need a random sequence. Whether to test a data structure’s performance or to run probabilistic unit tests, the provided rand primitive from your favorite programming language has several limitations. First, it’s been known for a while that if most implementations of the C standard library rand() function are not very random, despite being “good enough” in great many cases. Second, and more importantly, it does not allow you to easily control the period nor to generate a permutation on 0\ldots n-1, for example.

dice

There are many methods of generating pseudo-random number sequences. Not all exhibit the same properties and, accordingly, a method may be more useful in one case and perfectly useless in another. High quality pseudo-random number generation is a notoriously hard endeavor, but there is a number of very simple algorithms that will get you out of trouble for certain specific tasks. Let us consider, for example, the example where the pseudo-random generator must generate the numbers in 0\ldots{}n-1 exactly once, in a random order, of course, in exactly n draws.

Read the rest of this entry »


The Zune Freezes: More on Unit Testing

22/09/2009

Do you remember the epic fail that bricked the Zune a whole day on the last day of last year, a bisextile year? I described here and here how this error could have been entirely avoided using basic unit testing.

brick-small

You probably remember (if you read the original post) that I first claimed that it’d take a few seconds to check all possible dates but in fact it ended up taking something like 90 minutes. This week, I come back on unit testing of a very large domain under a time constraint.

Read the rest of this entry »


A quick Bash Fix

16/09/2009

Remember, not too long ago I told you how to shorten path names in a Bash prompt? Well two things. Apparently, there’s a similar mechanism in Bash 4.0 with PROMPT_DIRTRIM(which I haven’t tried yet). Second, noticed that I’m frequently using many terminals opened on many machines, and I’m not always sure which is which. Using uname -n in the terminal spews the machine name, but it’d be much better if the name appeared in the terminal title bar. To do so, use the same prompt I used previously, and add $HOSTNAME (a Bash variable that holds the machine’s name) in there:

PS1='\[\033]0;$HOSTNAME: $(shorten_path "${PWD}" 50)\007\]$(shorten_path "${PWD}" 50) >'

(again, use the view plain mode if WordPress messes up the syntax again)


What’s a Good Color Scheme?

15/09/2009

Although EMACS is growing old, filled with passé idiosyncrasies, and rather complicated to tweak, I grew accustomed to it and is now my main editor. I use it for shell scripting, C++, HTML, even. But to use EMACS properly, or a least make it enjoyable a little bit, one must do a fair bit of configuration. Key bindings to match modern keyboards, adding the macros you’re using the most, and, finally, adjusting the color scheme so that your eyes do not bleed after a few hours of work.

yeux-saignants

But what is a good color scheme?

Read the rest of this entry »


Suggested Reading: La Nouvelle Grammaire en Tableaux

11/09/2009

Marie-Éva de Villiers — La Nouvelle Grammaire en Tableaux et Recueil de Conjugaison — Québec Amérique, 2009, 324 pp. ISBN 978-2-7644-0690-8

(<del>Buy at Amazon.com</del>)

(Buy at Amazon.com)

Normally, I suggest English books, but since I know a certain part of my lectorate is French-speaking, I will make, now and then, an exception.

Un ouvrage de référence indispensable s’il en est un. Ce guide de la grammaire Française en plus d’être le plus à jour, a la particularité d’être très clair et complet; comme son titre le laisse entendre, l’information est présentée par tableaux, du genre if-then-else, chacun d’une grande simplicité mais aussi très complet. Pour comprendre l’usage du subjonctif plus-que-parfait (dont l’usage rare se fait trop souvent le prétexte aux phrases phonétiquement ambiguës — et aux farces salées) il suffit de consulter le tableau « concordance des temps dans la phrase. » Des néologismes ? Aucun problème ! Consultez le guide d’usage et de formation des néologismes.

Une lecture obligatoire pour tout bloggueur, thésard ou communicateur!

(hit Google Translate for fun)


Can you survive your Data Hiroshima?

08/09/2009

Even expensive and top-of-the-line hardware is fallible. Last night (at the time of writing) my main workstation’s PSU burned. I mean, not soft-failed and powered down, I mean burned. With the acrid smell filling the room, I knew something went very wrong the instant I entered my study. I found my computer powered down, non-responsive. I wasn’t too worried because I knew that even if the computer went dead for good, I would not loose much data since, you know, I have backups.

nuclear-test-(unknown)

Are you capable of surviving your own little Data Hiroshima?

Read the rest of this entry »


Suggested Reading:The LATEX Companion

04/09/2009

Frank Mittelbach, Michel Goossens, Johannes Braams, David Carlisle, Chris Rowley — The LATEX Companion — 2nd ed, Addison Wesley, 2006, 1090 pp. ISBN 0-201-36299-6

(Buy at Amazon.com)

(Buy at Amazon)

I should have told you about this book a long time ago. The LaTeX Companion is the definitive guide to LaTeX, ideal for anyone using it on a daily basis (or almost, as I do) or anyone wanting to learn LaTex. LaTeX is a complex and sophisticated mark-up language aimed at producing better typography for mathematics and scientific work—in which it totally succeeds. As for Linux, LaTeX (and TeX) comes in many distributions, some more geared toward the humanities, other for science, and still other for exquisite “art” typesetting.

A must read for graduate students.

*
* *

On the web:


Upcoming GT / Conférence-Causerie for #programmeur on Freenode

04/09/2009

The guys from the freenode channel #programmeur (irc.freenode.net) are Getting Together this saturday September 5th at 13h00 at the University of Montréal. The program: short (1h) talks about Distributed Version Control software, Numerical Stability, and Secure Networking.

Instructions to get there are here.

The cost of entry is 10$, mostly to pay for renting the room with media equipment. All are welcomed.


Short PWD in BASH Prompts

01/09/2009

It’s not uncommon to have inordinately deep directory hierarchy on your computer, especially if you’re like me and you like to give significant names to your directory. For example, if you’re using a 80×25 terminal, the location /home/steven/download/Album Photo/2009/06 jui/20-22/21-008-St-Georges-de-la-Malbaie will cause your shell prompt to wrap around the shell window quite messily. Of course, you could show only the last directory’s name, say 21-008-St-Georges-de-la-Malbaie to continue with my previous example, but that’s a bit terse, especially if you end up on a directory whose name is unexpectedly short.

The correct solution, may be, is to arrange the prompt to show adaptively long parts of the current working directory up to a given limit, and abstract parts of the path using, say, ..., and make sure the result is legible. For example, /home/steven/download/Album Photo/2009/06 jui/20-22/21-008-St-Georges-de-la-Malbaie, using a maximum prompt length of 50 would get shortened to .../06 jui/20-22/21-008-St-Georges-de-la-Malbaie, which is already much shorter yet retained its legibility and meaning.

Read the rest of this entry »