6/20/2012

Connecting Sybase with PHP

Firstly ensure you installed PHP with Sybase with ./configure.

./configure --prefix=/apps/solace/php --with-apxs2=/apps/solace/apache/bin/apxs --with-libxml-dir=/home/tptools/Linux/x86_64 --with-png-dir=/home/tptools/Linux/x86_64 --enable-bcmath --enable-mbstring --enable-sockets --with-mysql=/home/tptools/Linux/x86_64/vendor/mysql-5.1.36-linux-x86_64-glibc23 --with-sybase-ct=$SYBASE/version#

the SYBASE variable should set to the home dir of sybase. And the hostname will be in the sybase interfaces file.

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc35823_1500/html/uconfig/X41537.htm

Here is some sample code to setup connection with Sybase:
<?php 
$conn=sybase_connect('DATABASE_NAME','USERNAME','PASSCODE')
or die('Could not connect: ' . mysql_error());

if (!sybase_select_db('SUB_DATABASE',$conn)) {
echo "Can't select database\n";
exit;
}
echo "Connected!";
sybase_close($conn);
?>


And if you see the message Could not connect: It is the parameter you set for the connection incorrect.

Or you haven't setup your local tomcat environment file in apache's bin directory envvars file.
Add 
SYBASE=/usr/local/sybase
export SYBASE

and start tomcat again with apachectl start. you will be fine.
If you don't like the warnings popping up, go to the php.ini file (which should be in your php's lib dir, or try phpinfo() to see where the ini file is) and change the warning settings.


Don't forget to setup the root environment variables:

setenv SYB_USER username
setenv SYB_PASSWD password

6/19/2012

Yii: Awesome PHP Framework


This framework looks fantastic.
look at the chart, it supports everything.




By the way, when try to install mysql on linux, mysql will firstly search the option file in /etc/my.cnf, then ~/.my.cnf which is under your $HOME directory. Remember to configure the file to get server connected. If you get any error message like socket error, cannot connect to server, and you have not specify the hostname, username or password, probably your option file is not setup properly.


http://dev.mysql.com/doc/refman/5.5/en/option-files.html#option_general_defaults-extra-file

Strangely, I have to connect mysql with
[wshi@nycdlvapoc002 mysql-5.5.25]$ mysql -u username -p
instead of user=root. And if you like to use root by default just create an user.

http://dev.mysql.com/doc/refman/5.1/en/adding-users.html

6/16/2012

Remote debugging with eclipse

Debugging java application or web application on server is very painful with a lot of reasons. Here I set the server and client the same computer.

I used eclipse here so make sure you installed eclipse

Setup Server:
Assume you've finished your java code and looks like below:

public class ForInterview {
        public static void main(String[] args) {
String a = "ARMZM2G002825";
float b = genIndex(a);
float d = (float) 5.020802E24;
System.out.println(b == d);
int c = 'Z' - '\u0030';
System.out.println(c);
    }
}

Export the project/ForInterview.jar into some directory where you regard as the server. You can save it on your local machine or remote server. 

Then run 
    java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000 -jar    ForInterview.jar 
You'll see Listening for transport dt_socket at address: 8000
Now the server is waiting for debug command. 
// From java5 you can run  -agentlib:jdwp instead of -Xdebug -Xrunjdwp

Setup Client:
Right click on eclipse Run->Debug Configuration->Remote Java Application and setup the client as the graph below:


You can change whatever Host or Port as the server needed. But I think if the server require permission, there might be a problem, I haven't try that.

6/15/2012

Installing Apache+PHP on Redhat


A good habit is to do 'make clean' everytime you configure, or sometimes you will get something like symbol undefined error during compile time

Installing apache and php onto server:
http://unclean.org/howto/apache-php-mysql.html
http://www.php.net/manual/en/install.unix.apache2.php

(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
The description is indicate that i do not have enough privileged to bind the port for Apache http server. In Unix / Linux, only some privileged users are allow to bind the port between 1 to 1024. Apache http server is using port 80 as default.
Edit the config file to change the port Apache uses to a number greater than 1024.

When you successfully installed it should show the 'It Words' on your Server.
And remember to add the following to your conf/httpd.conf file: (or if you use 4, 3, change it to php4,3, etc)

 LoadModule php5_module        modules/libphp5.so
 AddType application/x-httpd-php .php .phtml     
 AddType application/x-httpd-php-source .phps

6/12/2012

Some useful metarials before working on

Source for SVN, clear enough:
http://svnbook.red-bean.com/nightly/en/svn.branchmerge.basicmerging.html

Time series database, used to log server data stream:
http://oss.oetiker.ch/rrdtool/tut/rrdtutorial.en.html
http://forums.cacti.net/about12202.html
http://www.fromdual.com/sites/default/files/rrd.pdf

It's really annoying to install rrdtool on unix. reference is:
http://oss.oetiker.ch/rrdtool/doc/rrdbuild.en.html#___top


It takes me a while to figure how to install source code onto my redhat server.
If I downloaded a .xz file, firstly I will have to install xz. using
./configure --prefix=SOME_DIRECTORY
make
make install
then set
PATH=SOME_DIRECTORY/bin:$PATH

command is: xz -d FILENAME ##-d is decompress -c is compress
xz actually is a more powerful tool than gz and bz

It's the same when installing all libraries we need, except we need to add some attributes to configure, make and install. eg. set the CFLAGS and LDFLAGS is probably needed if you are installing application on a server.

If there is a command not found, it might be that your environment variables are not correct. If there is a no file or directory, probably something wrong

When installing glib and you receive
1. glib AttributeError: 'dict' object has no attribute 'has_key'
it's probably because you're using the wrong python version. glib only support python 2.5-2.7
To change verstion all you need is adding the bin directory of your corrent version into PATH
setenv PATH SOMEPLACE/python2.5/bin
someplace is where your python is installed

2. keyword "msgctxt" unknown error

it usually is the gettex (a language support tool) is not installed. By installing it the problem will be fixed



6/01/2012

Dealing with Large Dataset

There are several ways to make the process of large dataset more effecient.

1. Compress technique:
    Try to use a link to every same element in the data instead of storing the copy of it.
    eg. if "Umbrella" appears in the data for couple times, then save just one Copy of them, and use link point to the word every other time it appears. In java, there is a method intern() that can compress a string.

2. Index Hashing:
    Hash every appeared element with an integer. Through this way you can save a lot of space.
    eg. "This is Mike and this is Jane." We want to calculate the probability of every word's appearance. If every word has probability and we saved as a Hashtable Counter <String, Double> where string represents every word in the sentence and every double represents the probability of the word's appearance. The probability of "this" is<"This", 2/7>.
    Then we can modify this into Hashtable IndexMap<String, Integer>+Hashtable Counter<Integer, Double>. Here IndexMap is an index for every string and Counter is an index and the probability. So we can search "this" in the IndexMap for the index and find the probability of "this" with the index.
    This technique saves a lot time because we are not using string in hashing anymore.

3. Use Float whenever possible instead of Double. Obviously, this is because Float is half the size of Double.

4. Use primitive collections instead of java.util.collections if your datatype is primitive type. This saves at least half of space and mostly 85% of space.