Posts

Get redirected url from response object - treq (twisted)

treq follows page redirects (by default) like how a browser does. So, no extra work needed here. But at times, we might need to know from where actually we got the response from. Unlike python-request library, the treq/twisted response object doesn't have the 'url' attribute which contains the redirected url. But fortunately response object (in Twisted > 13.1.0 ) have 'previousResponse' attributes, from which we get the redirected url as below. #!/bin/env python     __author__ = 'vignesh'     import treq from twisted.internet import defer, reactor def get_page(url): print "Requesting URL : %s" % url d = treq.get( url =url) def callback(result): previous = result.previousResponse if previous: location = previous.headers.getRawHeaders( "location" ) if location: response_from_url = location[ 0 ] else : response_from_url = url ...

Can a Coroutine is useful without Asynchronous IO ?

Coroutine is a way of doing concurrent programming without the need of Thread. For more information regarding coroutine, go to asyncoro  and  asyncio-task . Coroutine has numerous advantages when used with asynchronous IO. But in this post I am analyzing whether coroutine can be used without it and also checking whether coroutine can be used to replace threads in most scenarios as threads itself is not running in parallel due to GIL  in python. Below are the advantage and disadvantage of coroutines (without Asynchronous IO) when compared against threads. Advantage     1. No locking mechanism required (in most cases) as the next coroutine will run only after the current coroutine yields.       2.  No thread, so no context switch required between coroutine execution.     Disadvantage     1. If a coroutine gets blocked, it will block all other coroutines as well as there is...

Download page for packages in OBS

Image
What is OBS ? : The openSUSE Build Service is the the public instance of the Open Build Service (OBS) used for development of the openSUSE distribution and to offer packages from same source for Fedora, Debian, Ubuntu, SUSE Linux Enterprise and other distributions.   Here is a brief comparison of other build system with OBS http://en.opensuse.org/openSUSE:Build_Service_comparison Software Center of OpenSUSE OpenSUSE is concentrated on creating a Online Software Center, since last year, where the user can search for software and easily install it using "One click install". It's not just specific to openSUSE, it's a open software center for all Linux distributions. To emphasis on this, OpenSUSE has removed the link to download packages from build.opensuse.org.  But from developers point of view, a download page for his software will be great as he can make a Download link in his site. Actually OpenSUSE didn't removed the download page, it just remov...

Different way to search for files in Gnome

Image
Searching for files is one of the most frequently performed task that most of the user does. In Gnome, it can be done by any of the following four ways. Using Nautilus Search Using gnome-search-tool Using Tracker Desktop Search Using zeitgeist   Using Nautilus for searching.       It's more natural to use the file manager to search for files instead of using an external app, that's why i decided to starting with nautilus first. Nautilus do have a built in search functionality that works by using tracker as backend. But most of the user complains that the nautilus does not shows any search result most of the cases. This is because, search is case sensitive , and  search is done only in directives which are indexed by the tracker.        By default, tracker index recursively the user's document, pictures,  videos, Desktop, Music, Downloads directories and non recursively on user's home directory . ...

500 Internal server error

The internal server error might be caused by several reasons. Here i am providing solution for one of it. check your web server error log [ mostly it will be at /etc/httpd/logs ]. If the last few line of the error log contains the lines similar to (13)Permission denied: exec of '/var/www/html/index.py' failed (13)Permission denied: exec of '/var/www/html/index.cgi' failed or something similar, then solution to this as follow. If not, the error occured by some other reason. Try this site. Htmlfixit . You might face this error when you are trying to do some CGI programming in your system via apache server. Most of the time this error does not occur due to apache server misconfiguration, its mainly due to SElinux installed in your system. A brief note about SElinux : SElinux [ Security Enhanced Linux ] is installed by default in Fedora and many other linux distribution.  Its a super cool feature when one speak about security. But many time its...

Effective Use Of For Loop in Bash Shell Scripting

"for loops" are effective than "while loop" when a loop is to be done for each element in a array or each word in a string. This "for loop" is different, more powerful and useful then the version of for loop available in c/c . Here i am here to show some interesting new ways to use them in our bash scripts. Example 1: Simple and basic data="Bash scripting is fun" for i in $data do     echo "$i" done Output: Bash scripting is fun Explanation:     The bash [ Interpretor of the script ] splits each word in the variable data and each split piece is stored in the variable i on each iteration. The for loop starts and ends with 'do' and 'done' respectively. Example 2: simple and direct for i in Bash scripting is fun do     echo "$i" done Output: Bash scripting is fun Explanation:     Same as before but instead of using variable, we directly used data in the for...

Best way to start a Wine APP from terminal [ commandline ]

To all of us who use wine, there are times where we need to start a wine application [ windows application to be ran in wine on Linux ] from terminal. Most us will try to start it my issuing the command. user@localhost$ wine Although it will start the app, but most of the time the application crashes or send error some dll is missing or sometime just not works without informing anything. This is not the best way to start a wine app. The best way is that using two more option to wine while call it. The options are 'start' and '/unix' as follow, user@localhost$ wine start /unix Issuing the above command will success fully start the app. Note:  Reason for this is that, while issuing wine , the local dll files will not be set to lib path for wine. So adding the two option will inform the wine to load the local dll files too.