安装 Debian 6.0 Squeeze

 0. Install sudo (open users and groups form System-Administrations, check your username under relevant groups)
1. Install  virtualbox:
   -- add the following line to /etc/apt/sources.list
   $ deb http://download.virtualbox.org/virtualbox/debian squeeze contrib non-free
    --nd then add the public key:
   $wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -
   -- and install
   $ sudo apt-get update
   $sudo apt-get install virtualbox-4.1
   --finally, install extension pack

Two ways to connect a server through a socket

1. using getaddrinfo()

食物搭配禁忌(转载)

蔬菜类

黄瓜:不能与花生同食。
白萝卜:不能与红萝卜混吃,因红萝卜中所含分解酵素会破坏白萝卜中的维生素C。严禁与桔子同食,如同食会患甲状腺肿。同时也不能与梨、苹果、葡萄等水果同食。忌与何首乌、地黄混食。服人参时禁食萝卜。
胡萝卜:不得与酒同食,因为胡萝卜素与酒精一同进入人体,会在肝脏产生毒素,引起肝病。还不宜与西红柿、萝卜、辣椒、石榴、莴苣、木瓜等一同食用,因胡萝卜中含有分解酶,可使其他果菜中的维生素失去。胡萝卜最好单独食用或与肉类一起食用。

How to connect client and server by socket



The steps to establish a socket on the client side:

1. Create a socket with the socket() system call

int socket(int domain, int type, int protocol);

[C++]Function Prototypes in Socket programming

accept()

// sys/types.h
// sys/socket.h

int accept(int s, struct sockaddr *addr, socklen_t *addrlen);

[C++]Structs in Socket Programming

Below are IP structs used in socket programming.

Hash Tables in Java

A Well-known data structure for finding objects quickly is the hash table.  A hash table computes an integer called the hash code, for each object. A hash code is an integer that is somehow derived from the instance fields of an object, preferably such that objects with different data yield different codes.

Install MySQL connector/C++ on Ubuntu 11.04

Here is what I did to install MySQL and connector/C++.
First install MySQL Server.

Then download MySQL connector/C++ from here.
I used the binary file.

Install VirtualBox on Fedora

To solve DKMS failure:

yum install gcc kernel-devel kernel-headers
 
## PAE kernel users install ##
yum install gcc kernel-PAE-devel kernel-headers


Add VirtualBox User to vboxusers Group
usermod -a -G vboxusers user_name

Quicksort

"The quicksort algorithm has a worst-case running time of  Θ(n^2 ) on an input array of n numbers. Despite this slow worst-case running time, quicksort is often the best practical choice for sorting because it is remarkably efficient on the average: its expected running time is Θ(nlgn), and the constant factors hidden in the Θ(nlgn) notation are quite small. It also has the advantage of sorting in place, and it works well even in virtual-memory environments."  [Introduction to algorithms]

Maximum-subarray problem

/*
Maximum-subarray problem
Given an array, find the subarray whose sum is the largest among all of the subarrays. The program prints the left index, right index and the sum of the subarray. The maximum-subarray problem is interesting only when the array containssome negative numbers.
The program uses divide-and-conquer algorithm described on Page68, Introduction to Algorithms.
Of course, this problem can be solved by using loops directly as the second program does.
*/

[C++]Polynomial Class

Polynomial Class
The eval member function uses Horner algorithm.

File: polynomial.h

A 0-1 Knapsack Problem

/*
Input two integers M and N. Find all possible ways that the sum of numbers chosen from 1, 2,3,...N equals M. Print all possible combinations.
*/

Combination of letters

// List all combinations of letters in a string. Suppose no letter is repeated.
// traverse letters from the first one to the last one.
// combination[ ] is used to save the result of each combination.
// layer indicates the number of letters in the combination, also it tells you
// the position of the newly visited letter in combination[ ]
// layer increases by one in each recursion

Sieve of Eratosthen algorithm

Sieve of Eratosthen algorithm is used to find primes.
The following codes(modified) are from Algorithms in C++ and Core Java Volume I.

Palindrome

The following program determines if a given string is a palindrome.
Another way to do this is first to copy the string to another char[] and remove the non- alphabet characters from the string. Then copy it to the third char array and  reverse the order of the string . Finally compare the two strings.

[C++] An implementation of atoi

This is an implementation of atoi function I wrote. Seems it works.

Setup MySql on Ubuntu 11.04

Install MySQL
sudo apt-get install mysql-server-5.1
sudo mysql_install_db
sudo mysql_secure_installation
Then download and install JDBC (connector/J) driver.

MySQL Programming in Java

Connecting to Database:
String url = "jdbc:mysql://hostname:portNumber/databaseName";
String username = "dbuser";
String password = "secret";
Connection conn = DriverManager.getConnection(url, 
   username, password);

Setup MySQL on Fedora 15

yum install mysql-server
Start MySQL server and autostart on boot:
/etc/init.d/mysqld start  ## use restart after update
##OR##
service mysqld start ## use restart after update
chkconfig --levels 235 mysqld on

Acronyms of Programming Terms(DRAFT)

W3C — World Wide Web Consortium
XML — Extensible Markup Language 可扩展标示语言
SGML — Standard Generalized Markup Language
SMTP — Simple Mail Transfer Protocol 简单邮件传输协议
TCP — Transmission Control Protocol
IP — Internet Protcol

Configuration of Eclipse and Tomcat

1. Install Eclipse and Tomcat
Extract compressed files into your desired directories.
2. Create an Environment Variable JAVA_HOME for Tomcat if under Windows environment
Start --> Control Panel --> System --> Advanced --> Environment Variables
--> System Variables --> New :
name: JAVA_HOME
value: "Path to tomcat"

[Java] Renaming a batch of files

Due to some reason, the file names in my MP3 folder begin with two digits like this: 01 file.mp3. It is too tedious to rename them one by one since there are too many (hundreds of them). So I wrote a small program to remove the digits :) .

Block Cellphone Spam Text Message

It's really bothering to receive spam text messages on cell phone.  I got four today!
Here is an article telling you how to block spams.
http://pogue.blogs.nytimes.com/2008/06/12/how-to-block-cellphone-spam/
Hope it works.

Modified gnome-shell theme

Gnome-shell theme looks simple and beautiful. It works so far so good.

Canon D420 Printer Issue on Ubuntu 11.04

After  installing Ubuntu 11.04Beta, the  Canon D420 printer driver can't be installed because it depends on gs-esp which is not supported in the new environment. So here is an alternative way to install the driver.
Download the driver from here.
Extract it and go to its RPM foder.
Install alien which allows you to install rpm file on Debian/Ubuntu:
sudo apt-get install alien dpkg-dev debhelper build-essential 

Finding maximum

/* Finding max number in an integer array
using recursive method.
*/

Josephus Problem

/*
Josephus Problem
N people have decided to elect a leader by arranging themselves in a
circle and eliminating every M th person around the circle, closing
ranks as each person drops out. The problem is to find out which person
will be the last one remaining ( a mathematically inclined potential
leader will figure out ahead of time which position in the circle to take).
From Algorithms in C++.
*/

Connectivity Problem

/*
This program reads a sequence of pairs of nonnegative integers less than N from standard input (interpreting the pair p q to mean "connect object p to object q") and prints out pairs
representing objects that are not yet connected. It maintains an array id that has an entry for each object, with the property that id[p] and id[q] are equal if and only if p and q are connected. For simplicity, we define N as a compile-time constant. Alternatively, we could take it from the input and allocate the id array
dynamically.From Algorithms in C++
*/