Geekosopher

Yet Another Blog by Nitesh Mistry

Entries tagged "geekosophy"

Paste in to KDE Pastebin using Pastebinit
11th January 2011

First off, Wish you all a Very Happy New Year (that is the heights of laziness, you think?).

We all love chatting and collaborating on irc and pastebins are very usefull for sharing more than 3-5 lines of text as otherwise most channels consider it as flooding.

Almost all major projects including Debian and Ubuntu amongst others have their own pastebin utility. The latest to launch one was KDE.

There are also pastebin clients to help you send the files to the pastebins right from the CLI without needing you to launch the web browser, open the pastebin website, upload the file / copy-paste the contents in to the text box and then finally grab the url of your paste. One of such pastebin clients is Pastebinit.

Pastebinit is a very simple to use program written in Python. The irssi fans will appreciate the fact that they don't even need to leave the console. Simply give it the location of your file or make it read from stdin and specify the pastebin you want to use. It uploads the content of the file (or whatever was passed on to it) to the specified pastebin and gives you the url of the paste as the output. Now that's cool stuff! Isn't it?

How to get it? The tar ball is here. If you are Debian or Ubuntu user, simply give the following in the terminal:

sudo apt-get update; sudo apt-get install pastebinit


"Whats new? I am already a pastebinit fan!" - you say. Alright, so here is the 'new' part - How to use pastebinit to post to the KDE's newly launched pastebin?

As of now, pastebinit is not configured to post to paste.kde.org. So what? Just add the following text in a file and save it as paste.kde.org.conf

[pastebin]
basename = paste.kde.org
regexp = "http://paste.kde.org"

[format]
user = paste_user
format = paste_lang
content = paste_data
password = paste_password
expire = paste_expire
private = paste_private
api = api_submit
mode = mode
regexp = regexp

[defaults]
private = 0
format = "text"
expire = 86400
api = 1
mode = xml
regexp = "<id>(.*)</id>"

Now save this file[1] in /etc/pastebin.d/ directory (which is automatically created when installing pastebinit).

That is it and you are good to go. Test it - give the following command:
pastebinit -i <location of the file to share> -b http://paste.kde.org
and most probably it will print the url of the paste and return the prompt.

If you want to use the KDE pastebin by default, add the following line to your .bashrc or (as the case may be, .bash_aliases) file:

alias pastebinit='pastebinit -b http://paste.kde.org'

Now you do not need to give the -b http://paste.kde.org argument each time to paste to the KDE's pastebin.

Note - The above patch is already committed upstream. So the next time it is packaged, it will work with KDE pastebin service by default. But with all the doomsday predictions making rounds, why wait till then? :)

1 - Thanks to St├ęphane Graber for pointing out the missing 'regexp' lines.

Email comments to Nitesh Mistry   Tags: geekosophy, greetings, howto, kde, linux, pastebin.
Light Music - Internet Radio with mpg123
31st December 2010

Light music? No, I am not talking about any genre of music but about being light on your system while playing music.

Recently, I started playing (with) internet radio - one of the perks of having a unlimited broadband internet connection. Playing internet radio within the browser means managing one more window which needs to stay open all the while (constantly using around 100 MB of system memory), even if I am not browsing the web. So the other alternative is to give the url to your favourite gui music player to play. I use amarok for managing and playing locally stored music. It has a brilliant user interface to browse my music, manage playlists and all. But any modern graphical audio player also has a big memory foot-print (considering my poor 6 year old box) - grabbing almost 50-70 MB of RAM. And, since while playing internet radio, songs are automatically queued by the station, there is very little for me to tinker around, and the audio player usually stays minimised in the system tray.

Then why waste so much of resources when there is mpg123 to do the task. And it does the task really well. It runs from the terminal and still provides basic functionality (read man mpg123 for details). While it is playing, just check your system monitor; mgp123 rarely uses more than 700 KB of system memory (that is just 1% of what graphical audio players occupy) and it never shows up in the top 10 CPU users. As someone wisely said, "Frugal living is a virtue".

Wow! So how to go about it? Simple, run the following at the terminal:

sudo apt-get update; sudo apt-get install mpg123

To play internet radio with mpg123:

mpg123 <url of the radio station> &

For example, mpg123 http://205.188.215.226:8020/ & will play the classical guitar channel at sky.fm internet radio station.

To stop playing the music, just bring the process up giving fg command and interrupt it with ctrl-c or simply kill the process by giving killall mpg123 command.

Cool. Now enjoy the "light" music. ;)

Email comments to Nitesh Mistry   Tags: geekosophy, howto, internet, linux, mpg123, music, radio.
Redirecting to Other Website
13th November 2010

Yesterday, I gave this blog a website of its own. So now its address is http://blog.mistrynitesh.com instead of old http://www.mistrynitesh.com/blog. Creating a new site was very simple. As simple as opening a new email account, rather even more. With just 3 - 4 clicks, this blog had its spanking new website ready to shift in. Then it was just a matter of moving my blog contents to this new website and telling my DNS manager about its new address (follow this space on how did I get a new website and manage DNS). Also, getting a new website is as good as free because my webhost - NFSN - charges me only for the actual storage space and bandwidth used. So it is practically same as just transferring data to a new directory since my website is completely static.

So far so good. And then it hit me! What about the readers who are already following my blog? If they visit my old address, they will get 'Page Not Found' error. All those who have subscribed to my RSS feeds will no longer get the updates. Keeping the same content at both the places is not such an elegant solution. Neither does it do any good to search engine friendliness. So, how do I make the old visitors (who might directly visit my old address) go automatically to the new address?

".htaccess" To the Rescue!
Well, as I found out, there was no need to worry. If your webhost is using Apache webserver, this is just a two minute job. Apache webserver system provides a simple way to redirect a visitor to another website using a redirect directive in a .htaccess file. Oooo, sounds too geeky! Don't worry, it just sounds geeky. Actually you only have to create and save a file. So, create a text file named ".htaccess" and put the following line in that file

RedirectPermanent <old address> <new address>
For example, in my case the line was RedirectPermanent /blog http://blog.mistrynitesh.com (I did not need to write the old address completely; just the part which needs redirect). Save the file and close it. Now put this file in your public directory of webserver and you are good to go.

If you are even half as geeky as I am, you will definitely want to test this. So in your web-browser, type the old address and whoa, it automatically takes you to the new address! Another nice little thing I liked about this is, all the extra words and characters that are suffixed to the old address are automatically suffixed to the new address as well. Just to give you and example, I have a tag named 'linux' in my blog so to access it, the old address was http://www.mistrynitesh.com/blog/tags/linux which after putting this redirect, automatically goes to http://blog.mistrynitesh.com/tags/linux. And this applies to every link in the 'blog' directory.

Neat, isn't it?

Email comments to Nitesh Mistry   Tags: apache, geekosophy, howto, htaccess, redirect, website.
Computer as an Alarm Clock?
24th September 2010

We all like to wake up listening to good music instead of blaring noise of alarm clock or mobile phones. And, when it comes to sleep, if you are as much like Kumbhakarna as I am, chances are that you hit the snooze/stop button even without opening the eyes and sleep for another hour.

So I was always looking for a solution, where I could set my computer as an alarm clock, and play my favourite song or playlist to wake me up. This way I will have to get out of my bed and come to the desk to stop it, by which time I would have gained my senses. Similar question was also asked by someone in Mumbai Linux Users Group mailing list some time ago (I am not able to locate the exact thread right now).

But there was a two part problem in doing this:
One - I did not want to keep my computer switched on the whole night (you know how hip it is to be 'green' now-a-days); and
Two - How to play the songs without creating the security/privacy issue of making the computer log in to my user-space automatically.

But for linux users, no problem is too big to be solved.

First problem got solved when I came accross this great article by Mechatotoro. Until I read his post I was completely ignorant of a nifty feature residing in my computer's BIOS. To enter the BIOS settings, press DEL key (or depending on your computer make, F2 or F12 key) immediately after pressing the power button of the computer. On this white-and-blue screen, navigate to the Power Management Setup section. Now go to Resume by Alarm option and select Enabled. Set the day and time field immediately below that. Press F10 key and when prompted to save the settings press Y and Enter.

That is it and now the computer will automatically get powered on at the set day and time. Ofcourse I will need to keep the main power switch on, as I am using a desktop computer. No need to worry about this if you are using a laptop.

Now the second problem. One reason why I did not want to use Mechatotoro's solution as-it-is, was that, that involved setting up auto-login. How to play the songs without setting auto-login on the computer as it is a potential security and privacy hazard. Thankfully, most linux operating systems (including Ubuntu) have a nifty little feature named cron. Here all the users of the system can set up their own list of tasks to be executed automatically at the specified date and time. For example, fetching mails from the remote server every 5 minutes, or as in my case, play the specified song at a particular time of the day.

But using cron has a small little problem. While it can let any graphical audio players play the songs when the user is logged in, it cannot do so if the user is not logged in. In my case, since I would be asleep when the computer starts in the morning, I will not be able to feed in the password for my account to let cron play the songs. So I turned to my friends at Mumbai Linux Users Group for help and as expected, they pitch in right away. The problem it seemed was that, not all audio players can play songs without user being logged in. After many trials and errors, I was suggested to try mpg123, and it worked!

So here's how to put down the second problem:

Dan-te-naaaan! I am all set to wake up in the morning and do Pranayaam and Sudarshan Kriya. No more excuses.

Oh, but how do I stop the song?
Option 1 - Enter my password to log in to the computer > Fire up a terminal > type killall mpg123
Option 2 - Oh, I have a multimedia keyboard! So I just press the mute button.
Option 3 - Why should I stop it at all. Thats my favourite song, isn't it? I enjoy it while I brush my teeth and have morning cuppa.

So all you lazy bones, you have one less excuse to not get up in the morning.

Email comments to Nitesh Mistry   Tags: alarm, auto-power-on, bios, cron, geekosophy, howto, linux, mpg123.
Cloning Debian Installation
15th September 2010

There have been many times when I made a fresh installation of a Debian or Debian-based OS on a new computer or a different partition of my hard-disk and asked - how could I install all the other packages that I have installed on my main system in one go. Many answers involve remastersys, aptoncd, etcetera, etcetera. But they are helpful only when I want to install the same release of the distro. What if I upgraded my distro to the latest release? After every time I upgrade my system, I want to install all the packages that I had additionally installed on my older system.

The answer to this question always eluded me until recently when I read this article. And the solution was right there in my system itself, without the need for any external program. Not that I was completely ignorant of this solution, but I was not able to put it all together.

I am tempted to explain the whole thing here again, but the author of the original article has put it very descriptively. So I am going to only list the commands here:

Step 1 - On the system you want to copy from

sudo apt-get autoremove

Step 2 - Again on the system you want to copy from

dpkg --get-selections > installed-packages

A new file by the name of "installed-packages" will get saved in the home directory. Copy this file to the new system on which you want to install all the packages.

Step 3 - On the new system

sudo dpkg --set-selections < installed-packages
sudo apt-get dselect-upgrade

Note: Before you proceed with Step 3 - If the original system had some packages installed from third party repositories, add those repositories to the new system's /etc/apt/sources.list file. If you don't do this, those third party apps will not get installed. Also copy the /etc/apt/trusted.gpg file from the original system if you don't want to import gpg keys of all third party repositories from their websites.

That's it and you are done! Kewl B-)

Email comments to Nitesh Mistry   Tags: debian, dpkg, geekosophy, howto, install, linux.