Importing Rhythombox playlist data

I have Rhythombox on all my work and personal work machines(laptops) and I keep my music in ~/Music folder. 25GB of music from here and there, last 10+ years of music. Lots of them rated. And when I have to change laptops I lose all my playlists. Not anymore. Rhythombox saves all its data in ~/.local/share/rhythmbox and I copied rhythmdb.xml to new machine. One would say, why not copy home directory. Well, why would I copy home directory when most of my items are either on Google Drive or browsers have already synced them. I just copy Music and Rhythombox data files and am good to go. Yey!!!

Fix “Error mounting: mount exited with exit code 13: $MFTMirr does not match $MFT (record 0).”

I was moving around 200+GB data from one WD external drive to another. Although the drives were connected to USB3 port the process was taking time. And I felt asleep and shutdown the system. Next day I connect hard drive and I see

Error mounting: mount exited with exit code 13: $MFTMirr does not match $MFT (record 0).

“Wut!” The complete text said.

Failed to mount ‘/dev/sdc1?: Input/output error NTFS is either inconsistent, or there is a hardware fault, or it’s a SoftRAID/FakeRAID hardware. In the first case run chkdsk /f on Windows then reboot into Windows twice. The usage of the /f parameter is very important! If the device is a SoftRAID/FakeRAID then first activate it and mount a different device under the /dev/mapper/ directory, (e.g. /dev/mapper/media_eahaabcc1). Please see the ‘dmraid’ documentationfor more details.

OK. But my Windows XP Centrino laptop will take ages to bootk and I do have “ntfs-3g” installed. May be it can fix this problem. And I could see these

ntfs-3g           ntfs-3g.secaudit  ntfscat           ntfscluster       ntfsdecrypt       ntfsfix           ntfsls            ntfsmove          ntfswipe          
ntfs-3g.probe     ntfs-3g.usermap   ntfsck            ntfscmp           ntfsdump_logfile  ntfsinfo          ntfsmftalloc      ntfstruncate

And we have ntfsfix utility!

sudo ntfsfix /dev/sdc1

Look for the success message and done!

How to remove blank lines from text files or php files or js files or…

By running this command…

egrep --include=*.php -lRZ "^$"  ./ | xargs -0 -l   sed -i -e '/^$/d'

Just two parts to it, search for all *.php files and use sed to replace new lines with nothing.

That’s all.

PyGTK Hello World or: How I learned to write my first GUI application on Ubuntu?

There are so many things I like about Ubuntu and I can write in extent about all those. My focus is in this post is Python. Python is easy to learn. So easy that one can write GUI apps in just 2 minutes. The title for the post has also indicated this(and is somewhat similar to Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb ). I am a learn by doing person and this post is for same kind of persons. So first the code, with very little or no explanation, shows a hello world widow:

Hello World using Python & PyGTK
Hello World using Python & PyGTK
#!/usr/bin/python

import pygtk
pygtk.require('2.0')
import gtk

class Whc:
	def __init__(self):
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.connect("destroy", self.destroy)
		self.window.set_title("Hello world!")
		self.label = gtk.Label("H3ll0 W0rld!")
		self.window.add(self.label)
		self.label.show()
		self.window.show()

	def destroy(self, widget, data=None):
		gtk.main_quit()

	def main(self):
		gtk.main()

if __name__ == "__main__":
	base = Whc()
	base.main()

…and then how I tweaked it

#!/usr/bin/python

import pygtk
pygtk.require('2.0')
import gtk
import os
import commands

class Whc:
	def __init__(self):
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.connect("destroy", self.destroy)
		self.window.set_title("Your \"fortune\"")
		self.window.set_default_size(200,100);
		f=commands.getoutput("fortune")
		self.label = gtk.Label(f)
		self.window.add(self.label)
		self.label.show()
		self.window.show()

	def destroy(self, widget, data=None):
		gtk.main_quit()

	def main(self):
		gtk.main()

if __name__ == "__main__":
	base = Whc()
	base.main()

…and then output

Displays a random fortune cookied in GUI
Displays a random fortune cookied in GUI

…and now the analysis. 🙂

The code given above uses PyGTK, GTK bindings for Python, GTK, OS and Command module. The OS and Command module is just to fetch the output of fortune command. fortune is a Linux command, more can be found here and may have to be installed, the package is fortune-mod. The Python code is plain English, create a TOPLEVEL window, see for more. In the first code listing another GTK widget Label has been added. The Label contains a snippet of readonly text rendered on Window and in first snippet the text string is legendary, “H3ll0 W0rld!” in L33T. The string in 2nd code snippet is replaced by output of fortune command for which I utilised command and os modules. Easy!!!

This post was lying in drafts for more than 15 months.

Python httplib example

This is a very simple example of httplib in Python. I am trying to write a very simple client which can simply ping a URL.

import httplib
while True:
 myURL = raw_input('\nURL Please: \n> ')
 if myURL == '':
 print '\URL Please: \n'
 break
httpconnection = httplib.HTTPConnection(myURL)
httpconnection.request('GET', '/')
res = httpconnection.getresponse()
#I am only interested in 200 OK response, anything else can be ignored
if res.status != 200:
 print 'Errr!!!!', myURL, 'seems to be a troublesome URL. The "Internet" says "', res.reason, '" and the status was', res.status, '. Try again.'
else:
 data = res.read()
 allheaders = res.getheaders()
 print data