2009-08-30

"Acquiring network address" problem of wireless LAN

Max's laptop has a problem of wireless connection, status is stuck always at endless "Acquiring network address". The reason lies on the client adaptor doesn't support the encryption method used in router. Solution is found here
  1. Change SSID in rounter to create a new profile.
  2. Use basic WEP 64bit ASCII encryption.
  3. now wireless works.

2009-08-21

apt-get install without debian CD

For a fresh Debain installed from a CD, if someone wants to use apt-get install some packages, you may get the following error:

'Debian GNU/Linux 5.0.2a _Lenny_ - Official i386 CD Binary-1 20090817-00:24'
in the drive '/cdrom/' and press enter

if you have taken out the debian CD for a long time.
It is because that by default CD installation, apt-get will always check if your desired packages can be found in cdrom at first. Solution is simple, comment out the first item in your /etc/apt/sources.list

#deb cdrom:[Debian GNU/Linux 5.0.2a _Lenny_ - Official i386 CD Binary-1 20090817-00:24]/ lenny main

2009-08-20

Setup SVN+SSL server at home

Max finally setup a svn server at home.

0) Install Debian Lenny
1) DynDNS dynamical update your IP to dns
2) Set Port forwarding on router, open 80 (HTTP) and 443 (HTTPS)
3) Install apache + ssl. Some workaround about missing script.
4) If you get following message when you restart "/etc/init.d/apache restart". You need to read this artical
># /etc/init.d/apache2 restart
Restarting web server: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

5) Install and setup svn.

2009-08-14

Upload your DHCP IP to FTP server

1) create ip_ftp.bat
====ip_ftp.bat ==========

@echo off
curl.exe http://whatismyip.com/automation/n09230945NL.asp > ip.txt
ftp.exe -s:ftp.txt.bat
2) create ftp.txt.bat
==== ftp.txt.bat ==========
open $ftpserver
$ftpuser
$password
put "ip.txt"
bye
3) download curl.exe to the same fold
4) Run ip_ftp.bat
5) Check if upload success by "curl.exe $server/ip.txt" (your IP will be shown)
6) Put your script into scheduled tasks

Some useful tips about x-window

1) Where to check, if xwindow fails? Answer
2) How to install xwindow? Answer
3) How tow switch start level ? Textual or Desktop? Answer

2009-08-13

Extract DHCP dynamic IP

A previous article has explained how to extract static IP using a batch. But if your computer has a dynamic IP assigned by DHCP server, how can you get your IP? ipconfig? let's see.



Look! You just got an useless local IP 192.168.x.x.
  • Where is your current WAN IP? Click here. Now you got a your real IP, at right now.
  • Why this happens? See the explanation here. The reason is your router. It determines the IP in WAN, but you or your code can only get it a LAN IP from it.
  • How let your script get the WAN IP? Try this! "curl http://whatismyip.com/automation/n09230945NL.asp". Of course, you need to install the curl at first.
  • How to let your code get WAN IP? Use libcurl.

Qt - signals and slots

Max is used to be a hardcore supporter of fox-toolkit for C++ GUI developement. Fox is a good, free and cross-system library. But Max always has some kinds feeling that Fox-toolkit may miss something important. Until today Max read something about Qt, another open source GUI library, he came to realize that fox-toolkit may somehow be short of good communications between different components. Interaction between Fox GUI components is possible but not straight forward. In contrast to Fox-toolkit, Qt uses a smart way - signals and slots - to let different component to talk to each other.

See the introduction of "Signals and Slots".



From the design pattern point of view, "Signals and Slots" in a certain sense follows the idea of "Command Pattern". The basic idea is to let two objects to work together, but they don't need to know each other. It sounds a little wired, but it can significantly simplify the design, coding and maintaining. With help of this mechanism, components can be better encapsulated and full decoupled to each other. The connection between objects is built up by a simple QObject::connect() function calls. You can connect as many signals as you want to a single slot, and a signal can be connected to as many slots as you need.

The other common methods for the interaction between GUI objects:
  • Callback function
  • Event
  • Data binder.


Reference:

batch file to extract static IP

If you installed VMware in your windows computer, more IPs will be displayed by ipconfig. How to seperate your static IP from VM IP? Good news: all vm IP start with 192.168. See the following batch:




@echo off

IPCONFIG |FIND "IP" | FIND /V "192.168" > %temp%\TEMPIP.txt
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
set IP=%IP:~1%
echo %IP% >%temp%\ip.txt
echo The current IP address is "%IP%"

2009-08-11

DHCP at home

DHCP is short for Dynamic Host Configuration Protocol. Most of house computers access the internet as DHCP clients. For example, as Max starts his house computer, as a DHCP client, it sends request to DHCP server (owned by ISP) and get a response with a dynamical configuration information of network:
  • IP Address
  • Subnet Mask
  • Default Gateway
  • DNS server
  • ...
The most important is IP address. DHCP client will never get a static IP for a long term. For example, T-online (ISP) automatically recycles all the IPs and assigns a new IP to your computer (DHCP client) in 24 hours. Actually, all the DHCP server has somehow been configured that client IP will be reassigned within a certain time span and IP ranges. What is DHCP good for? Because static IP is valuable resource of www, while DHCP is enable to more efficiently reuse the IP resource.

Just have a fun. If some marketing people of ISP keep bothering you with some blabla.., just ask him this question:

"Could you provide me a static IP with this price?"

He will shut up immediately. Trust me.

2009-08-10

How to switch between diff gcc version?

You don't need to uninstall or reinstall anything in Debian. Take an example, you want to compile some code with gcc 4.3 und gcc 4.1 and compare the performance.

As root:
1) Install both of them
  • >apt-get install gcc 4.1
  • >apt-get install gcc 4.3
2) You could find both gcc exist at /usr/bin
  • >ls gcc*
3) Assume you want to set gcc 4.3 as default c compiler.
  • >cd /usr/bin
  • >ln -s gcc-4.3 gcc (create a symbolic link)
  • >export CC=/usr/bin/gcc (set variable)
  • Now you can complie you code now (e.g make)
4) If you want to use gcc 4.1, do the same thing as above.

In the most case, it works well.

2009-08-09

google code hosting

Max is looking for a cost-free way to share the code with partner in Shanghai. Someone in the forum says: "If you start an open source project, try SourceForge or Google Code Hosting." SourceForge is well-known, it still has 24 million unique visitors, 2 million downloads a day and 125,000 active projects. While Google Code Hosting is something brand new, from last week. Some features are not yet offered. Even though, Max's first trial come out positive feedback.

Here is a sample of google code project. Have you see it? It has everything already! Version control with svn, source browser, issue tracking, wiki, project block, member management, auto document. See FAQ to get know more about this new stuff.

Max likes google team, these google guy make complicated thing simple, make simple thing classic. It was one of his dreams to be a member of google team in one day. Ok, forget about it. Too emotional! Be cold.

Private Project is not yet availalbe in Google Code Hosting.
For something good, we need to be patient. Let's wait.


References

Buildroot for AT91SAM9261_EK (II)

The first try fails. Too bad!
Building was blocked by some funny miniperl issues. It looks not so simple.

ext/util/make_ext: line 122: ../../miniperl: No such file or directory Warning: No Makefile!

Reverse gcc compile:
  • gcc 4.3 => gcc 4.1
  • g++ 4.3 => g++ 4.1
Max tried to change the configuration in following way. Maybe it works.
Target Architecture (arm)
Target Architecture Variant (arm926t)
Target ABI (OABI)
The rest settings use default ones.


After about 30 minutes, it seems that building success. At least no error message come out. See the root.
user@debian:~/buildroot$ ls -l
total 116
drwxr-xr-x 3 user user 4096 2009-08-09 14:06 binaries
drwxr-xr-x 9 user user 4096 2009-08-09 15:00 build_arm
-rw-r--r-- 1 user user 7190 2009-08-09 13:18 CHANGES
-rw-r--r-- 1 user user 10673 2009-08-09 13:18 Config.in
-rw-r--r-- 1 user user 17987 2009-08-09 13:18 COPYING
drwxr-xr-x 2 user user 4096 2009-08-09 15:00 dl
drwxr-xr-x 3 user user 4096 2009-08-09 13:18 docs
-rw-r--r-- 1 user user 17396 2009-08-09 13:18 Makefile
drwxr-xr-x 303 user user 12288 2009-08-09 13:18 package
drwxr-xr-x 2 user user 4096 2009-08-09 13:18 project
drwxr-xr-x 3 user user 4096 2009-08-09 14:06 project_build_arm
drwxr-xr-x 3 user user 4096 2009-08-09 13:18 scripts
drwxr-xr-x 21 user user 4096 2009-08-09 13:18 target
-rw-r--r-- 1 user user 806 2009-08-09 13:18 TODO
drwxr-xr-x 13 user user 4096 2009-08-09 13:18 toolchain
drwxr-xr-x 18 user user 4096 2009-08-09 14:43 toolchain_build_arm
Strange!

After some tries, Max located the problem. Building fails due to "EABI", a feature of targeting toolchain to optimize the floating point computation. See the following test.
  • gcc 4.3.1 + EBAI => Fail
  • gcc 4.1.1 + EBAI => Fail
  • gcc 4.3.1 + OBAI => Success
  • gcc 4.1.1 + OBAI => Success
Reference:

2009-08-08

Etch Lenny Sid

Max installed Debian Lenny Server in last week. Since then he saw different Debian name in the internet, like Debian Etch, Debian Sid. He wondered what those funny "nicknames" mean? The answer is a big surprise:
  • Etch: old stable
  • Lenny: stable
  • squeeze: testing
  • Sid: unstable
He is using a stable Debian system right now. Klasse!

Buildroot for AT91SAM9261_EK

It is the first time for Max to play Buildroot. Hopefully, it's not the last time.
The target system is an evaluation board of ATMEL "AT91SAM9261_EK". Buildroot tools will generate following things for the target system.
  • Customizing the target filesystem
  • Customizing the Busybox
  • Customizing the uClibc
  • Customizing the packages
  • HelloWorld Project
  • ....
In a word, a brand new system for target board.

About download and install the Buildroot tools, please check here.
1) Start from ${buildroot}
> make menuconfig

2) Configuration.
Max took the most default setting and customized the configuration as following (who knows, let's just have a try!) . In the end, a .config file will be generated at ${buildroot}


Target Architecture (arm)
Target Architecture Variant (arm926t)
Target ABI (EABI) See the reason here.

Target Options:
Project options:
Project name (HelloWorld)
hostname (syn_at9261_0)
banner(Welcome to HelloWorld)

Generic serial port config:

Serial port to run a getty on (ttyS0)
Baudrate to use (115200)


ToolChain
[*] Build/install c++ compiler and libstdc++?
[*] Use ARM Vector Floating Point unit

Package Selection for the target
[*] make
Graphic libraries and applications (graphic/text)
[*] Qt
Target filesystem options
[*] Das U-Boot Boot Monitor --->
board name (at91sam9263-ek)



3) Build it and finish.
  • >make
Ok!Ok! I lied. It is not so easy. Usually you need do something more. You need to download some necessary packages. Can you handle it yourself? Tell me "yes, yes, yes". Only one nasty thing you may encounter is the failures of some sanity tests. See this page for the solution. The most problems occurs in the first 2 minutes. Afterwords, you can take a coffee and chat with your friends.

Till now, the building has not yet finish. Max's host system is debian Lenny at VM. It will take sometime. To be continued....

2009-08-06

About toolchain

What is Toolchain?

Toolchain, more precisely, cross-compilation toolchain is a set of tools to build binary files for your target system. Let me explain in this way, you have coded a c program on a PC with Debian 5.0 system and x86 CPU (host system). Now you want to build to the c file to an executable and let it run in a board with ARM processor (target system). Cross-compilationToolchain will help you to build your binary file for the specific target system, based on your current host system.

What does a Toolchain have?
  • Compiler (gcc),
  • linker and assembler (binutils),
  • C standard library (uclib)

How to get a Toolchain?

Usually you can get toolchain from the board provider. Or build your own using Buildroot.
See the artical.

What do you need to know before build a Toolchain?

To be continued...

Predicate Delegation

C#2.0 has introduced several interesting grammars into simple c++ style coding. "Predicate Delegation" is one of them. From the point of linguistic semantics, a predicate is an expression that can be true of something. In the C#, predicate delegation is a reference of function, whose return value is true or false. Why do we need it? Because predicate delegation works like a filter and make search operation among a collection (List, IEnumerable) simpler and clearer. Let me paste the example from here

Here is a common c type function to return odd numbers from an array.


int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] odds = GetOdds(numbers);
private static int[] GetOdds(int[] numbers)
{
int[] odds = new int[numbers.Length];
int counter = 0;
for (int i = 0; i < numbers.Length; i++)
{
if ((numbers[i] % 2) != 0)
{
odds[counter++] = numbers[i];
}
}
return odds;
}
Using Predicate Delegation the above program can be simplified as
int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };        
int[] odds = Array.FindAll<int>(numbers, IsOdd);

private static bool IsOdd(int number)
{
return ((number % 2) != 0);
}
Powerful! Isn't it?

use sudo

sudo is the command that allows you run some commands using other login, without switch user at first. Of cousre, you need to tip the corresponding password. For exmple
  • >sudo less /var/log/boot
To see the boot log, you need to be root. But sometimes even the correct password is given, you still got the following error message.

[sudo] password for user:
user is not in the sudoers file. This incident will be reported.

Error message is self-exlained. You need to edit sudoers file, which is located at "/etc/sudoers". As root, you can edit the file by
  • >vis /etc/sudoers
  • Add "user ALL=(ALL) ALL" into it
Now sudo should work. /etc/sudoers is very powerful to manange which user can run which program. See more tricks in "sudoers file".

2009-08-05

Putty connets to local VM

On the windows host, Max prefers to use Putty console instead of directly using VM windows to play the local Linux VM. Everyone know it. Since Putty uses SSH protocol to connect to server, it is logical that we have to install SSH daemon on the Linux VM Guest at first.


1) Install SSH package
>apt-get install openssh-server

2) Start SSH Daemon
>/etc/init.d/ssh restart

3) Get IP of guest
>ifconfig

4) Start Putty from Windows Host and connect to the Guest IP


Share folder of Debian VM

VM guest and host share data by hgfs service.
Eniviroment:
  • Host: WindowsXP
  • Guest: Debian 5.0 Lenny Server
  • VMware: VMware player 2.5.2
1) Install vm tools in Debian VM. Or directly download a Vmware Tools installed Appliance.
2) Check the boot log, if VMTools deamon is started.
2) Edit *.vmx, add following text in the end.

isolation.tools.hgfs.disable = "FALSE"
sharedFolder0.present = "TRUE"
sharedFolder0.enabled = "TRUE"
sharedFolder0.readAccess = "TRUE"
sharedFolder0.writeAccess = "TRUE"
sharedFolder0.hostPath = "D:\work\share\"
sharedFolder0.guestName = "win-share"
sharedFolder0.expiration = "never"
sharedFolder.maxNum = "1"

3) Enable the share fold by menu:
VMware Player->Share folders->Always enable

share folder is found at /mnt/hgfs/${sharedFolder0.guestName}

boot log

How to check see the boot log? Simple!
  • >vim /etc/default/bootlogd
  • >BOOTLOGD_ENABLE=Yes
  • >reboot
  • >less /var/log/boot
Actually you can find more logs in /var/log.

2009-08-04

Install VMware Tool in Debian VM

VMware Tool is important not only for performance but also for sharing folder between host and guest. Be default, VMware tool won't be installed for VMware Player, only available for VMware Workstation. However, VMware tool doesn't require any cost licences for installation. With some tricks, VMware Player can also use VMware Tools. Someone has explained how to do it in the case of "Linux Host/ Window Guest". In the following, we are going to talk about how to install the VMware tool in the case "Windows Host/Linux Guest".
  • Host: WindowsXP SP2
  • Guest: Debian 5.0 Lenny Server
  • VMPlayer: 2.5.2
1) Download "VMware Server 2". Pick up tar image, not the rpm and exe.

2) Extract vmware-server-distrib/lib/isoimages/linux.iso from the tar.gz file and copy to a usb stick.
  • tar xvzf VMware-server-*.tar.gz vmware-server-distrib/lib/isoimages/linux.iso
3) Mount usb stick in Vmware player.
  • Devices->${USB_STICK}->Connect.
  • >mkdir /media/usb
  • >mount -t vfat /dev/sdb1 /media/usb
4) Mount linux.iso in Debian guest and fetch VMwareTools-???-.tar.gz
  • > su
  • > mkdir /tmp/vmware_tools
  • > mount -o loop linux.iso /tmp/vmware_tools
  • > cp /tmp/vmware_tools/VMwareTools-*-.tar.gz /tmp/
5) Extract the VMwareTools-*-.tar.gz
  • >tar xvzf VMwareTools-*-.tar.gz
6) Install Vmware Tools. Choose the default setting. If some packages (make, psmisc, gcc, linux-header) are missing, you need to update or install by apt-get.
  • > /tmp/vmware-tools-distrib/vmware-install.pl
Reference:

7) Reboot
  1. Installing VMware Tools on Debian Lenny 5.0.2 with gnome destop on ESX server 3.5 update 4
  2. VMware Tools failed to build vmmemtcl module
  3. proxy problem of apt-get update
  4. The path “/usr/src/linux/include” is not an existing directory

2009-08-03

gconftool - preferences setting

As Max seeked to setting Proxy for his Debian VM, he found an interesting configuration tool in GNOME, "gconftool", which is used to manage all kinds of appliation preferences, i.e, proxy server, desktop and so on. He decided to spend sometime to learn it.

The cool thing is that " if someone changes a setting by gconftool, it instantly updates in all the applications that interested in this setting" . Simple but powerful, thousand times better than nasty Windows Registry. Take the example of set proxy server in article "Make Debian work better" Let's see how it work:

  • > gconftool -s /system/http_proxy/use_http_proxy -t bool true
  • > gconftool -s /system/http_proxy/host -t string ${PROXYSERVER}
  • > gconftool -s /system/http_proxy/port -t int ${PORT}
  • > gconftool -s /system/http_proxy/use_same_proxy -t bool true
  • > gconf -s /system/proxy/mode -t string manual

No news is good news! At the time, if you open System->preference->Network Proxy, you would find all the settings have been updated, without logout or restart. More explaination in detials can be found in Victor's blog .

Where are these preference value saved? Here you are:

>cat .gconf/system/http_proxy/%gconf.xml


You see, so-called repository is nothing but a just well-structured xml data. More precisely, the repository is not single xml but a series of xml in different storage locations (Configuration sources). You can search a preference in repository as

> gconftool -g /system/http_proxy/port
81

Or recursively show all preference in the path

> gconftool -R /system/http_proxy

use_http_proxy = true
use_authentication = false
host = ${PROXYSERVER}
authentication_user =
ignore_hosts = [localhost,127.0.0.0/8]
use_same_proxy = true
authentication_password =
port = 81

By default, GConf searches the xml files in the following order:

  • xml:readonly:/etc/gconf/gconf.xml.mandatory (w:root)
  • include "$(HOME)/.gconf.path"
  • xml:readwrite:$(HOME)/.gconf (The above setting is save here)
  • xml:readonly:/etc/gconf/gconf.xml.defaults (w:root)

Make Debian work better

Max begins to play Debian + VMWare on his firm computer. In the following are some userful tipps to make the system run better in a company computer enviroment.
0) How to change keyboard layout
  • >su
  • >dpkg-reconfigure console-data
1) How to disable the annoying Beep of Gnome concole?
The noise really bother his office mates. But more important, it brokens Max's style: being quite. Let's make it off.

  • a) Click on Applications > Accessories > Terminal
  • b) Now click on Edit Menu > Current Profile
  • c) Click on General Tab > General > Remove check box (Terminal bell)
  • d) Add "setterm -blength 0" into /etc/profile

2) How to set the proxy server?
Without google Max cannot work at all. Many companies allow users to access internet only throught Proxy server, not the default DCHP.

a) In order to make the apt-get work, by the way apt-get is the program in Debian to automatically update installed packages, very useful.
  • >su (switch root)
  • >cd (go to home)
  • add "export http_proxy=${PROXY_SERVER}:${PORT}" in the file /etc/profile.
  • >apt-get update

b) In order to make the internet brower works.
  • 1) System>Preferences>Network proxy
  • 2) Select Manual proxy configuration
  • 3) USe the same proxy for all protocal
  • 4) Input proxy server and port.

2009-08-02

Learning is a way

Max is an engineer, not good, not bad. But he loves all kinds of computer techniques, coding, hack skills, whatever.... He kept learning and learns everything fast. But one day, he found a strange thing. As he learned more, he found out more open questions. He asked himself "does it make any sense? A person that konws more but in the end find himself more stupid. Why should he keep learning, like an idiot?" This question puzzles him for a long time. Till one day, he read a word from Buddha:

"Es gibt keinen Weg zum Glücklichsein, Glücklichsein ist der Weg."

Now Max feels better and starts to write this blog, to remember the every tiny joy experienced in his long match of learning techniques. At least he won't be alone...