8/16/2012

Accessing Gmail Accounts through Mail

Today when I was trying to add my nyu account to mail it always showed the same error message: server rejected your username and password.
 Some people mentioned cleaning the Captcha but it didn't work for my case. So I explored google support and I got the way to figure it out.

First go to account:

Then click on security:

And turn the 2-step verification on (It might require you to login again). After turning it on you will be able Generate new application-specific password by edit Authorizing application and sites.

Each application will need a new password but you will need to enter it once then it's all set.

I still have a lot problems switching from my pc to mac, such as shortcut keys issue and personal settings. And now I should say Mac is a good system, much better than windows in a lot of aspects.

8/05/2012

jQuery plugIn: Fixed header table for IE

For the purpose of building a spreadsheet-like table, I will have to make the table header fixed while the body is scrollable. While in Chrome and Firefox you can accomplish this simply set the css of the table body: scrollable. This does not work for IE. After searching I used one plugin on the internet called http://www.farinspace.com/jquery-scrollable-table-plugin/.
And modified it into my own edition.  To use it, simply type:

$("#"+TABLEID).createScrollableTable();

Code is as below:



(function($) {
$.fn.createScrollableTable = function(options) {
var defaults = {
width: '1160',
height: '600'
};
var options = $.extend(defaults, options);


return this.each(function() {
var table = $(this);
prepareTable(table);
});


function prepareTable(table) {

var tableId = table.attr('id');
var tb = $('#'+tableId);
var wholeWidth = $("#"+tableId).width() > options.width ? $("#"+tableId).width() : options.width;
// wrap the current table (will end up being just body table)
var minheight = 580;
var css;
if (minheight > $("#"+tableId).height()) {
css = {
'width': options.width,
'height': $("#"+tableId).height()+20,
'overflow': 'auto'
};
}else {
css = {
'width': options.width,
'height': options.height,
'overflow': 'auto'
};
}
var bodyWrap = table.wrap('<div></div>')
.parent()
.attr('id', tableId + '_body_wrap')
.css(css);

var thead_tr_first = $('thead tr:nth-child(1)',tb);
var tbody_tr_first = $('tbody tr:first',tb);
var col_width = [];
var w = 0;
var cells_head = thead_tr_first.find('th');
var cells_body = tbody_tr_first.find('td');
if (cells_body.length == 1) {
for (var i = 0; i < cells_head.length; ++i) {
col_width[i] = $(cells_head[i]).width();
}
}
else if (cells_head.length == 0) {
for (var i = 0; i < cells_body.length; ++i) {
col_width[i] = $(cells_body[i]).width();
}
}
else {
for (var i = 0; i < cells_body.length; ++i) {
col_width[i] = $(cells_head[i]).width() > $(cells_body[i]).width() ? $(cells_head[i]).width() : $(cells_body[i]).width();
}
col_width[0] = col_width[0] < 0 ? 20 : col_width[0];
}

var thead_cols = $('thead tr:nth-child(1)',tb).find('td, th');
var tbody_cols = tbody_tr_first.find('td');

var tbh = $('<table class="tablesorter" cellspacing="0"></table>').insertBefore(bodyWrap).prepend($('thead',tb));
tbh.css('width', options.width);
var css_head = {
'width': options.width,
'overflow': 'hidden'
};
var headWrap = tbh.wrap('<div></div>').parent().attr('id', tableId + '_head_wrap').css(css_head);

$.each($('.tablesorter'), function(i, elem) {
$(elem).css('width', wholeWidth);
$(elem).css('table-layout', 'fixed');
});

$.each (thead_cols, function (i, elem) {
$(elem).width(col_width[i]);
// $(elem).css('width', col_width[i]);
});
$.each (tbody_cols, function (i, elem) {
$(elem).width(col_width[i]);
// $(elem).css('width', col_width[i]);
});

bodyWrap.scroll(function () {
headWrap.scrollLeft($(this).scrollLeft());
});
}


function getWidth(td) {
if ($.browser.msie) { return $(td).outerWidth() - 1; }
if ($.browser.mozilla) { return $(td).width(); }
if ($.browser.safari) { return $(td).outerWidth(); }
return $(td).outerWidth();
};


};
})(jQuery);

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