Sunday, October 24, 2010

[QnA] Activate the ethernet card of Toshiba L600 laptop (for Ubuntu 10.04)

I've bought a laptop (Toshiba Satellite L600) several days ago. Everything seems alright when I inserted the Live CD of Ubuntu 10.04 to play example audio and video files. So I installed Ubuntu 10.04 in my new laptop. After the installation, I tried to connect to the Internet for system upgrade and found the pppoeconf complained with ``no Ethernet card'' messages.

From the searched results and based on my own incomplete test, here are the steps to activate the Ethernet card of the Toshiba Satellite L600:

Step 1: Check the type of card.
$ lspci | grep Ethernet
04:00.0 Ethernet controller: Atheros Communications AR8152 v1.1 Fast Ethernet (rev c1)


Step 2: Use the keyword of the card to search the driver. What I found is AR81Family-linux-v1.0.1.13.tar.gz

Step 3: Untar the downloaded files and install the driver.
$ make
$ sudo make install
$ cd src/
$ sudo cp atl1e.ko /lib/modules/2.6.32-21-generic/kernel/drivers/net/atlx/
$ sudo depmod -a

Step 4: Reboot the system then go for pppoeconf to set up the DSL connection.

Thursday, October 14, 2010

[Py] Assign values of one list to another

It is easy to ``copy'' lists in Python, but it is also easy to get things wrong, especially when you ignore something important like what I did.

Consider the following situation:
>>> A = [1,2,3]
>>> B = A
>>> B[0]=-1
>>> A
[-1, 2, 3]

What I want is to create a new list B which contains identical elements of the original list A. This doesn't work, however. As you can see in the above test, any modifications made on list B will affect list A. The reason is that when we type ``B=A'', the list B is just another name of list A. They are identical and of course are pointed to the same address. See the following tests:

>>> B is A
True
>>> B.index, A.index
(, )

So, if we need an independent list B which has a set of values' copy in list A, use ``list slicing'':
>>> B = A[:]
>>> B is A
False
>>> B.index, A.index
(, )
---
Ref: An Introduction to Python Lists

[Py] Be careful when create multi-dimensional lists

I wrote a note about the creation of multi-dimensional lists in Python, when I had not yet encountered another problem which have emerged recently. The problem is about appending items to the multi-dimensional lists.

Consider the following example:

>>> A = [[]]*3
>>> A
[[], [], []]
>>> for i in range(3):
...    for j in range(3):
...        A[i].append(i+j)
...
>>> A
[[0, 1, 2, 1, 2, 3, 2, 3, 4], [0, 1, 2, 1, 2, 3, 2, 3, 4], [0, 1, 2, 1, 2, 3, 2, 3, 4]]

But what I really want is something like
A = [[0, 1, 2], [1, 2, 3], [2, 3, 4]]

My guess is that the creation approach doesn't create a list which contains three independent rows, but just create three rows which actually point to the same address or something like that.

The solution (perhaps not the best one) is to create the rows in the form of list comprehension:

>>> A = [[] for rows in range(3)]
>>> A
[[], [], []]
>>> for i in range(3):
...    for j in range(3):
...        A[i].append(i+j)
...
>>> A
[[0, 1, 2], [1, 2, 3], [2, 3, 4]]

Friday, October 01, 2010

[QnA] Change the permission of viminfo to enable the command histroy of Vim

After upgrading from Ubuntu 8.04 to 10.04, I found the command history of Vim was missing. The reason is simple: in Ubuntu 10.04, the ~/.viminfo file has a 600 permission so only the root can access it.

To get the command history of vim back, you may change the permission from 600 to 666. I don't know whether this change has any side effects, however. At least for only one user using one computer, this is a quick trick. :-)

---
Ref: