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.

July 27, 2014

ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ്

 
ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ്  ഉപയോഗിക്കാൻ തുടങ്ങിയതുമുതൽ അതിനെക്കുറിച്ച് എഴുതണമെന്നു കരുതിയതാണ്. വിക്കിപീഡിയ പോലെ ആർക്കും എഡിറ്റ് ചെയ്യാവുന്ന ഒരു മാപ് ആണ് ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ്. ആ വിവരങ്ങൾ എങ്ങനെയെല്ലാം ഉപയോഗിക്കാം എന്നുള്ളതിനെക്കുറിച്ചാണ് ഇവിടെ പറയാൻ പോകുന്നത്.

http://www.openstreetmap.org അല്ലെങ്കിൽ  http://osm.org ഉപയോഗിച്ച് ഓപ്പൺ സ്റ്റ്രീറ്റ് മാപ് സൈറ്റിലേക്ക് പോകാൻ പറ്റും. ഈ സൈറ്റ് പ്രധാനമായും മാപ് എഡിറ്റ് ചെയ്യാനും, ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ് എങ്ങനെ ഉപയോഗിക്കാം എന്നുള്ള ഒരു ഉദാഹരണവുമാണ്. അക്കാരണത്താൽ മറ്റേതെങ്കിലും മാപ്പ് ഉപയോഗിക്കുന്നതുപോലെ ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ് സൈറ്റ് ഉപയോഗിക്കാൻ ശ്രമിച്ചാൽ ചിലപ്പോൾ നിങ്ങൾ നിരാശരായേക്കും. അപ്പോൾ പിന്നെ ഇതെങ്ങനെ ഉപയോഗിക്കാം എന്നുള്ള ചോദ്യം വരും. അവിടെയാണ് ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ്പിന്റെ ശരിക്കുള്ള ഗുണം വരുന്നത്. ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ്പിലെ വിവരങ്ങൾ വളരെ ലളിതമായ ലൈസൻസിൽ ലഭ്യമാണ്. അതുപയോഗിച്ചിട്ടുള്ള വളരെയധികം സർവീസുകളും ലഭ്യമാണ്.

ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ്പിലെ ഡേറ്റ, സന്നദ്ധപ്രവർത്തകർ ചേർക്കുന്നതുകൊണ്ട് മിക്കവാറും ശരിയായിരിക്കാനാണ് സാധ്യത. എന്നിരുന്നാലും ചില സ്ഥലങ്ങളിലെ കവറേജ് മറ്റു മാപ്പുകളെപ്പോലെ പൂർണ്ണമായെന്നിരിക്കില്ല. അതിനാൽ മറ്റേതു സർവീസും ഉപയോഗിക്കുമ്പോഴെടുക്കുന്ന മുൻകരുതലുകൾ ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ്പ് ഉപയോഗിക്കുമ്പോഴും എടുക്കേണ്ടതാണ്.

ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ്/ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ് ഡാറ്റ ഉപയോഗിച്ച് എന്തെല്ലാം മാപ് സർവീസുകൾ ലഭ്യമാണെന്നു നോക്കാം.

നാവിഗേഷൻ
OsmAnd : https://play.google.com/store/apps/details?id=net.osmand
ഓഫ്‌‌ലൈൻ മാപ് സൗകര്യമുള്ള നല്ലൊരു ആൻഡ്രോയ്ഡ് ആപ്ലിക്കേഷനാണിത്. ആവശ്യമുള്ള രാജ്യത്തിന്റെ മാപ് ഡൗൺലോഡ് ചെയ്താൽ ഡേറ്റാ കണക്ഷനില്ലാതെ ഈ ആപ്പുപയോഗിച്ച് നാവിഗേറ്റ് ചെയ്യാം. ഇന്ത്യൻ മാപ് ഏകദേശം 200 എംബിയോളം വരും. പത്തു മാപ്പുകൾ മാത്രമേ ഫ്രീ വെർഷനിൽ ഡൗൺലോഡ് ചെയ്യാൻ പറ്റൂ എന്നൊരു പ്രശ്നമുണ്ട്. ഇതുപയോഗിക്കുന്നതെങ്ങനെ എന്നു വിശദമാക്കുന്ന നല്ലൊരു ബ്ലോഗ് എന്റ്രി ഇവിടെ ഉണ്ട് :https://joostschouppe.wordpress.com/2014/07/25/using-osmand-on-the-road/

navfree : https://play.google.com/store/apps/details?id=com.navfree.android.OSM.ALL
OsmAnd പോലെ ഓഫ്‌‌ലൈൻ നാവിഗേഷൻ ഉപയോഗിക്കാവുന്ന മറ്റൊരാപ്ലിക്കേഷനാണിത്. ഇതും ഓപ്പൺസ്റ്റ്രീറ്റ് മാപ്പിൽ നിന്നുള്ള ഡേറ്റയാണുപയോഗിക്കുന്നത്. കഴിഞ്ഞ ഒന്നു രണ്ടു വർഷമായി ഞാൻ ഇതുപയോഗിക്കാറില്ലാത്തതിനാൽ കൂടുതൽ വിവരങ്ങൾ പറയാനില്ല.

ഓൺലൈനിൽ റൂട്ടിങിനു വേണ്ടി http://map.project-osrm.org/,http://open.mapquest.com/ എന്നീ സൈറ്റുകൾ ഉപയോഗിക്കാവുന്നതാണ്.

ഓപ്പൺസ്റ്റ്രീറ്റ് മാപ്പിൽ നിന്നുള്ള ഡേറ്റ ഉപയോഗിച്ച് പല തരം സർവീസുകളും ലഭ്യമാണ്. ചിലത് ഇവിടെ വിവരിക്കുന്നു.

പ്രിന്റഡ് മാപ്പുകൾ
http://fieldpapers.org/ എന്ന സൈറ്റിൽ നിന്ന് ആവശ്യമുള്ള പ്രദേശങ്ങളുടെ മാപ് നമുക്കുതന്നെ സെലക്റ്റ് ചെയ്ത് പിഡിഎഫ് ഫയൽ ആയി ഡൗൺലോഡ് ചെയ്യാൻ പറ്റും.  ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ് സൈറ്റിൽ നിന്നു തന്നെ മാപ്പുകൾ jpg/png/pdf/svg ഫോർമാറ്റുകളിൽ എക്സ്പോർട്ട് ചെയ്യാനുള്ള സൗകര്യമുണ്ടെങ്കിലും സെർവർ ലോഡ് അധികമാണെങ്കിൽ റിക്വസ്റ്റ് റിജക്റ്റ് ചെയ്യപ്പെടാനുള്ള സാധ്യതയുണ്ട്. അതിനാൽ fieldpapers.org ൽ നിന്നും മാപ്പുകൾ എടുക്കുന്നതാകും സൗകര്യം.

മാപ് സെർച്ച്
നേരത്തേ സൂചിപ്പിച്ചതുപോലെ ഓപ്പൺസ്റ്റ്രീറ്റ് സൈറ്റിന്റെ ഉദ്ദേശം മാപ് എഡിറ്റിങ്ങും മറ്റുമായതിനാൽ എല്ലാത്തരം വിവരങ്ങളും ആ സൈറ്റിൽ കാണാൻ പറ്റില്ല. മാത്രവുമല്ല അവിടെ സെർച്ച് ചെയ്യുന്നതും അത്ര സുഖമുള്ള പരിപാടിയല്ല. അങ്ങനെയുള്ള ആവശ്യങ്ങൾക്കായി ഉപയോഗിക്കാവുന്ന ചില സൈറ്റുകളാണ് http://www.openstreetbrowser.org/, http://osm24.eu,http://www.lenz-online.de/cgi-bin/osmpoi/osmpoi.pl എന്നിവ.

മറ്റു സർവീസുകൾ
http://www.openrailwaymap.org/ : റെയിൽ മാപ്പുകൾ.
http://openfiremap.org/ : ഫയർ സ്റ്റേഷനുകൾ, ഫയർ ഹൈഡ്രന്റ് എന്നിവയുടെ സ്ഥാനം അടയാളപ്പെടുത്തിയിട്ടുള്ള മാപ്.
http://openbeermap.github.io/ : പബ്, ഷാപ്പ് എന്നിവ കാണിക്കാൻ വേണ്ടിയുള്ള മാപ്.
http://waymarkedtrails.org/en/ : ഹൈക്കിങ് ട്രെയ്‌‌ലുകൾ

ഇത്രയും പറഞ്ഞ സ്ഥിതിക്ക് ഇതിൽ കുന്നംകുളത്തിന്റെ മാപ്പുണ്ടോ എന്ന ചോദ്യത്തിനും ഉത്തരം തരേണ്ടത് ആവശ്യമാണല്ലോ. കുന്നംകുളത്തിന്റെ മാപ്പുണ്ട്, പക്ഷേ പല വിവരങ്ങളും അതിൽ ഇതുവരെ ലഭ്യമല്ല. കുന്നംകുളത്തിന്റെ വിവരങ്ങൾ ഓപ്പൺസ്റ്റ്രീറ്റ്മാപ്പിൽ ചേർക്കാൻ താല്പര്യമുണ്ടെങ്കിൽ http://learnosm.org/en/ എന്ന സൈറ്റിൽ പോയാൽ വിവരങ്ങൾ ഓപ്പൺസ്റ്റ്രീറ്റ് മാപ്പിൽ എങ്ങനെ ചേർക്കാം എന്നു മനസ്സിലാക്കാം.

July 22, 2014

JOSM Preset Builder

I was trying to build some presets for JOSM (https://josm.openstreetmap.de/) few days back and thought it would be a good idea to automate the process. Read the some documentation that was available from http://josm.openstreetmap.de/wiki/TaggingPresets. The defaultpresets.xml contained in the JOSM package gave some very useful information in writing the script.

The idea was to have a text file with the preset data and generate the XML file using a script. I finally settled on a pipe separated file format with embedded key value pairs. When finished, it could generate presets with key value pairs, drop downs and lists.

The scripts and sample files are released under GPLv3 and available at https://github.com/primejyothi/JOSMPresetBuilder

Hope someone will find it useful.

May 14, 2014

Changing starting index of tmux panes

I use the bind key + q combination to quickly switch between tmux panes. I use ctrl + a as the bind key and I found it bit of troublesome to press 0 to switch to the first pane as 0 is at the right side of the keyboard. If the pane index started with 1, it would be much easier to select from 1 onward and won't have to go all the way to zero. Fortunately there is an option for that. Set pane-base-index to 1 and the pane index will start from 1. All that need is the following entry in the ~/.tmux.conf


set -g pane-base-index 1

tmux pane index starting with 1
As you can see from this screen shot, the pane index now starts with 1.