Easy copy and paste in the Mac OSx terminal

In the Xerox Palo Alto Research Center between 1973 and 1976, Larry Tesler implemented the first version of what will be later known as the Copy-Paste tool. This tool is indeed very handy especially in graphical user interfaces and I guess we no longer can still live without it, but it also can be pretty convenient in text-based interface (as the terminal) without requiring the mouse.


Larry Tesler, 2007. Picture under CC License. Source Wikimedia

Two commands exist in Apple’s OS and they are pbcopy and pbpaste.

The power of these two commands comes from the fact that we can use them with redirections and pipes. Here are some examples:

ps -A | pbcopy
ls -la | pbcopy
cat ./file.txt | pbcopy

or simpler:

pbcopy < ./file.txt

And then you will be able to paste the content of your clipboard like this:

pbpaste >> ./anotherfile.txt

Quite helpful isn’t it ?

Git: squash the latest commits into one

Let’s say you’re working on a new local branch (based on master) and you did multiple commits that are closely related. You might want to squash these latest commits into a single one. Git does not provide a direct way to do this but the steps are pretty much straightforward.

Here is what you need to do in two steps:

First you need to soft reset your working directory to master:

git reset --soft master

This will undo the commits but will leave the changes you did.

Then all you have to do is to commit those changes all together:

git ci -m "your commit message"

In order to simplify these steps you can also add an alias in your git config:

squash = "!f() { git reset --soft master && git ci -m \"$1\"; }; f"

You will then use it this way:

git squash "your commit message"

Of course this is helpful only in the case where (1) your branch is based on the master and where (2) you need to squash all the recent commits of your branch since the master.

If that’s not your case you can change the first step to use HEAD instead, like this for example:

git reset --soft HEAD~3

Which will undo the last 3 commits.

So here you go, how to squash your latest commits into a single one.
You can play with the last command and put the number of the last commits you want to squash as a parameter in the git alias if you want to.

(E)Git history after renaming or moving a file

When renaming/moving a file, git log /path/to/file will only show the commits history from that renaming/moving until now. To follow the commits until the first one and display them in the history you will need to do a

git log --follow /path/to/file

All the commits will be shown in the history. But note that this will work only for a single file.

If you’re using Egit in Eclipse, you can do the same by checking the box Follow Renames in Preferences -> Team -> Git -> History

PS: If you want to move a file in a git repository, you can consider using git mv oldpath newpath which is a shorthand for

mv oldpath newpath
git add newpath
git rm oldpath

More informations and options for git log.

Git: Copy a file from one branch to another


Let say you are on the master branch and you want to do some devs without messing up your master. What one usally do is create a new branch dev based on the main branch (in this case master) and do all the developments there.

Sometimes you may want to copy just one or two files from this dev branch without merging the whole branch with master.

The easiest way to do so is the following (assuming you are in another branch than dev):

git checkout dev -- path/to/your/file

Note that you can also get a whole folder, all the files inside this folder will be copied:

git checkout dev -- path/to/your/folder

For more informations on checkout, take a look at the man page git checkout

Make Eclipse recognize your scala source files

Scala programming language logo

If you use the Eclipse and if you mix Java and Scala source files in the same project, Eclipse might not recognize the Scala ones.

To make it recognize them you’ll have to modify the .project file in particular buildSpec and natures tags :


Or simply by going to the menu :
Right click on your project -> Configure -> Add Scala Nature

And that’s it.

Install MariaDB on Mac OSX

First you’ll need to install Homebrew if you don’t have it on your machine :

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

If you already have homebrew installed, type brew update

Then : brew install mariadb

It will download and install some dependencies first (cmake, pidof, …) then it will download and build MariaDB on your mac.

It took around 7 minutes on my pc, so … go take a coffee :)

If this step finished successfully, congrats ! You have MariaDB running on your mac !

If not, type brew doctor and try to resolve all the problems before installing any package.

Now, type mysql to login. You’ll see something similar to this :

Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 5.5.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MySQL [(none)]>

Type status, you should see a message similar to this one :

mysql  Ver 15.1 Distrib 5.5.32-MariaDB, for osx10.6 (i386) using readline 5.1

You can now create new users, grant to them some privileges and start working.

If you’re running MariaDB on a production environment, type mysql_secure_installation and follow the instructions.

Git: Display the content of a deleted file

Sometimes, for some reason, you want to see the content of a file that you already deleted (and commited) but you don’t want to recover it.

To do that you will need two things :

  1. The last commit where the file was still there
  2. The full path of this file

and then you’ll just need to execute this cmd

git show commitID:path/to/the/file

PS: You can also get the full list of the files that you deleted in the working tree using this command

git log –diff-filter=D –summary

Circular Dependencies: Forcing Eclipse to compile projects

Circular Dependencies are bad, really bad, and you should fear them as much as you would fear wolves in a dark forest by a dark winter night !

But sometimes, you have no other choices, and you have to face them, at least temporarily. And in this case, if you use Eclipse, you’ll not be able to launch your application because your favorite IDE does not want to compile your projects.

But (because there’s always a but), you can force it to compile them by doing this simple manipulation:
Preferences -> Java -> Compiler -> Building -> And then set “Circular Dependencies” to “Warning

Now Eclipse should compile your workspace correctly.
And don’t forget to resolve the circular dependency ASAP.

Hope this will help someone someday.

Working with Django and client side frameworks using similar tags

If you’re developping in Django and want to use some client-side frameworks like Backbone.js or Angular.js, may be you are wondering how to mix both of these client and server side frameworks especially if they are using very similar tags as {{ tag }}.

The solution came with django 1.5 and its brand new verbatim tag. If you want to insert client-side framework tags inside your django templates, just surround your code like this :

{% verbatim %} Your jQuery.js/Backbone.js/Angular.js/SomethingElse.js code {% endverbatim %}

Et voilà !

If you’re using a previous version of django you can plug this django file in your project and do the exact same manipulation.

As said by Janos in the comment section, you can change the delimiters of the client-side framework if this one provide a way to do so. For example, in AngularJS you could try

myModule.config(function($interpolateProvider) {

more details here and here