Category Archives: Uncategorized

Converting a video to an mp3 via terminal

The days we had to remember dozens of ffmpeg flags has long gone. avconv is easy as easy could be.

sudo apt-get install ffmpeg libavcodec-extra-53 libav-tools

To convert video.mp4 to song.mp3, all you need to do is,

avconv -i video.mp4 audio.mp3

It’s so easy it just hurts. 😯

You can of course give avconv a dozen flags to tune the output to your will, but you just need a simple conversion 90% of the time.


K. Mandla writes on false:

In fact, it’s anything but helpful. It won’t take help flags. It does what it’s supposed to do, but does it unsuccessfully, every time.

Even the man page tells you that. What’s false? Every time, that’s what. Hardly helpful. Hardly useful. Just … false.

It must be really hard when people expect you to be unsuccessful. 😐

ACTUAL Vim in Sublime Text

ActualVim is a fucking brilliant project:

The goal is to use a hidden Vim instance to accurately manipulate a Sublime Text buffer as though you were editing the text directly in Vim. This has been accomplished.

It’s not simply a terminal emulator embedded in a text editor. Sublime is still in control of the text buffer. You will be able to use the entire native Sublime interface while in INSERT mode, including plugins.

IMNSHO, all Vim emulators suck. This freak of a project will surely make you feel you’re at home. Heck, you can use your complete Vim setup with this.

The only downside is (you saw this coming :twisted:), it does not work on Windows. On Linux or OS X you can simply use Vim itself, but the Windows version is ugly and Sublime is the best alternative out there. Perhaps I’m asking for too much. 😐

Anywho, this is wonderful news for Linux/OS X Sublime Text users out there.

Reading pdf files from the terminal with less

The good old less command can be used to open more than plain text files. All you need is to set the LESSPIPE environment variable to pipe the /usr/bin/lesspipe script in your .bashrc or .zshrc file. In most systems, the lesspipe script is pre-installed. Otherwise you can download it from here.

export LESSOPEN='|/usr/bin/lesspipe %s'

Now simply open your pdf files with less.

less abc.pdf

Besides from pdf files you can pipe in compressed files (like tar.gz, zip, rar, etc), ISO files and even .doc files. But who uses .doc files anyway? :mrgreen:

c for cat

An year-old tweet from @paul_irish:


Countdown timer shell script

I made a small countdown script for the shell. It goes as follows:

# ./countdown <num of seconds> <msg>
# eg:
# ./countdown 300 Time to rock!
date1=$((`date +%s` + $1));
while [ "$date1" -ne `date +%s` ]; do
echo -ne "$(date --date @$(($date1 - `date +%s` - 19800 )) +%H:%M:%S)\r";
notify-send 'Timer finished' "$*"
zenity --info --title "Timer finished" --text "$*"
view raw countdown hosted with ❤ by GitHub

Some tricks used in the script include:

  1. echo -ne "blah blah \r" was used to write in the same line over and over
  2. That 19800 is the time difference from GMT 0.0 in seconds. In Sri Lanka, it’s 5.30 hrs. Yes, we’re dealing with epoch time here, but still trying to figure out why we need to offset the time difference. 😕
  3. notify-send sends a desktop notification
  4. zenity --info pops up a message box

You can also add a sound to play with mplayer.

Resuming a failed scp transfer

Every now and then I scp some large files and the connection drops half way through. 😐 Thanks to rsync it’s pretty easy to resume the transfer.

rsync --partial --progress --rsh=ssh user@ip:remotepath localpath


--partial – this lets rsync know that it should keep the already downloaded partial files and download only the remainder
--progress – show the progress of the transfer
--rsh=ssh – use the ssh protocol
user@ip – remote machine. This might be the alias you’ve given it in your ssh config file.
remotepath – path to the file in the remote machine
localpath – path to the partially-downloaded local file

ShellCheck – static analyzer for shell scripts

Just came across ShellCheck. From its About page:

ShellCheck is a static analysis and linting tool for sh/bash scripts. It’s mainly focused on handling typical beginner and intermediate level syntax errors and pitfalls where the shell just gives a cryptic error message or strange behavior, but it also reports on a few more advanced issues where corner cases can cause delayed failures.

Interestingly, the tool’s completely written with Haskell. You can copy/paste the script on the site, or even install it so you can conveniently check shell scripts every now and then. You need cabal to have installed to compile the source. On Debian, you can install the package haskell-platform to install cabal.

Installing rupa/z

z is a command-line tool that would make jumping around your favorite directories much, much faster. It sits in the background and monitors where you cd to often, like a creep. 😯 And whenever you need to change to that ~/pictures/lol/cats directory, all you have to type in is z cats and you’ll be there. How it achieves this feat is by overriding the default cd‘s functionality with a custom shell function. Bad, bad z. 😈

Install rupa/z somewhere in your $PATH, say ~/bin.

cd ~/bin
curl -O
chmod +x

You might get a ‘no such file or directory’ error the first time, just ignore that. z works in both bash and zsh. You might need to add the source ~/bin/ line in your .bashrc or .zshrc so it starts up with your shell session.


Optionally, you can install the z man page as well. Jump to a directory in your MANPATH (you can find these using the command man -w) and download the man file.

cd /usr/local/man/man1
sudo curl -O

Reaching pi

This is old, but randomly came across this TeX FAQ which explains why the version numbering of TeX is reaching pi:

Knuth has declared that he will do no further development of TeX; he will continue to fix any bugs that are reported to him (though bugs are rare). This decision was made soon after TeX version 3.0 was released; at each bug-fix release the version number acquires one more digit, so that it tends to the limit π (at the time of writing, Knuth’s latest release is version 3.1415926). Knuth wants TeX to be frozen at version π when he dies; thereafter, no further changes may be made to Knuth’s source. (A similar rule is applied to Metafont; its version number tends to the limit e, and currently stands at 2.718281.)

Reaching π isn’t as easy as it sounds though. So many iterations and still you won’t be there. You can’t achieve perfection.