January 3, 2016

chequePrint : Linux utility to print into cheques

The problem : As I do not write much on paper these days, writing cheques will cause some cheque leaves go waste. Earlier I had created a template in LibreOffice to solve the problem. However, I could not use that template as it was for a different bank. It was too difficult to get the alignment correct as there were boxes for days, month & year.

Solution : Write a script! Initially considered generating TeX files but zeroed in on PostScript as it would be easy to do the layout.
The script is available in the chequePrint GitHub repo.

August 9, 2015

syncReaders: Linux utility to synchronize Calibre & CoolReader database

I use the coolReader in my Android phone and tablet to read e-books. The e-books are managed in my Linux system using Calibre. One of the problem I had was that it was difficult to maintain the ratings and read status of the books across the three devices. Manually updating the ratings and read status was not practical. Since I go by "Machines should work and men should enjoy", some time ago I ventured into writing a program to synchronize the status and read status in both applications. I have been using the utility for a while and serves my purpose. The downside is that the database files of the applications have to be manually copied to Linux system for synchronization and then copy back to respective devices manually.

The source code for syncReaders is available here : https://github.com/primejyothi/syncReaders

December 3, 2014

ഷെൽ ബ്രേസ് എക്സ്പാൻഷൻ

ഒന്നിലധികം അക്ഷരങ്ങളോ വാക്കുകളോ കൂട്ടിച്ചേർത്ത് പുതിയ സ്റ്റ്രിങ്ങുകൾ നി‌‌ർമ്മിക്കാൻ പറ്റിയ ഒരു ഉപാധിയാണ് ഷെല്ലിലെ ബ്രേസ് എക്സ്പാൻഷൻ. ഉദാഹരണത്തിന് a,b എന്നീ അക്ഷരങ്ങൾ ആദ്യവും c, d എന്നീ അക്ഷരങ്ങൾ രണ്ടാമതും വരുന്ന 2 അക്ഷരങ്ങളുള്ള വാക്കുകൾ ഉണ്ടാക്കാൻ {a,b}{c,d} എന്ന എക്സ്പ്രഷൻ ഉപയോഗിക്കാം.
echo {a,b}{c,d}
ac ad bc bd
ഇംഗ്ലീഷ് അക്ഷരമാല മുഴുവൻ പ്രിന്റ് ചെയ്യണമെങ്കിൽ ഇരുപത്താറക്ഷരങ്ങളും ടൈപ്പ് ചെയ്യുന്നതിനുപകരം {a..z} എന്നു കൊടുത്താൽ മതി.
echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
echo {a..z}{a..z} എന്നു കൊടുത്താൽ aa മുതൽ zz വരെ പ്രിന്റ് ചെയ്യും
echo {1,2}{a..z}{a..z} എന്നത് 1aa..1zz,2aa...2zz എന്നും പ്രിന്റ് ചെയ്യപ്പെടും.
ബ്രേസ് എക്സ്പാൻഷൻ കാര്യങ്ങൾ എങ്ങനെ എളുപ്പമാക്കുന്നെന്നു കാണാൻ മറ്റൊരുദാഹരണം പറയാം. 2000 മുതൽ 2014 വരെയുള്ള മാസങ്ങളുടെ പേരിൽ 2000_jan, 2000_feb എന്നിങ്ങനെ ഫോൾഡറുകൾ ഉണ്ടാക്കണമെന്നു കരുതുക. നൂറ്റി എൺപതു ഫോൾഡറുകളുടേ പേരുകൾ ഒന്നൊന്നായി ടൈപ്പ് ചെയ്യുന്നതിനുപകരം
mkdir {2000..2014}_{jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec}
എന്നു കൊടുത്താൽ മതിയാകും.
ഇനി 2000 മുതൽ 2014 വരെ നാലു വർഷങ്ങൾ ഇടവിട്ടുള്ളവയാണു വേണ്ടതെങ്കിൽ {2000..2014..4}_{jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec} എന്ന് എക്സ്പ്രഷനുപയോഗിക്കാം.
അക്കങ്ങൾക്കു പകരം അക്ഷരങ്ങളിൽ ..4 എന്നു കൊടുത്താൽ നാല് അക്ഷരങ്ങൾ ഇടവിട്ട് പ്രിന്റ് ചെയ്യും. ഉദാ : echo {a..z..4} എന്നത് a e i m q u y എന്നു പ്രിന്റ് ചെയ്യും

August 17, 2014

Up!

Like many other scripts, the bash shell function "up" is a by product of my laziness. As the name vaguely indicates, it can move you up in the directory tree. If you want to move 3 levels up in the directory tree, you invoke the function as up 3 instead of cd ../../../  which saves a ton of typing. The shell function can be downloaded from my GitHub repo. 

# Go n level up in the directory structure.
# License : GPLv3
function up ()
{
        lvls=""
        if [[ ! -z "$1" ]]
        then
                for i in `seq $1`
                do
                        lvls="${lvls}../"
                done
        else
                lvls="../"
        fi

        # Will land up in / if n is too large.
        cd ${lvls}
        pwd
}


The ShellUtils repo contains few other shell scripts that might be interesting. See the Readme file in the repo to find out what those scripts are doing.

August 2, 2014

Dbus-MPRIS Music Player Controller

The Short story :
Here is a shell script that can control media players like Amarok, Clementine, mpd & VLC : https://github.com/primejyothi/Dbus-MPRIS-MusicPlayer-Controller

The long story :
Like most of the programmers, I'm a big fan of command line. Since I can touch type, things get done really faster. There will be a music player running in my system and most of the time I will be using mpd with ncmpcpp. Only problem is that I keep forget which key is used to stop/pause ncmpcpp. This problem was quickly resolved by installing mpc and few aliases. Things were pretty fine and I even wrote a script (https://github.com/primejyothi/ShellUtils/blob/master/mpdLyrics.sh) to extract the album art of the song being played in mpd and show it on Conky .

Problems cropped up when Amarok or Clementine were used. The controls were on top for Amarok and in case of Clementine it was just opposite. I could use the media keys in the keyboard, but I hardly use them as mpd does not respond to them. The search of consistency ended with MPRIS. Quickly put together a script and any of these media players could be controlled with a single script. Few aliases and I can control the media player without leaving vim :)

For VLC and mpd, MPRIS need to be enabled manually. The VLC player need to be started as vlc --control dbus. In case of mpd, mpDris2 need to be running.