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/

Monday, October 26, 2009

[SW] Learning Lsip using Vim as the editor

I prefer Vim over Emacs. One day, I happened to be curious about Lisp, and then found the page ``Practical Common Lisp.'' The so-called ``programming environment'' confused me. Furthermore, Emacs seems to be the standard (or mainstream) editor/environment for the Lisp programming.

I've set the Emacs and SLIME for a try, but it's not easy for me to remember the key stroking in Emacs. So I also found some approaches to let me learning Lisp with my beloved Vim.

The first approach I found was: slime.vim, but I do neither understand the script nor the steps. After trying and trying, I gave it up.

The second approach is to install the Limp, a plugin for Vim. It does not work identically to what has shown on the web page, but it seems not bad and simple enough for me.

---
(Maybe my problems are due to my poor understanding of how Lisp works.)

[SW] Emacs and SLIME for Common Lisp

I am not familiar with Emacs, but I still tried to install Emacs as well as SLIME for trial.

Here are simple steps for setting all these up:
$ sudo apt-get install clisp emacs slime sbcl cl-asdf

Then, in the .emacs file:
(setq inferior-lisp-program "/usr/bin/sbcl")
(add-to-list 'load-path "/usr/share/common-lisp/source/slime/")
(require 'slime)
(slime-setup)

---
Ref: How to set up Emacs + SLIME + SBCL under GNU/Linux

[QnA] Using the terminal in Ubuntu -- simple but useful commands

Here is a web page for newbies: UseingTheTerminal. Most of the commands are simple but could be useful in daily operation.

Sunday, October 25, 2009

[SW] Taglist -- a Vim plugin for browsing the source code

To make Vim handier for programming, the taglist is a good choice. It works with Exuberant Ctags to make you browse the variables, functions, or classes of the source code easily.

Just make sure you have installed Exuberant Ctags:
$ sudo apt-get install exuberant-ctags

It's a good idea to set hot-key to toggle the TlistToggle function (use <F12> as the example):
nnoremap :TlistToggle
nnoremap <F12> :TlistToggle <CR>

[SW] Vimperator -- Let you use Firefox as in Vim

I read the article and it mentioned Vimperator, an add-on for Firefox. You would like it if you are a Vim fan. :-)

Tuesday, October 13, 2009

[QnA] Redirect the error message given by gcc compiler

I tried the redirect operator ``>'' to write the error and warning message to files, but it didn't work. There was nothing written into the files. Then, I found the solution:

$ gcc $> file

The ``$'' character is needed to make the redirection work.

Links:

[QnA] Mount smb folders from command line

Here are simple procedures to mount remote folders using command line interface.

$ sudo apt-get install smbfs
$ sudo mkdir /media/theFolderInYourPC
$ sudo mount -t smbfs -o username=theUsername,password=thePassword //theRemotePCsIP/theRemoteFolder /media/theFolderInYourPC

Links:

Monday, October 05, 2009

[Chat] Just write down what you've learned

When I was searching some solutions for data sorting in Python, I met this article: If you are in tech and don't have a blog.

This article has given two important reasons why we should have a blog to record something we've learned:
  1. For our own reference. We are human beings, and human beings are prone to forgetting things. This is why I write down things here.
  2. For someone else who needs the solutions you've just found or figured out. When someone else are trying to Google the solutions and you happen to have them in your blog, then people might have more chances to find these solutions. That's good!
Just blog it, for recording as well as sharing.

Monday, September 21, 2009

[QnA] memo: USB memory stick booting

Links:
Steps:
  1. $ sudo umount /dev/sdX (if the USB stick has been mounted; X = a, ..., z)
  2. $ sudo mkdosfs /dev/sdX
  3. $ sudo su -c "zcat boot.img.gz > /dev/sdX"
  4. $ sudo mount /dev/sdX /media/mountPoint
  5. $ cp *.iso /media/mountPoint

Before the above steps, the capacity of my 8G USB stick was


After the above steps, it became only several MB


But I don't know what caused this.

Sunday, September 20, 2009

[SW] GHMM in Python: importing problem

In July, I installed a library of HMM called GHMM. When I had no experience about Python and therefore ignored the part of Python bindings. With the amazing capabilities of Python+SciPy, I began to notice the possibility to learm more about HMM using the Python bindings of GHMM. Therefore I followed the installation steps on GHMM webpage and got it worked on one of my PC.

Today, I tried to follow the same procedures to install GHMM in my another Ubuntu and Debian system on another two PCs, but got some problems.

After installing the GHMM as well as the Python bindings, I imported ghmm in iPython but got errors:

ImportError: libghmm.so.1: cannot open shared object file: No such file or directory

I tried to find out whether libghmm.so.1 was installed by using
$ sudo updatedb
$ locate libghmm.so.1

then got
~/ghmm/ghmm/.libs/libghmm.so.1
~/ghmm/ghmm/.libs/libghmm.so.1.0.0
/usr/local/lib/libghmm.so.1
/usr/local/lib/libghmm.so.1.0.0

The messages indicated that the libghmm.so.1 had been in my system, but the Python somehow couldn't find it. So there must be some setting needed to make it work.

There have been some discussions in the mailing lists of GHMM as follows.
[Ghmm-list] cant find _ghmmwrapper
[Ghmm-list] ImportError: libghmm.so.1 ...

With the above information, I add the LD_LIBRARY_PATH into .bashrc as
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

It works. :-)

---
Some information found during my solution-searching:
The 3rd and 4th links are beyond my knowledge, so I decide not to bother with them now... :-p

---
memo (090923): I found the libghmm.so.1 file has been in the path of ``/usr/lib/'' instead of ``/usr/local/lib/'' in the first Ubuntu PC which has ghmm installed without any problem. Therefore I tried to cp the libghmm.so.1 file into the path of /usr/lib/ for the other two PCs and everything is okay now.