Baptiste Fontaine’s Blog

Preventing Bash Pranks

The easiest and most popular Bash pranks involve someone messing up with your ~/.bashrc. For example, here is a real-life example:

#! /bin/bash
echo >>$b
echo "echo sleep 1 >>$b" >>$b

If you execute this script, it’ll add a newline in your ~/.bashrc just in case it doesn’t end with a newline, then add this line:

echo sleep 1 >>~/.bashrc

The effect of this isn’t immediately visible to the pranked user. When they’ll start a new Bash session, e.g. by opening a new terminal window, the code in ~/.bashrc will be executed, and the previous line will add sleep 1 at the end of it, which means it’ll be executed and the user will have to wait one more second before having their prompt. The next time they’ll open a session, it’ll add one more line and thus will wait 2 seconds, and so forth.

In this post, I’ll give you an overview of the existing solutions to prevent these pranks.

A Python Toolbox

I started learning Python four years ago and have been heavily programming with it for near than a year now. In this post I’ll share some tools I use to ease and speed-up my workflow, either in the Python code or in the development environment.

How to Speed-up Vim’s Command-T Plugin

Command-T is a wonderful Vim plugin which allows you to open files with a minimal number of keystrokes. It’s really handy in a large codebase where you only have to type <leader>t, then a couple letters and press enter to open your file. It’s based on a fuzzy matching, which let you skip letters without worrying.

I recently installed the plugin on another machine and noticed it was really low: I had to wait a couple seconds to get the files list everytime. My computer has 8GB RAM so the problem wasn’t there.

How to Remember the Difference Between Conj and Cons in Clojure

When I started writing Clojure, I couldn’t memorize the difference between conj and cons and always used one instead of the another. Their name are similar, but cons is used to add an element at the beginning of a vector, while conj is used to add an element at the end of it. How can one memorize this? I found a mnemonic trick over the time that helps me remember this. Here is it:

Fixing Gnuplot-py’s “unknown Aqua Terminal” Warning on OSX

When plotting with gnuplot-py on OSX, I got an annoying warning saying that terminal aqua is unknown or ambiguous, even when I use a different terminal (e.g. postscript). This terminal doesn’t exist on my Gnuplot installation (4.6.3). In fact, gnuplot-py uses slightly different files depending on your platform. OSX’s one is exactly the same as other UNIX-flavored OSes but its default terminal is aqua. There are two ways to fix the warning, a hacky one I used before this blog post, and a clean one I discovered while writting this post. Hope this help!

Using Coveralls With Clojure

Coveralls is a service that keep track of your tests coverage for you. It can notifies you when your coverage decreases under a custom threshold, and their bot comments on pull requests to report their tests coverage. Like Travis-CI, it allows you to add a badge to your readme with an up-to-date tests coverage percentage.

If you already test your GitHub projects with a CI server like Travis, it’s very easy to add Coveralls to your workflow. Unfortunately, they have a library for Ruby, a couple user-provided libraries for other languages such as PHP, Java and Python, but nothing for Clojure. Fortunately, they provide an API for unsupported languages like Clojure. Here is how to use it.

Function-level Black-box Testing

Black-box testing is a method of software testing that examines the functionality of an application (e.g. what the software does) without peering into its internal structures or workings (Wikipedia). While it’s usually done at a system level, I think the most obvious place it should be used is at the function level. It’s even more efficient if you write tests for someone else’s code.
Here is how I write unit tests for functions.

Local .vimrc’s

I discovered a great feature in Vim today. While we generally use the same Vim settings everywhere, we sometimes (have to) contribute to projects with a coding style different of ours, and because nobody wants to edit their .vimrc everytime to switch between configurations, Vim allows you to have per project .vimrc’s.

Use a Custom Tld for Local Development

In this post, we’ll create a custom TLD for local development, and configure Apache to work with that. It’ll allow you to work on your local version of with the local domain, with the exact same URLs, except that little .com which is replaced by .dev.

Get RFCs in Your Terminal

When working with Internet protocols, we have to read RFCs a lot. They can be found on the Web, but it’s better to have them directly in the terminal. Ubuntu provide some packages to have them offline, but if you aren’t a sudoer, you can’t install them with apt-get. So I needed a little script to fetch RFCs from IETF’s website and read them locally.