Blog is moving

My blog is moving to http://victormendonca.com/blog/. If you are looking for a specific or older post you are in the right place Otherwise check out my new page for more up to date content.

Sunday, March 29, 2009

Getting daily tips for bash


I still consider my self a new Linux user and a noobie. One of the things that I strive to learn is scripting in bash, but I do have difficulties as I have no programing background, so I try to read and get as much help as I can.

During my searches on the web I found a very interesting twitter profile for the author of “O'Reilly's Bash Cookbook”. He has daily updates with interesting bash tips, which I have found very useful.

So today I'll be providing a function script that can be added to your ~/.bashrc and used as either a command or a welcome message for you terminal emulator. This script will go to the twitter profile of “Bash cookbook” and download their daily content.

The script is compatible with links and elinks (Red Hat) for downloading the content. It creates 3 environment variables on your system to hold links version, last update and downloaded content.

Open you ~./bashrc with your favourite text editor and paste the lines bellow:
bash_tips ()
{
# checks for version of links
if [ -z "$LINKS_VERSION" ] ; then
export LINKS_VERSION=$(links -version | grep Links | cut -f1 -d" ")
fi

# checks variable that holds last update time
if [ "$BASH_TIPS_DATE" != $(date "+%d") ] ; then
export BASH_TIPS_DATE=$(date "+%d")
if [ "$LINKS_VERSION" = "ELinks" ] ; then
# script for ELinks
export BASH_TIPS=$(links -dump -dump-width 300 http://twitter.com/bashcookbook | egrep '^ *1\. [^http]' | sed 's/^ *//g')
else # script for Links
export BASH_TIPS=$(links -dump -width 300 http://twitter.com/bashcookbook | egrep '^ *1\. [^http]' | sed 's/^ *//g')
fi
fi

echo -e "\n## Today's bash tips ##\n$BASH_TIPS"
}

If you want to have the daily tips displayed when you open a terminal emulator, just add “bash_tips” to your ~/.bashrc.

This is what they will look like:
victux ~ $ bash_tips

## Today's bash tips ##
1. Using += on an array assignment adds new elements to the array. If RA has element 0-6 then RA+=(new elems) creates RA[7] and RA[8].10:24 PM Mar 27th from Identica


Book:
http://oreilly.com/catalog/9780596526788/
Twitter site:
http://twitter.com/bashcookbook
Official site:
http://www.bashcookbook.com/

Thursday, March 26, 2009

How to highlight pdf files on Linux and Windows machines


Two annoyances that I have always had with ebooks and pdf material is that when I'm reading I like to highlight important info for future reference. Most readers (like Adobe) only allows you to highlight files that you have document rights to it, which I don't think makes any sense.

The other problem is that I read the same book between multiple computers and multiple platforms. I always have to write down the page I read last, and this is a bit annoying.

After doing a lot of searches I was finally able to find a pdf reader (PDF-XChange Viewer) that allows me to highlight text and save that information. Even better, they have a portable version so you can have the book, program and saved data (highlight and page) on a USB device and access it between machines.

For my utmost surprise the program works under wine and also reads the saved data.

Hot to get it working

1- Download the portable version of the program and unzip it to your flash device (either on Linux or Windows)

http://www.docu-track.com/download/PDFX_Vwr_Port.zip

2- Install wine on your Linux machine if you have not already done so

# Ubuntu (8.10)
$ sudo aptitude install wine
$ winecfg

3- Create a script in the flash drive within the program folder to open the program on Linux

$ echo -e '#!/bin/bash\n\nwine PDXCview.exe &' > PDFXCview_for_Linux

You should now be able to open the program on either Windows or Linux and see your highlighted text.