Custom Function – getElementsByClassName

[codesyntax lang=”javascript”]

document.getElementsByClassName = function(className) {
    var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
    var allElements = document.getElementsByTagName("*");
    var results = [];

    var element;
    for (var i = 0; (element = allElements[i]) != null; i++) {
        var elementClass = element.className;
        if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
            results.push(element);
    }
    return results;
}
var items = document.getElementsByClassName('anyClassName');
for (i = 0; i < items.length; i++) {
    // do your actions with items[i]
}

[/codesyntax]

Posted in JavaScript | Tagged | Leave a comment

My /etc/rc.local in Development Server of RHEL

[codesyntax lang=”bash”]

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

#stop iptables
service iptables stop

#start vsftpd
/etc/rc.d/init.d/vsftpd start

#start svn server
/usr/local/svnserver/bin/svnserve -d -r /data/svndata

#start php-fpm
/usr/local/webserver/php/sbin/php-fpm start

#start mysql server
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/data/mysql_data1/my.cnf &
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/data/mysql_data2/my.cnf &
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/data/mysql_data3/my.cnf &

#Start memcached
/usr/local/memcached/bin/memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211 -c 1024 -P /tmp/memcached.pid

#start nginx server
/usr/local/webserver/nginx/sbin/nginx

#mount ftp dir
mount --bind /data/share_data /home/kim/share

[/codesyntax]

Posted in Linux, RHEL | Tagged , | Leave a comment

One Tips for the Loading Order of Environment Files

loading order which? who? when?
1 /etc/enviroment system once
2 /etc/profile (& /etc/profile.d/*) all users once
3 ~/.bash_profile | ~/.bash_login | ~/.profile you once
4 ~/.bashrc you each time
5 /etc/bashrc all users each time
6 ~/.bach_logout all users each time
Posted in Linux | Tagged , | Leave a comment

XHProf for PHP Profile

Environment :
php 5.2.14
xhprof 0.9.2
graphviz 2.26.3

1. Download and install xhprof :
[codesyntax lang=”bash”]

$ wget http://pecl.php.net/get/xhprof-0.9.2.tgz
$ tar -xzf xhprof-0.9.2.tgz
$ cd xhprof-0.9.2
$ cp -r xhprof_html xhprof_lib /data/vhosts/www/
$ cd extension
$ phpize
$ ./configure
$ make
$ make install

[/codesyntax]

2. Modify php.ini :
[codesyntax lang=”ini”]

extension = "xhprof.so"
[xhprof]
xhprof.output_dir = "/data/xhprof"

[/codesyntax]

3. Restart apache (or nginx and php-fpm) and see xhprof section :

4. Start profiling file_to_profile.php :

[codesyntax lang=”php”]

// start xhprof
xhprof_enable();

/**
 * your application code
 * ......
 * ......
 */

$xhprof_data = xhprof_disable();
$xhprof_root = '/data/vhosts/www/xhprof/';
include_once $xhprof_root . "xhprof_lib/utils/xhprof_lib.php";
include_once $xhprof_root . "xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xr");
echo 'see xhprof result';

[/codesyntax]

5. Additional effect with graphviz :
[codesyntax lang=”bash”]

# download and install graphviz
$ wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.26.3.tar.gz
$ tar -xzf graphviz-2.26.3.tar.gz
$ cd graphviz-2.26.3
$ ./configure --prefix=/usr/local/graphviz
$ make
$ make install

[/codesyntax]



to be continue …

Posted in Optimization, PHP | Tagged , , | Leave a comment

Linux Hardware Detection

[codesyntax lang=”bash”]

# Linux Version
$ cat /proc/version

# System Core
$ uname -a

# CPU Type
$ cat /proc/cpuinfo | grep "model name" | head -1

# Base Board Information
$ dmidecode | more

# Total Memory
$ cat /proc/meminfo | grep "MemTotal"

# Disk
$ sudo fdisk -l

# VGA Information
$ lspci | grep VGA

# Sound Card
$ lspci | grep -i audio

# NIC Information
$ dmesg | grep -i eth

# Interrupts Information
$ cat /proc/interrupts - 中断 

# I/O Information
$ cat /proc/ioports

# Partitions Information
$ cat /proc/partitions

# Swap Information
$ cat /proc/swaps

# Processes and CPU Information
$ top

# Virtual Memory
$ vmstat

[/codesyntax]

Posted in Linux | Tagged | Leave a comment