I Love Twitter, I Love Python = I Love Twython

I was really late to join Twitter. As soon as I joined Twitter, I started exploring various aspects of Twitter and hence the Twitter API. While searching for a wrapper for Twitter API in python, I came across python-twitter which was good and tweepy which was ok and I finally found twython. Twython is awesome and more importantly upto date with Twitter API.

While I was using twython, I found one fact very irritating. It didn’t have docstrings. And I had to go to Twitter API Wiki for description of every single function ๐Ÿ™ I talked to Ryan (Twython developer, who works all day long at his day job with webs.com and develops twython when everybody sleeps ๐Ÿ˜› ) about the same and offered to write docstrings for twython.

I spent a few hours and sent a patch with docstrings for all the functions. Now twython has complete documentation. Also Ryan is trying his best to implement wrappers for the newly introduced functions in Twitter API. So, currently Twython is THE best wrapper available in python for Twitter API.

PS : Next post will be “How to use twython”.

 

How To: Recover Deleted Files in Linux Using Photorec

Frequently I get messages like “I have accidentally deleted my project. Is there any way to recover it in Linux?” or “I worked really hard on that program and managed to deleted it right before submission ๐Ÿ™ How do I recover?”. Well I didn’t really have any idea on “How to actually recover deleted files in Linux”.

A few days back I was designing the new logo for Videocache in Inkscape. After finishing the design, I saved the svg file carefully. And deleted other images which I embedded in the logo. A few moments later I realized that I just screwed up myself by deleting all those files as the svg file is now good for nothing.

I searched a lot on recovering files in Linux but in vain. Then a friend (bitgeek) told me about Photorec. I managed to recover all the files using photorec. I thought it would be a good idea to let others know and spread a good word about Photorec. Below is a step by step howto on using Photorec to recover your files.

What is Photorec?

From Photorec website,

PhotoRec is file data recovery software designed to recover lost files including video, documents and archives from Hard Disks and CDRom and lost pictures (thus, its ‘Photo Recovery’ name) from digital camera memory. PhotoRec ignores the filesystem and goes after the underlying data, so it will still work even if your media’s filesystem has been severely damaged or re-formatted.

For This HowTo

Lets say I had a file download_arrow.png in /home/saini/Desktop which I have removed accidentally. Login as root and create a directory recover which will be used to store all the recovered files.

Install testdisk/PhotoRec

Photorec comes as a part of testdisk package in Fedora (I hope its same for other distributions as well). Use yum to install testdisk.

[root@fedora-tips ~]$ yum install testdisk

Launch Photorec

Once you are done with installation. Open a terminal and launch photorec (as root).

[root@fedora-tips recover]$ photorec

Select Hard Disk

If you have more than one hard disk in your system, select the one from which you have deleted the file(s).

PhotoRec Hard Disk Selection

Select Partition Type

If your hard disk has Linux partitions, then select [Intel].

PhotoRec Partition Selection

Select Filetype Option

Move to [File Opt] and press enter. Here you can disable all file types by pressing ‘s’ . Use space to toggle the check button. Now since we removed a png file, we are going to check only png file type.

PhotoRec Filetype Selection

Select Options

Photorec also has a list of different options. Under normal circumstances you don’t need to modify them

PhotoRec Option Selection

Select Partition

Move the selector to the partition from which you have removed the file. Then press enter on search.

PhotoRec Partition Selection

Select Filesystem Type

If you are using Linux, its going to be ext2/ext3/ext4. So the default selection is file.

PhotoRec Partition Selection

Select Space for Analysis

Select free if you didn’t write to that partition after removing the particular file otherwise select whole.

PhotoRec Space Selection

Select a Directory to Recover Files

Now select the path where the recovered files will be stored. Then press ‘Y’.

PhotoRec Recovery Directory Selection

Recovery Progress

Photorec will show how many files it has recovered.

PhotoRec Recovery Progress

All recovered file will be stored in the directory selected above. Open them in a file browser and you’ll get the removed file there. I hope this howto will help you recovering files you accidentally delete ๐Ÿ™‚

 

How To: Install ATI Catalyst (fglrx) Drivers

Note: This How To is valid up to Catalyst Driver version 10.1.
Note: With minor changes this How To may work for other Linux distributions like Mandriva, Suse, Ubuntu, Red Hat, Cent OS etc.

Following the suggestions in comments on my last post about ATI Catalyst (fglrx), I tried to reinstall ATI drivers version 9.8 and finally it worked. I thought of noting down the the process in few simple steps which anyone can follow and get the drivers working on Fedora 11 with latest kernel versions.

Step 1 : Update Kernel, Install kernel-devel

Huge thanks to Richard Lloyd and mxyzptlk2063 for pointing this out.
This step is not necessary. You may like to stick to the kernel version you already have. In case you want the latest kernel, just use yum to get the latest kernel.

Note: Do not forget to update the kernel-devel package as well as its needed to compile the fglrx kernel module.

DONT UPDATE THE KERNEL. Instead stick to whatever kernel version you have. If you have 2.6.30.*, you are unlucky ๐Ÿ™ Get a kernel version 2.6.29.* and install the kernel-devel for the same.

With Catalyst Driver version 9.10 you can update kernel to latest version before installing the Drivers.

[root@fedora ~]$ yum update kernel
[root@fedora ~]$ yum install kernel-devel

Step 2 : Download Drivers

Download the ATI Catalystโ„ข 9.8 Proprietary Linux x86 Display Driver from ATI/AMD website.

Step 3 : Install Drivers

Install the drivers that you have downloaded using the following command.

[root@fedora ~]$ bash ./ati-driver-installer-9-8-x86.x86_64.run

Step 4 : Check Installation Result

Check the /usr/share/ati/fglrx-install.log file for result of installation. If there are no errors, proceed to the next step.

Note: You may see lines like this at the end of file

You must change your working directory to /lib/modules/fglrx
and then call ./make_install.sh in order to install the built module.
– recreating module dependency list
– trying a sample load of the kernel modules
done.

You can ignore these lines happily if they don’t contain any error message. You don’t really need to execute the command mentioned in those lines.

Step 5 : Blacklist radeon and radeonhd kernel modules

Add these lines to /etc/modprobe.d/blacklist.conf.

blacklist radeon
blacklist radeonhd

Step 6 : Generate initial Xorg configuration file

Note: This step is optional with Catalyst Driver version 9.10, but it wont harm even if you execute this.

You have to generate the initial xorg.conf file which will use fglrx as display device.

[root@fedora ~]$ aticonfig --initial

Step 7 : Modify xorg.conf

Open your /etc/X11/xorg.conf file and add the following line to “Device” section (the one with fglrx as driver)

Option "SWCursor" "true"

Step 8 : Reboot

Reboot your machine. And you’ll have the latest ATI Catalyst drivers working on your Fedora 11 ๐Ÿ™‚

Step 9 : Testing

You can test your newly installed drivers and get the performance benchmarks for your graphics card using the commands below.

[saini@fedora ~]$ glxgears
[saini@fedora ~]$ fgl_glxgears

My graphics card is ATI Radeon HD 3200 (256MB, Onboard) and I get 1500FPS with glxgears and 300FPS with fgl_glxgears.

In case you messup things somewhere, you can uninstall the fglrx drivers using the following command

[root@fedora ~]$ /usr/share/ati/fglrx-uninstall.sh
 

Info: ATI Drivers 9.8 Doesnt Work with Fedora 11 (2.6.29+)

After a night out I was about to go to bed when I saw the news that ATI has released a new version of ATI Catalystโ„ข 9.8 Proprietary Linux x86 Display Driver, its proprietary display drivers for Linux. I immediately downloaded the drivers to test with my Fedora 11 as I am getting more and more desperate to watch HD Movies ๐Ÿ˜ Installed them on a manually compiled kernel 2.6.27 and the build failed ๐Ÿ™ Installed the latest kernel version (for fedora 11) 2.6.29.6.xxx and build failed yet another time. Switched back to 2.6.27 and tried to build again. This time build was successful. Everything worked as expected. I was getting 1500FPS with glxgears and 300FPS with fgl_glxgears. But after sometime display hanged inturn freezing the system. Hard reboot was the only solution and then this happened for a few times in a row. Now, I am back to radeonhd, waiting for yet another release of ATI drivers so that I can try them yet another time to see yet another failure ๐Ÿ™

Update : Drivers are working now. Move on to How To: Install ATI Catalyst (fglrx) 9.8 Drivers on Fedora 11.

 

TIP: Simple Regular Expression for Email Validation

I was playing around with Ruby on Rails and needed an email field for some application. I thought of validating the email address before actually saving it. Googled for same and got tons of results, but none of them was perfect. Few were somewhat exhaustive but horribly difficult to understand and those which were simple wereย  not exhaustive enough for practical use. I thought I’ll just write the regex myself and came up with the following. I have tested it for few weird cases like an email hosted on a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.exmaple.com (a subdomain deep down the hierarchy) etc.

^[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+\.)+([A-Za-z0-9]{2,4}|museum)$

I hope it’ll be of help. And don’t forget to pen down your suggestions via comments.