Sunday, February 28, 2010

[SW] Podcast in Quod Libet

Several moths ago, I installed Quod Libet for the first time. When I could not figure out how to add the podcast feeds in the Quod Libet, and posted my question on Ubuntu Forums. But I totally forget it after my posting... O__O"

I saw the thread when I was searching something else. Then I followed what lazka suggested:
$ sudo apt-get install python-feedparser
After installing the python-feedparser, just restart Quod Libet and find the Audio Feeds entry in the menu. Use the New button to add podcast feeds.

[Py] Random data generation -- a trial

I am studying the usage of LIBSVM recently. What I want is to test the library with some simple data to enhance my understanding for using the library. Therefore, I thought about generating some random data sets for my own learning purpose, and of course, the first choice came into me was Python.

The following are my code and the resulting data plot.
---------------------------------------------
Code:
from pylab import *
from numpy import *

data =[]
#generate random data sets
data.append( 1.2*random.randn(2,30) )
data.append( 2.0*random.randn(2,30) )
data.append( random.randn(2,30) )

#shift the data sets
x0 = data[0][0]; y0 = data[0][1]
x1 = data[1][0]+3.5; y1 = data[1][1]+2.5
x2 = data[2][0]-1.5; y2 = data[2][1]+4.5

f = open('randData','w')
for i in range(len(x0)):
print >> f, '%f %f %f %f %f %f'\
% (x0[i], y0[i], x1[i], y1[i], x2[i], y2[i])

f.close()

plot(x0, y0, 'ro', x1, y1, 'go', x2, y2, 'bo')
savefig('randData.png')
show()


Saturday, February 27, 2010

[SW] Two CLI screensavers

Actually, I do not use screensavers. I always turn off the monitor when I have to leave my PC for a while. As a CLI fan, however, I am willing to see a CLI screensaver running on my monitor, especially when the screensaver is cool.

Cmatrix is a cool screensaver and it's easy for Ubuntu users to install. Just use the command
$ sudo apt-get install cmatrix
to get it, and you can have a really Matrix-like screensaver. Looks really cool, doesn't it?


The second one I installed is ASCIIQuarium. I found it on the Mostly CLI blog (Is that a Fish in Your CLI? The asciiquarium Screensaver.), which is worth visiting if you are also a CLI fan. Followed the steps, I download the Term::Animation module but got a warning when I runned the ``perl Makefile.PL'' command. The warning message was
Warning: prerequisite Curses 1.06 not found.
Then I tried to find out how to installed the so called ``curses'' in my Ubuntu 8.04, even install the libncurses5-dev (it's not the right one), but got no luky. Then, I noticed that all the packages are related to Perl! I am not familiar with Perl so I had no clear idea what searching strategy was right. Finally I knew that the libcurses-perl is the key. So if you encounter the same problem I had, please use the following command to install the libcurses-perl package.
$ sudo apt-get install libcurses-perl
Then here comes the ASCII fishes (as well as other things...).

Sunday, February 21, 2010

[SW] Mutt usage and setting -- with Gmail

Thank Andrew! I followed his blog article and finally make Mutt work with Gmail!

Here is the excellent instruction for newbies who want to try Mutt but have no idea how to to:
Using Mutt with Gmail

I have changed some settings for the inbox folder from
    /var/spool/mail/your_username
to
    $HOME/mail/inbox

Although there are more things I need to learn, Andrew's guidance has given a good start. Hope you can benefit from this.

Friday, February 19, 2010

[SW] Rhythmbox and Quod Libet don't play music

I have used Rhythombox and Quod Libet for listening to music, podcast, and internet radio. But I didn't listen to music on my PC for a while, and these days I encountered a problem when I used Rhythombox and Quod Libet to open my music files. Both of them cannot play the ogg files. I tried to remove and reinstall them, but it didn't work.

Finally, I found a post from ``rhythmbox : does not play the songs at times. When I click play song, no response''.

So the solution is to change the sound setting to ALSA. The problem for me now is that I don't remember why I changed the sound setting to PulseAudio...

[SW] Invert the documents colors in Okular

[NOTE] Here is a newer version of this post:
Invert the document colors in Okular with toggle shortcut

I prefer viewing documents in black background with white text, just as what is usual in the command line environment. It seems no color inverting function in Evince, so I have to use Okular to satisfied my own requirement.

Open your PDF file with Okular, and follow Settings --> Configure okular to open the following dialog.
Check the ``Change Colors'' box and choose ``Invert colors'' of the color mode. Looks great!

[SW] Invoke Okular from the command line -- use soft symbolic link

I have installed Okular in my Ubuntu for several months and appreciated its annotation functions which allow me more freedom with my own documents. When I want to invoke Okular from the command line, however, it cannot be found by the system. After some investigations, the symbolic link seems to be the handiest solution.

Go to /usr/bin and use ln to make a symbolic link:
$ sudo ln -s /usr/lib/kde4/bin/okular okular

This is my first time to use ln, and it works as expectation. :-)

Friday, February 12, 2010

[SW] How to import html tables into the OO Calc?

I am working on patent search these days (and it's really a terrible task, at least for me). With some assistant tools I got a downloaded list of the patents I've found, and this list has been given with a xls filename extension. The xls file works fine with MS Excel but not OO Calc. When I tried to open the xls file in my Ubuntu, it showed as a text file with gedit with some html tags in the content. So the xls file was essentially a html table file, and OO Calc just cannot open the file directly.

The unoconv was the first possible solution I found. It can convert between formats that supported by OpenOffice. The command line usage is simple, just define the ouput format as the following
$ unoconv -f ods originalfile.html

and the unoconv gives the output file with assigned format (originalfile.ods in this example). However, when I tried to open the converted ods file with OO Calc, nothing happened, the OO Calc didn't open anything and showed only empty content.

Luckily, another simpler solution has been there. Just utilize the import function provided by OO Calc itself to import the html table, then everything goes smoothly. You can find the function in ``Insert/Link to External Data'' and it comes up a dialog for choosing your file.

---
Ref:
OpenOffice Calc Tips: Webquery : Importing HTML tables

Tuesday, February 09, 2010

[QnA] Convert MOD to AVI using transcode -- without audio ouput

Sometimes we might take videos with some environmental noise or conversations which are not suitable to be heard by others. Also, we don't need or want to add other audio into the original video, so just export the video without audio is fine enough.

I had some MOD files to be converted by using transcode before, and this time I want to export my MOD files into avi files with no sound. It's can be done by apply the ``null'' option as the following

transcode -i input.MOD -y xvid,null -o output.avi

That's all.

Friday, January 08, 2010

[Py] Problems of XML processing (Dive Into Python)

I am learning how to parse XML content with Python, and the tutorial I've followed is the Dive Into Python. In Chapter 9, most of the examples are clear for a newbie to follow. When I tried the example 9.10 (toxml works on any node), however, unexpected results occurred.

Fortunately, someone had the same problem and there is a solution: Possible error in 'dive into Python' book, help!

The key point is to use documentElement instead of firstChild.

I don't realize the reason yet. More study is necessary for me to understand the whole idea.

---
Ref:

Thursday, December 31, 2009

[QnA] SCIM setting in Debian.. again...

I installed the Debian in one of my PC, but then reinstalled it to give a disk space for the LFS. After the reinstallation, I forgot how to install and set up the SCIM... AGAIN... I even forgot I've had an article about this issue in my own blog HERE. Orz

This time, my procedures are the follows:
# apt-get install scim scim-chinese scim-tables-zh
# vim /etc/X11/Xsession.d/95xinput
/usr/bin/scim -d
XMODIFIERS="@im=SCIM"
export XMODIFIERS
And didn't get what I want, so I kept tring
# vim /etc/X11/xinit/xinput.d/all_ALL
XMODIFIERS="@im=SCIM"
GTK_IM_MODULE="scim"
QT_IM_MODULE="scim"
Then the SCIM setting had been completed.

Finally, I installed the Japanese and Chinese imput methods to which I used.
# aptitude install scim-anthy scim-chewing

(Later, I removed
/etc/X11/Xsession.d/95xinput, and everything works well so far.)

Saturday, November 14, 2009

[QnA] Taking screenshots of virtual consoles?

I am trying to find ways to take screenshots of virtual consoles. This article shows the method of taking screenshots from console using the ImageMagick. The author said that the method also works for consoles with the command as the follows

$ sudo chvt N; sleep T; import -display :0.0 -window root output.png; sudo chvt M

where N is the target console and T is the time in seconds. The last chvt command is just for returning the original working console.

After testing with the command, however, I found the png file was generated but the image itself is not what I expected. At the beginning I thought that might due to my framebuffer setting so I disabled the corresponding setting in the /boot/grub/menu.lst. Nothing has been improved and I still can only get the following useless image.

[QnA] FrameBuffer setting

Several months ago, I learned the way to view images in the virtual console. I happened to recall the framebuffer and want to know more about it, so I began to search related information again.

Here are several informative web pages:
  1. Images and Videos on the Command Line? YES!
  2. Using framebuffer devices on Intel platforms
  3. Ubuntu wiki: FrameBuffer
In the 2nd web page, there is a table showing the values for different resolution as follows:

Colours 640x400 640x480 800x600 1024x768 1152x864 1280x1024 1600x1200
--------+--------------------------------------------------------------
4 bits | ? ? 0x302 ? ? ? ?
8 bits | 0x300 0x301 0x303 0x305 0x161 0x307 0x31C
15 bits | ? 0x310 0x313 0x316 0x162 0x319 0x31D
16 bits | ? 0x311 0x314 0x317 0x163 0x31A 0x31E
24 bits | ? 0x312 0x315 0x318 ? 0x31B 0x31F
32 bits | ? ? ? ? 0x164 ?
Furthermore, from the 3rd reference I found more useful setting such as
  • ``vga=normal'', or ``nofb'', disables the framebuffer
  • ``vga=ask'' will able you to set a value at each boot good for testing out the various modes.

Friday, November 13, 2009

[QnA] Sound volume control in command line

I've used wmii for several weeks, and it meets most of my need well. Sometimes, however, I want to control the volume but there is no the control panel as in the Gnome desktop environment.

Here is the solution: amixer (or alsamixer, which has the ncurses interface).

To use alsamixer is easier due to the straightforward interface. If you get the following error message when you type ``alsamixer'' in the command
alsamixer: function snd_ctl_open failed for default: Connection refused
then do the following steps:
$ rm ~/.asoundrc and then do
$ asoundconf list
$ asoundconf set-default-card foo
where the foo is one of the sound cards listed by `asoundconf list.'

---
Ref:
http://ubuntuforums.org/showthread.php?t=597765
http://ubuntuforums.org/showpost.php?p=3631606&postcount=4

Thursday, November 12, 2009

[SW] Big5 and utf-8 in Vim

To make Vim open big5 files properly, just set the following
set fileencodings=utf-8,big5,euc-jp,gbk,euc-kr,utf-bom,iso8859-1
set encoding=utf8
set tenc=utf8
---
Ref: http://wiki.debian.org.tw/index.php/Unicode#VIM

Thursday, November 05, 2009

[Py] Equal sign

Python: Careful with equal sign

I found this article when I was searching for the information about comparisons in Python.

When we assign a variable to another, for example, a = 1; b = a, Python just passes the reference (of variable a) to the new one (i.e., the variable b) but not creates a new copy with new memory address.

>>> a = 1
>>> b = a
>>> id(a) == id(b)
>>> True

But if we change the value of b, then a new memory block will be used to store the new assigned value.

>>> b = 2
>>> id(a) == id(b)
>>> False

[Py] Comparisons -- ``=='' vs. ``is''

In Python, there two operators which check whether things are the same. One is ``=='' and another is ``is.'' They may produce identical results but actually they have different meanings.

I found an article talked about this: is is not the same as equal in Python

The simple guideline has been given by Eric:
You should really only use 'is' to check for object identity, and for any kind of value comparison, == is the way to go.
And an interesting example has been given by Kevin:
>>> "peter" == "peter"
>>> True
>>> "peter" is "peter"
>>> True

>>> "peter" is "peter1"[:-1]
>>> False
>>> "peter" == "peter1"[:-1]

>>>True
---
ref: Python built-in types: comparison


[Py] Guidelines for Python coding style

Here are two links about the Python coding style:
One thing I've never noticed is the indentation problem. Python relies on consistent indentation of code blocks, so if the programmer mixed spaces and tabs in the code there could be problems when others open or edit the code with other editors with different tab setting.

The above links give many information that I cannot read throughly in limited time, but they have offered me some useful guidelines to follow in the future.

Tuesday, November 03, 2009

[QnA] Cannot mount disk -- you are not privileged to mount volume

One of my Windows XP disk partition happened to be unmountable and I totally didn't know why. I've set the auto mounting in /etc/fstab and it has worked well till today.

To solve this problem, use:
$sudo mount -t ntfs-3g /dev/yourdevice /media/yourfolder -o force

[QnA] GPG error -- the solution

When the Ubuntu users update and upgrade their system, there are, sometimes, GPG error messages shown in the GUI dialog or command line terminal.

Here are a solution I've found useful and easy (only two steps):

$ gpg --keyserver keyserver.ubuntu.com --recv put_the_last_8_digits_of_the_key_here
$ gpg --export --armor put_the_last_8_digits_of_the_key_here | sudo apt-key add -

---
Some other related links (for backup and reference):
https://answers.launchpad.net/easyubuntu/+question/73458
https://answers.launchpad.net/ubuntu/+question/73171
http://kovyrin.net/2006/11/28/debian-problem-apt-get-update/