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
Posted at
10/11/2011 02:35:00 PM
1. using getaddrinfo()
食物搭配禁忌(转载)
Posted at
10/11/2011 07:36:00 AM
蔬菜类
黄瓜:不能与花生同食。
白萝卜:不能与红萝卜混吃,因红萝卜中所含分解酵素会破坏白萝卜中的维生素C。严禁与桔子同食,如同食会患甲状腺肿。同时也不能与梨、苹果、葡萄等水果同食。忌与何首乌、地黄混食。服人参时禁食萝卜。
胡萝卜:不得与酒同食,因为胡萝卜素与酒精一同进入人体,会在肝脏产生毒素,引起肝病。还不宜与西红柿、萝卜、辣椒、石榴、莴苣、木瓜等一同食用,因胡萝卜中含有分解酶,可使其他果菜中的维生素失去。胡萝卜最好单独食用或与肉类一起食用。
黄瓜:不能与花生同食。
白萝卜:不能与红萝卜混吃,因红萝卜中所含分解酵素会破坏白萝卜中的维生素C。严禁与桔子同食,如同食会患甲状腺肿。同时也不能与梨、苹果、葡萄等水果同食。忌与何首乌、地黄混食。服人参时禁食萝卜。
胡萝卜:不得与酒同食,因为胡萝卜素与酒精一同进入人体,会在肝脏产生毒素,引起肝病。还不宜与西红柿、萝卜、辣椒、石榴、莴苣、木瓜等一同食用,因胡萝卜中含有分解酶,可使其他果菜中的维生素失去。胡萝卜最好单独食用或与肉类一起食用。
How to connect client and server by socket
Posted at
10/04/2011 02:04:00 PM
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
Posted at
9/27/2011 07:20:00 PM
accept()
// sys/types.h // sys/socket.h int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
[C++]Structs in Socket Programming
Posted at
9/27/2011 07:20:00 PM
Below are IP structs used in socket programming.
Hash Tables in Java
Posted at
9/17/2011 06:02:00 PM
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
Posted at
9/01/2011 07:00:00 PM
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.
First install MySQL Server.
Then download MySQL connector/C++ from here.
I used the binary file.
Install VirtualBox on Fedora
Posted at
8/16/2011 07:31:00 PM
To solve DKMS failure:
Add VirtualBox User to vboxusers Group
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
Posted at
8/01/2011 05:16:00 PM
"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
Posted at
7/14/2011 07:28:00 PM
/*
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.
*/
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
Posted at
7/13/2011 06:10:00 PM
Polynomial Class
The eval member function uses Horner algorithm.
File: polynomial.h
The eval member function uses Horner algorithm.
File: polynomial.h
A 0-1 Knapsack Problem
Posted at
7/13/2011 01:36:00 PM
/*
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.
*/
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
Posted at
7/13/2011 09:02:00 AM
// 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
// 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
Posted at
7/06/2011 10:51:00 AM
Sieve of Eratosthen algorithm is used to find primes.
The following codes(modified) are from Algorithms in C++ and Core Java Volume I.
The following codes(modified) are from Algorithms in C++ and Core Java Volume I.
Palindrome
Posted at
7/05/2011 09:09:00 PM
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.
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
Posted at
7/05/2011 06:07:00 PM
This is an implementation of atoi function I wrote. Seems it works.
Setup MySql on Ubuntu 11.04
Posted at
6/23/2011 11:06:00 AM
Install MySQL
sudo apt-get install mysql-server-5.1 sudo mysql_install_db sudo mysql_secure_installationThen download and install JDBC (connector/J) driver.
MySQL Programming in Java
Posted at
6/23/2011 11:05:00 AM
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
Posted at
6/23/2011 11:04:00 AM
yum install mysql-serverStart 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)
Posted at
6/23/2011 11:02:00 AM
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
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
Posted at
6/23/2011 11:00:00 AM
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"
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
Posted at
6/23/2011 09:41:00 AM
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
Posted at
4/29/2011 09:15:00 PM
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.
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.
Canon D420 Printer Issue on Ubuntu 11.04
Posted at
4/04/2011 02:49:00 PM
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:
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
Posted at
2/14/2011 11:57:00 AM
/* Finding max number in an integer array
using recursive method.
*/
using recursive method.
*/
Josephus Problem
Posted at
2/12/2011 06:21:00 PM
/*
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++.
*/
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
Posted at
2/12/2011 10:11:00 AM
/*
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++
*/
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++
*/
Subscribe to:
Posts (Atom)