Skip to main content

Posts

Showing posts from 2011
Nowadays normally Ubuntu mounts external hard drives without the executable bit set as a precaution against dangerous scripts from running automatically. Without the executable bit set it becomes impossible to run scripts from external hard drives. However, setting the executable bit is not as hard but little bit laborious. So I wrote a small script to decrease the load.

In order to set the executable bit for the normal user the specific partition has to be unmounted as root and then remounted by the normal user with SSID and setting the executable bit so that he has execution permission. The normal remounting process could be done in the userspace so it is all included in the script but the unmounting requires root privilege. Since, sudden unmount can freeze open files and cause data loss if the mount point is removed forcibly (rm -rf) I have not included it in the script. So the unmounting has to be manually by the user with root privileges. So if using a public computer or a share…

Gateway Netbook LT2802u tinkering

This Gateway Netbook LT2802u is a very compact machine. You need to take it apart in order to even install RAM. So I opened it up for fun and put it back.

In order to open the Gateway netbook there are many guides. First read the instructions on
http://dl.dropbox.com/u/26855544/Gateway%20LT28%20Series%20Netbook%20Repair.pdf

from ( http://gadgetgeekgrrl.blogspot.com/2011/08/netbook-memory-upgrade.html)

then see the following video
http://www.youtube.com/watch?v=uBM9jbhUpkc

and then see the tips at

http://www.notebookforums.com/t/237671/lt2802u-ram-xp-install-instructions

The last link gives crucial tips on how not to scratch your laptop. So use a thin laminated card or a Safeway card (not your credit card) instead of a screwdriver. If you are still using a thin flat screwdriver then cover its tip with some thin paper like a receipt. But do not try to remove those thin T-shaped screws which hold the keyboard in place and visible from the battery compartment. It is unnecessary and you woul…

A script to extract audio from a bunch of video files

This sript extracts the soundtrack from any video format and converts it to mp3. Put all videos in a single folder and run this script on them. This works on all kinds of video. This is specially useful on those bunch of youtube videos.
It works like flv to mp3, mp4 to mp3, avi to mp3 etc.
==================================


#!/bin/bash # convert-video-to-mp3 v2.0 by JOnes. # This sript extracts the soundtrack from any video format and converts it to mp3. # Put all videos in a single folder and run this script on them. This works on all kinds of video. This is specially useful on those bunch of youtube videos. echo -e "\nThis sript extracts the soundtrack from any video format and converts it to mp3. Put all videos in a single folder and run this script on them. This works on all kinds of video. This is specially useful on those bunch of youtube videos.\n\n"
if [ ! `which mplayer` ] ; then echo -e "Install mplayer \nsudo apt-get install mplayer" exit 0 fi
if [ ! `which lame`…

Internal Field Separator (IFS)

Internal Field Separator (IFS): This internal variable in bash shell turns out to be an indispensable tool in these days of spaces and other weird characters in filenames. Anyone who has tried to script in bash which involved accessing lot of filenames have definitely come across the problem of spaces in filenames.
The problem is this. It becomes impossible to split a directory listing "ls" into filenames using just the for $i in `ls` command. And the reason is simple. The directory listing separates filenames by spaces but the filenames themselves might have spaces. So the for command cannot figure out where the filename ends and where it begins. That is where this neat trick comes in. We have to tell bash to ignore all separation symbols other than newline while splitting up the directory listing into filenames. This means each line would be a new filename. And we have to make sure that each line has a new filename. This is easily achieved by the "ls -1" command.

mplayer shortcut to change aspect ratio while playing video

The following command tells the available commands for keyboard input.
mplayer -input cmdlist
The keyboard shortcuts to mplayer are stored in two locations - /etc/mplayer/input.conf and ~/.mplayer
I prefer editing the /etc/mplayer/input.conf.
Assign shortcuts to aspect aspect ratio switching as follows
switch_ratio
e.g.
a switch_ratio 1.3333 # 4:3 s switch_ratio 0 # switches back to original aspect ratio b switch_ratio 1.7777 # 16:9 ratio
put his at the end of /etc/mplayer/input.conf.

A script to automount external USB HDD with the executable bit set

Recent releases of Ubuntu mounts external USB HDD in userspace and hence it does not set the executable bit on the drive. As a result if I try to run softwares or scripts installed in the external HDD I have to pmount it manually. So I wrote a small script which would - 1. verify that drive is mounted. 2. it is not empty(from a previous manual mount unmount cycle) 3. then unmount the drive and re-mount it in userspace with the executable bit set.
I wanted this script to be minimal. So I did not make it complicated which accepts a drive LABEL from the user and uses it. Just replace your drives LABEL in place of "passport-2" in the second line of the script. So if your external drive is called Sandisk replace passport-2 with Sandisk. If it turns out that the script fails due the use of $LABEL, then replace all $LABEL in the entire script with your drive label manually.
================================== #!/bin/bash $LABEL=passport-2 cd /media # check if $LABEL exists if [ ! -d &qu…

Minimal install LaTeX without documentation

The LaTeX package for Linux is the texlive package. The normal install of texlive is huge due to the documentation included can go upto 500MB itself. A leaner latex is what we all desire. It is not possible from inside Synaptic.
Use this command to install latex without docs.
sudo apt-get install --no-install-recommends texlive texlive-pstricks texlive-fonts-extra prosper

How to buy a laptop

Laptop is a  very specialized piece of equipment. It has to chosen carefully in order to suit your needs and not just by looking at benchmarks. That procedure is for desktops.

I will not list laptop models or vendors here because the hardware and configurations change so fast that by next day it would be outdated. To figure which ones are topping the list go to pcmag.com, laptopreviews.com But remember the your final choice might be complete different than the ones they recommend. But if you sure that this is what I need then go ahead.

Now let us see how to choose the right laptop.

To select a laptop answer these first

1. Why do I need it ?
2. What do I expect from it?
3. How much spending can I afford ?
4. How much battery life I want?
5. How long do I want my laptop to be mainstream?

CATEGORIES :

A> Business - This means you have to make presentations with it. And travel a lot.

Options : Business laptops are available to suit this niche. But personally I would say - Buy one lapt…

A simple laptop battery monitor script

The script displays alert when the battery falls below 20% or charges up beyond 80% which should be the optimal range of its working.

The code is as below. Just copy and paste and save as any file name but preferably battery-notify.sh. The script can independent of what name it is given. Needs to have acpi (default install) and notify-send installed (sudo apt-get install notify-osd).


============================================

#!/bin/bash


# battery-notify v1.2 by JOnes


# It is a script to monitor battery and keep it between 20% to 80% the optimal battery working range. If the battery goe beyonds the set limit it gives pop-ups every 10 seconds. No sound warning as sound can easily be muted and ignored.
# Things that could be added : 1> The flexibilty of range. But it is not recommended  hence not implemented. 2> Notification in form of email or sms. 3> Sound / beep for critical state of battery.
# The script goes into background. To kill it at any time use : kill `pgrep battery-no…

How to choose a webcam

I am biased. I prefer Linux. So i am going to talk about webcams which work in Linux.
The primary driver for webcam in Linux is the UVC driver. Goto the UVC site and look for the supported hardware - http://www.ideasonboard.org/uvc/#devices

Other drivers available are SPCA drivers. The official website
http://www.quickcamteam.net/software/linux/drivers/spca5xx-webcam-driver .
describes the installation details.

For supported hardware look at -
http://mxhaard.free.fr/spca5xx.html.

For step by step procedure, look at the video at http://www.linuxjournal.com/video/get-your-webcam-working-gspca.

For Skype tested webcams - https://wiki.ubuntu.com/SkypeWebCams

For more information go to https://help.ubuntu.com/community/Webcam
To test my webcam and adjust its brightness I use vlc and v4l2ucp. Cheese and v4l2upc combo can also be used. Here's what I do. (vlc needs to be installed)
vlc v4l2:///dev/video0
In another terminal open v4l2ucp, the Video 4 Linux v2 control panel.
v4l2ucp
Now in the v4…

Split djvu into jpg files

In order to convert a djvu file into a collection of jpg files two tools are needs. One is djvulibre and the other is Imagemagick. Install these first.

One way to convert would be to follow these instructions from http://en.wikisource.org/wiki/Help:DjVu_files
To extract images from a DjVu file, you can use ddjvuddjvu -page=8 -format=tiff myfile.djvu myfile.tif If you done all the pages (without -page=**) you can split the multi-page tiff into single pages png (or any other format)convert -limit area 1 myfile.tif myfile.png
But if the djvu has more than 8 pages then all these pages would be included into the tiff. When Imagemagick tries to convert that tiff and splits it into jpgs then it runs out of cache with the following error.

convert: unable to extend cache file.tif': @ error/cache.c/OpenPixelCache/4175.

It could be remedied but I do not know how. The solution might to limit the memory map http://www.imagemagick.org/script/architecture.php#tera-pixel

But instead a bash script can…

Make all output formats available in Kdenlive

In Kdenlive more often than not I had found that many render options are grayed out. Particularly the flv formats. It would say "unsupported video codec" when the mouse is hovered over each crossed and grayed out item. This means that these codes are unavailable in the system. Most probably all codecs are correctly installed but some are in the restricted section hence not installed by default. For example, the extra codecs. To install them first we have to turn on the "multiverse" and "Medibuntu" repos. See medibuntu.org to find out how to add that repo. (Medibuntu is not needed for what we are going to install now, but add it anyways as it has lot of good useful codecs). Then we can proceed to install all possible extra codecs needed by Kdenlive.

Depending on the system or OS version the following must be installed


libavcodec-extra-52 libavdevice-extra-52 libavfilter-extra-0 libavformat-extra-52 libavutil-extra-49 libpostproc-extra-51 libswscale-extra-0

Latex in chat gmail and pidgin

We write equations in latex to collaborators but most of them have to be read and interpreted in latex. It is only too natural to have some interpreter which converts the latex code into graphical output in the communication mediums like email client and chat clients. I would describe three possible ways to share equations with collaborators.

Gmail - To send equations in email had always been hassle. Either we had to send the raw latex codes or send copy paste of the output from some latex compiler. Now, latex codes could directly be compiled in gmail. Install, gmailtexhttp://alexeev.org/gmailtex.html. The site provides all information needed to get it working. I prefer the greasemonkey script method because no fonts etc. needs to be installed. But since it fetches fonts online you need to have good internet connections. For slow connections stick to local install methods.
Note - Just remember to turn off rich text formatting for gmailtex to be able to compile.
Gmail chat - http://users…

Vertical scroll not working HP Pavilion dm3 Notebook Touchpad in Natty/Ubutnu

This is a generic issue and not tied with HP Pavilion dm3 Notebooks. Many notebook touchpads do not have a working edge scroll first time with Ubuntu. The key is to pass a option to the psmouse module.

lsmod

See if psmouse is running. If not running check here

/lib/modules/`uname -r`/kernel/drivers/input/mouse

Do a ls. If no psmouse.ko is present then it has to be recompiled with latest kernel headers. I would not go into that.

Assuming psmouse is present. Then unload it by

rmmod psmouse

Then inject the following line

sudo echo "options psmouse proto=imps" >> /etc/modprobe.d/psmouse.conf

It might give an error if the file is not present. Then

sudo echo "options psmouse proto=imps" > /etc/modprobe.d/psmouse.conf

Reload the psmouse module

modprobe psmouse

The vertical scroll should work now.

Reinstalling GRUB Legacy after windows reinstall

After Windows reinstall the windows would overwrite the GRUB. If using Ubuntu 9.10 or later or have the GRUB2 installed then see here - 1. https://help.ubuntu.com/community/Grub2 2. https://help.ubuntu.com/community/DualBoot/Grub
If using older GRUB legacy version then the situation is a little bit tricky but not hard. There are two ways to do this.
A) Use older LiveCD, possibly of Jaunty.
1. Make a bootable USB. Use unetbootin and not the Startup disk creator otherwise you will have the error
vesamenu.c32: not a com32r image
(https://bugs.launchpad.net/ubuntu/+source/usb-creator/+bug/686041)
2. Boot into LiveCD.
3. Run grub
sudo grub
4. Find where Grub is.
grub> find /boot/grub/stage1 (hd0,5)
This may or may not be the correct partition where grub resides. If there is /boot partition in addition to a root partition then there might two locations where grub is installed for e.g. /dev/sda5/boot/grub and /dev/sda6/boot/grub. The one that contains the menu.lst is the one that is to be used.…

An essay on time : Saugata Chatterjee

Time is something we experience every day. Curiosity about the nature of time dates pre-civilization times, more than 30,00 years ago, when men drew the phases of moon and counted days. But serious thoughts about nature of time was begun only much later, in Europe, by Socrates, who plunged the idea deep into the philosophical school of Greece and taken forward by Plato and in India. where people pondered over true nature of creation. The Greco-Roman concept of time was practical, involving measurement of time. The Indians took it many more leagues further by describing time as infinite (Lord Vishnu floating eternally and creating universe out of nothingness). The concept of infinity might have also entered Vedic culture in the context of creation and the role of time, but infinity might be used from a different perspective. The endless cycles of time divided into 4 major "Yugas" clearly depicts that ancient Hindus conceived time as endless but the only way they could incorp…

Executable bit not set for external USB hard disks problem workaround

Problem : Previously the Linux system could automount external HDDs with executable permissions. Any file could be run directly from the hard disk. But the flip side was that almost many files including text files used to get the executable bit set. Hence Nautilus attempted to autorun the HDD. This apparently confused many first time users. So from 10.10 onwards Ubuntu stopped setting the executable bit on external HDDs. At what level it is done UDEV, HAL or PMOUNT is unclear tome. But since pmount is the final piece the workaround could be applied there.
Workaround :
First plug in the external disk. Display the mount points.
df
See where is the mount. For eg.
/dev/sdb1 /media/My-Passport
Then unmount the disk as root su umount /media/My-Passport
Then as a normal user mount it using the pmount wrapper for mount with the executable bit set for ALL files.
pmount --fmask 077 -d -e /dev/sdb1 My-Passport
fmask of 0 makes everything executable. pmount man claims that VFAT supports per file umask. B…

RAW record audio streams playing thorugh the PC speakers

RAW record audio streams playing in browsers like Firefox, Chromium or any streaming player like Quicktime, Realplayer, Helixplayer etc.
The best way to copy the audio streams available through the PC speakers is to stream copy through Pulse in Ubuntu.
Lucid Lynx 10.04 and Maverick Meerkat 10.10
These instructions describe how to record any audio stream that are piped through to your sound system (e.g., external speakers, headphones) using Audacity. Any KDE recording software should work. For the purposes of this example, the audio (voice, music, or soundtrack) player will be Sonic Visualiser but could be any sound source (e.g., MPlayer, VLC, Firefox Flash video, MIDI device). The "PulseAudio Volume Control" program is not installed by default, but can be installed by typing the command sudo apt-get install pavucontrol from a terminal window, or using the System Settings' Software Management to install the pavucontrol package. 1. Click the K menu. 2. Click Multimedia » PulseA…

Bulk rename files in Linux

Use the rename command :

To add the album title at the beginning :$ rename -v 's/^/TITLE-HERE-/' *.mp3

-v : verbose
s : substitute. it acts in the same way as regular expressions do in SED.

To replace a part of filename: $ rename -v 's/MISC\.\ -/Fossils-/' *.mp3

e.g. :-
MISC. - 01.mp3 to Fossils-01.mp3
MISC. - 02.mp3 to Fossils-02.mp3
MISC. - 03.mp3 to Fossils-03.mp3


To rename to lower case: $ rename 'y/A-Z/a-z/' *

To rename recursively: $ find ./ -type f -exec rename 'y/A-Z/a-z/' {} \;

Linux command : find

find & xargsPart of the reason why the Linux command line is so POWERFUL! Finding files can be a daunting task, given the vast number of files on your average Linux filesystem. The number of system files in an average Linux install is well into the tens of thousands, or even hundreds of thousands of files. That's not counting user files!
The command `find` is, as it's name implies, used to aid you in finding files you are looking for, anywhere in your filesystems. Plus much more (see below).

find can use a large number of other criteria to find a file.
The first argument to "find" is the directory (or directories) to perform the search. Example: find (and display) every file in your home directory: find $HOME"-name" the name of a file, or a partial name (basic regex). Example: find the file named "bookmarks.html" in your home directory: find $HOME -name bookmarks.htmlExample: find all files starting with the name "…

Video file manipulation

Many times I have downloaded a movie and when opened it is in French or Russian or any other language I do not know. Most people outright delete the file. I thought no. In most of the cases the video quality is superb while it is difficult to find  the same movie in english with the same quality. The reason is obvious. However, as it turns out that the big uncle does not care about the prints in English which are very low quality. So, I thought that I can download them, extract their audio and plug the mp3 into the audio track of the high quality print in different language. And here's how to do it. These methods work only in Linux (sorry Windows users).

To extract audio from avi(or mpg) file :

ffmpeg -i file.avi -acodec copy output.mp3

acodec does a direct copy of the audio track without involving any encoding into mp3.

To add the audio to avi file :

Open avidemux and load the video file (with nn-english audio). Say yes to all pop-ups. Then goto the menu Audio-> Main track ->…

when "cannot talk to klauncher" happens

Sometimes things go bad, for example if you had to press Ctrl+Alt+Backspace to restart the X, some services can misbehave after you log in anew. If KDE apps point messages at you saying "cannot talk to klauncher", and system tray icons appear in windows, instead of appearing on the system tray, then instead of rebooting or reinstalling Linux (as some may suggest) simple type in a console:

$ dcopserver_shutdown
$ kdeinit

That's all.

NIce utilities to have in Linux distro

Meld - File comparison. Very good. Also, can try out Kompare. Text based mode would be to use vimdiff.

F.lux  - Adjust the screen color and hue so that the glare is reduced during the night when tehre is less ambient light.

Flpsed - Pdf annotator. Very accurate. But limited in that it can only add text to pdf's.

Ipe - A spline based vector graphics drawing tool. Very very good for scientific/mathematical drawing. For example, a surface with vectors on it is easily drawn. Much better at drawing curves than xfig. The best feature is its Latex friendliness. Any graphic object could be labeled by a expression writtten in LaTeX. If I want to label the normal vector to my surface na then all I have to do is click and type $n^a$ and then run latex and it directly comes onto the screen. For xfig it is only ouputed in the file and not visible on-screen.