Recently in Tips n Tricks Category
Converting Video/Audio on Linux is a breeze, and there is no shortage of tools. Especially between ffmpeg and mencoder, I can't think of any conversion that's not possible.
However, the problem is finding the right parameters suited for a specific task. There are multiple "wrapper" tools (e.g. Avidemux, HandBrake) that make life a lot easier. However, sometimes, knowing the actual conversion parameters help.
I was trying to convert some videos so that they play on Windows without need for any extra codecs etc. WMV format is the way to go for this. The following ffmpeg recipe seems to be working fine:
ffmpeg -i <input_file_name> -s <output_resolution> -b <video_bitrate> -vcodec wmv2 -acodec wmav2 -ar 44100 -ab <audio_bitrate> -ac 1 -y <output.wmv>
Example:
ffmpeg -i output.avi -s 180x120 -b 300k -vcodec wmv2 -acodec wmav2 -ar 44100 -ab 48000 -ac 1 -y movie.wmv
However, the problem is finding the right parameters suited for a specific task. There are multiple "wrapper" tools (e.g. Avidemux, HandBrake) that make life a lot easier. However, sometimes, knowing the actual conversion parameters help.
I was trying to convert some videos so that they play on Windows without need for any extra codecs etc. WMV format is the way to go for this. The following ffmpeg recipe seems to be working fine:
ffmpeg -i <input_file_name> -s <output_resolution> -b <video_bitrate> -vcodec wmv2 -acodec wmav2 -ar 44100 -ab <audio_bitrate> -ac 1 -y <output.wmv>
Example:
ffmpeg -i output.avi -s 180x120 -b 300k -vcodec wmv2 -acodec wmav2 -ar 44100 -ab 48000 -ac 1 -y movie.wmv
Recently I was playing with couple of link scraping libraries, and was impressed by the simplicity of the mechanize toolkit. The only problem they have is lack of documentation.
Following is an example script written in python that can do a google search and scrape the result links (of class ‘l’) in a few lines of code.
import re
import sys
from mechanize import Browser,DefaultFactory
import mechanize;
br = mechanize.Browser( factory=DefaultFactory(iwantbrokenxhtmlsupport=True))
br.addheaders = [ (“User-agent”, “Mozilla/5.0 (compatible)”) ]
br.sethandlerobots(False)
br.open(‘http://www.google.com/search?q=’+sys.argv[1])
def arrtonamed(arr):
ret = {};
for x in arr:
ret[x[0]] = x[1];
return ret;
# follow second link with element text matching regular expression
for link in br.links():
hash = arrtonamed(link.attrs);
if hash.has_key(‘class’):
if (hash[‘class’] == ‘l’):
print link.url+’[‘+link.text+’]’
A sample output for the script is:
$ python goog.py samya
http://www.thinkbabynames.com/meaning/0/Samya[Samya - meaning of Samya name]
http://www.samyatech.com/[SAMYA Technology : Green Power Expert! 祥業科技股份有限公司: 綠色 ...]
http://www.yawiktionary.com/s/1148371572412.html[samya - definition of samya - yawiktionary.com]
http://samya.indiangeek.com/[[ IndianGeek ] Welcome to Samya's HomePage]
http://www.hossamramzy.com/stars/starsofegypt_samya.htm[The Stars of Egypt ® | Hossam Ramzy]
http://www.belly-dance.org/samia-gamal.html[Samya Gamaal - the queen of raqs sharki]
http://www.samya.ca/[Samya Therapies Splash Page]
http://samya-photography.deviantart.com/[Samya-Photography on deviantART]
http://www.facebook.com/people/Samya_Badraoui/1434855400[Samya Badraoui | Facebook]
http://www.healthgrades.com/directory_search/physician/profiles/dr-md-reports/Dr-Samya-Nasr-MD-EB461FD0.cfm[Dr. Samya Z. Nasr, MD, Pediatric Pulmonology, Pediatrics, located ...]
Continue reading Using python to search google.
On my impending trip to India, I'm planning to move my family from using Windows to Linux. I have Kubuntu Intrepid Ibex in mind as the distro.
The primary applications for my parents are Email (Thunderbird) & Web browsing (Firefox), both of them work like charm on Linux.
However, my father being a writer, he needs an editor that allows him to write in bengali, a regional language. Now, there is of course the keyboard layouts available for writing in bengali, and generate unicode output, it's not that useful as it doesn't support phonetic input. So, the writer will have to remember the keyboard layout.
Then I found Bhasha, a Java stand-alone application that allows writing in bengali phonetically, and produces unicode output. Problem solved.
Here is a screenshot.
The primary applications for my parents are Email (Thunderbird) & Web browsing (Firefox), both of them work like charm on Linux.
However, my father being a writer, he needs an editor that allows him to write in bengali, a regional language. Now, there is of course the keyboard layouts available for writing in bengali, and generate unicode output, it's not that useful as it doesn't support phonetic input. So, the writer will have to remember the keyboard layout.
Then I found Bhasha, a Java stand-alone application that allows writing in bengali phonetically, and produces unicode output. Problem solved.
Here is a screenshot.
I've been noticing Firefox using up a lot of CPU lately. At any given time, I normally have about 3 to 4 firefox windows with about 5-6 tabs in each open. But with no activity in them, there should not be much CPU usage. On a hunch, I installed flashblock, a firefox plugin to disable showing flash apps automatically. Instead, it shows a blank rectangle, with a play button in the middle to start the flash app. Installing this made a dramatic effect, and soon I realized this is due to the n number of flash advertisements in different websites. I probably had about 10-15 flash apps playing at the same time, none of them really useful to me. Would highly recomment this add-on.
As part of my job, I work with a huge source tree structure. In last count, the tree has more than twenty five thousand directories and subdirectories. To get from one part to another in the tree, I use a set of aliases and bash functions. One of them is the following "goto" function.
The idea here is, there are a set of source directories that I normally go to, or work under directly. Then there are some directories that are more then one level deeper but are under these same source directories. Then there is the rest of the tree where I need to go from time to time.
So when I run "goto xyzd", I want it to run the search in three phases:
1. Check if xyzd is there as the first level subdirectory under any of the common directories I work on. This should be the most common scenario.
2. If not found, do a "find" based search on the specific commonly used source directories only.
3. If pass 2 also fails, do a complete search from root of the tree.
4. In any of the passes, if a directory is found, cd to it.
This works out well for me. There are enhancements that can be done (like, if more than one name is found, giving options), but so far I didn't find any need for it.
The script looks like the following. You will need to change the DEV_ROOT and SDIRS variables to match your tree.
The idea here is, there are a set of source directories that I normally go to, or work under directly. Then there are some directories that are more then one level deeper but are under these same source directories. Then there is the rest of the tree where I need to go from time to time.
So when I run "goto xyzd", I want it to run the search in three phases:
1. Check if xyzd is there as the first level subdirectory under any of the common directories I work on. This should be the most common scenario.
2. If not found, do a "find" based search on the specific commonly used source directories only.
3. If pass 2 also fails, do a complete search from root of the tree.
4. In any of the passes, if a directory is found, cd to it.
This works out well for me. There are enhancements that can be done (like, if more than one name is found, giving options), but so far I didn't find any need for it.
The script looks like the following. You will need to change the DEV_ROOT and SDIRS variables to match your tree.
function goto() {\
echo "Searching for $1 ...";
DEV_ROOT="root/dir/for/tree"
SDIRS="src/xxxx/usr.bin:src/xxxx/usr.sbin:src/xxxx/yyyy/common:src/xxxx/sbin";
# Pass 1
for i in `echo $SDIRS|sed 's/:/ /g'` ;
do
if [ -d $DEV_ROOT/$i/$1 ];
then
cd $DEV_ROOT/$i/$1;
return;
fi;
done;
echo "Couldn't find $1 in first pass... Trying second pass...";
# Pass 2
for i in `echo $SDIRS|sed 's/:/ /g'` ;
do
echo "Searching in $DEV_ROOT/$i..."
DIRPATH=`find $DEV_ROOT/$i -type d -name $1`
if [ "$DIRPATH" != '' ];
then
echo $DIRPATH
cd $DIRPATH
return;
fi
done;
echo "Couldn't find $1 in second pass... Trying full search ...";
# Pass 3
DIRPATH=`find $DEV_ROOT/src -type d -name $1`
if [ "$DIRPATH" != '' ];
then
cd $DIRPATH
return;
fi
echo "Failed to find directory $1."
}
One of the applications that I find lacking in Linux is a full featured blogging client. There are a few like BloGTK, blokkal etc. but they are far from being fully featured. There are some plug-in based variants, like Scribus, but I'm not much of a fan of it. The online native posting is still more fully featured than any of these.
Here comes an easy trick for quickly posting to your blog from within firefox (or any other browser), without leaving the current page. You can create a bookmark in firefox with the following link (remember to change your blog's mt.cgi path)
http://<path to mt.cgi>?__mode=view&qp=1&_type=entry&blog_id=1
In the "Properties" for the bookmark, remember to select "Load this bookmark in the sidebar" checkbox. Now, if you remain logged in to the blog, you can just start blogging by clicking on this bookmar. Here is how it looks in Firefox while I'm writing this post.

Here comes an easy trick for quickly posting to your blog from within firefox (or any other browser), without leaving the current page. You can create a bookmark in firefox with the following link (remember to change your blog's mt.cgi path)
http://<path to mt.cgi>?__mode=view&qp=1&_type=entry&blog_id=1
In the "Properties" for the bookmark, remember to select "Load this bookmark in the sidebar" checkbox. Now, if you remain logged in to the blog, you can just start blogging by clicking on this bookmar. Here is how it looks in Firefox while I'm writing this post.

One of my major gripes after moving to full-time Linux was, I can't read the Bengali newspaper Anandabazar online anymore. They, absolutely utterly moronically, use a proprietary font (I'm sure someone there paid for it), which does not offer ANY extra advantage over using Unicode Bengali!!
I started working on a python script that can translate those fonts to Unicode, and it was going well. But halfway through, I realized someone has already done this, and it is already available as a Mozilla extension.
The extension is named padma, and it's targeting different Indian languages. Works great on Firefox. The download page is here. You'll need to restart Firefox after installing the extension.
I started working on a python script that can translate those fonts to Unicode, and it was going well. But halfway through, I realized someone has already done this, and it is already available as a Mozilla extension.
The extension is named padma, and it's targeting different Indian languages. Works great on Firefox. The download page is here. You'll need to restart Firefox after installing the extension.