Archive for the ‘Programming’ Category

Java程序优化过程及linux相关

Friday, March 5th, 2010

1.Jprofile找到程序性能的瓶颈
2.需要很长时间完成的过程由单线程转多线程或线程池。假如是IO之类的问题(普遍IO是系统的瓶颈),采用NIO即rector模式处理
3.大量小文件压缩后存入内存,定量写入硬盘。大量中间变量存入内存,或序列化压缩后存入内存,后解压反序列化调用
4.使用Queue进行不同过程的缓冲
5.Linux下普遍有打开文件个数限制,消除1024限制:ulimit -n 8192
6.JVM普遍内存限制,消除内存限制:增加运行参数 -Xms20m -Xmx200m

另:
1.如何执行jar中某个类的main方法: java -cp test.jar com.acosys.clawer.GetContent
2.如何让java程序在linux后台运行: nohup … &
3.如何查看linux后台运行的nohup程序列表: jobs
4.后台FTP上传下载工具: ncftpget ncftpput
5.如何查找linux后台程序列表 ps aux | grep …
6.强行终止linux程序: kill -9 …
7.查某文件夹下文件数目: ls -l |grep “^-”|wc -l
8.执行多个依赖库的java程序:java -cp nutch-1.0.jar:commons-logging-1.0.4.jar:hadoop-0.19.1-core.jar:xerces-2_6_2.jar org.apache.nutch.tools.DmozParser content.rdf.u8 > domz/urls

Online php debug method

Sunday, January 10th, 2010

Put the following code in your php code.
<code>
echo ‘<!–’;
print_r($display);
echo ‘–>’;
</code>
you will see your debug messages in your html source code.

Make user inputed variables translatable in drupal

Sunday, January 10th, 2010

Add variables in settings.php

$conf['i18n_variables'] = array(
// Site name, slogan, mission, etc..
’site_name’,
’site_slogan’,

);

or if it is your module you can do like this:

/**
* Implementation of hook_init().
*/
function uc_cart_init() {
global $conf;
$conf['i18n_variables'][] = ‘uc_cart_breadcrumb_text’;
$conf['i18n_variables'][] = ‘uc_cart_help_text’;
$conf['i18n_variables'][] = ‘uc_cart_new_account_details’;
$conf['i18n_variables'][] = ‘uc_checkout_instructions’;
$conf['i18n_variables'][] = ‘uc_checkout_review_instructions’;
$conf['i18n_variables'][] = ‘uc_continue_shopping_text’;
$conf['i18n_variables'][] = ‘uc_minimum_subtotal_text’;
$conf['i18n_variables'][] = ‘uc_msg_continue_shopping’;
$conf['i18n_variables'][] = ‘uc_msg_order_existing_user’;
$conf['i18n_variables'][] = ‘uc_msg_order_logged_in’;
$conf['i18n_variables'][] = ‘uc_msg_order_new_user’;
$conf['i18n_variables'][] = ‘uc_msg_order_submit’;
}

Make your contributed drupal modules translatable in translate interface of i18n

Sunday, January 10th, 2010

For variables in your codes:
Step 1:

/**
* Implementation of hook_locale().
*/
function casetracker_locale($op = ‘groups’) {
switch ($op) {
case ‘groups’:
return array(‘case_tracker’ => t(‘Case Tracker’));
}
}

Setp 2:
if(module_exists(‘i18nstrings’)) {
$options[$state->csid] = tt(‘case_tracker:state:’. $state->csid .’:options’, $state->name, NULL, 1);
}
else
{ … }

something about the cron permission of drupal

Tuesday, December 29th, 2009

drupal cron has no permission to do node save and anything related to permission.
But we should not hack the core to remove the permission feature of cron, because
the index module aquire this feature.
How to call api related to permission?
Just give the cron some permission in your functions. See http://drupal.org/node/494810