ZSH - command not found

If you use ZSH and want the well known “command not found” feature, you simply have to add source /etc/zsh_command_not_found in your ~/.zshrc. If it’s not installed at all: aptitude install command-not-found.

If you don’t know what “command not found” does, here is an example:

% play
The program 'play' is currently not installed. You can install it by typing:
sudo apt-get install sox
zsh: command not found: play

It tells you in which package you’ll find a specific command when you type it and it’s not installed. How great is that?

Hack Day Paris

I should have written this post 6 months ago! Hack Day Paris was an event that took place in Paris in November, 2011.

Hack Day Paris is a 40-hour marathon of hyper-intensive design and development followed by a lighting round of presentations and demos. The result is the exchange of ideas, community, and invention not realized during the normal pace of work and play.

The motto was “Come build something brilliant.”

365 days on canvas

Another long term project! This one will last, you guessed it, one year.

No, that’s not true, I will probably give up in a few weeks. I’ve tried taking photographs everyday but I stopped at 80. I’ve tried writing everyday (750 Words) and it lasted only 11 days.

So, I’m bad at projects that require that I work on them everyday. Should I stop? Hell, no!

What’s 365 days on canvas?

I’m sure you get the “365 days” part so let’s focus on the canvas part. <canvas> is an HTML tag that allows you to draw with JavaScript code. You can draw shapes, lines, text and other images. If you redraw the canvas several times per second, you have an animation. That’s what I’ll be doing in this project. I’ll be drawing stuff and animating it. Probably interactive animated stuff.

There is no goal. I will work on my canvas every day, twenty minutes a day. I’ll post weekly updates, with the work of the seven previous days. At some point, hopefully before the end of the year, I’ll build some app that will allow you to browse easily all these canvases and all this code.

I won’t have 365 great ideas so I encourage you to tell me in the comments where you want this project to go.

365 * (1 idea + 20 minutes) == guaranted fun!

The first seven days are here!

A node program that is also a shell script

Here is the code with a JavaScript syntax highlighter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

#!/bin/sh
true /* ignored by js

if which node > /dev/null; then
this_file=$(readlink -f $0)
exec node $this_file
else
echo You must install node to run this program
fi

exit 0
ignored by sh
*/


console.log('i am in node');

and with a Shell syntax highlighter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

#!/bin/sh
true /* ignored by js

if which node > /dev/null; then
this_file=$(readlink -f $0)
exec node $this_file
else
echo You must install node to run this program
fi

exit 0
ignored by sh
*/

console.log('i am in node');

How does it work?

It’s a shell script. Check the first line. #!/bin/sh tells the system to execute this file with /bin/sh.

Near the end, there’s a exit 0 statement. It ends the script shell. /bin/sh won’t read what’s after this line. So it can be JavaScript.

Now, we want this file to be a valid NodeJS file. The first line will be ignored since it’s the shebang. We have to comment the shell code between /* */. A line can’t start with a /* since it’s not a valid shell command. We need some code that works in both language.

true is perfect for that purpose. In shell, it’s just a command that always succeeds and ignores any parameters. In JS, it’s the true keyword.

true /* opens the JS comment block and is valid in both languages. Finally, we can close the block with a simple */ since we do it after the exit 0.

What’s the point?

In the example it’s used to check if node is installed. You could even install it if it’s not there. If it’s installed, it simply executes node with the current file as first parameter.

But mostly, it was fun to write.