Some low level debugging tools in linux.

nm : just lists symbols from obj file
================
-n sort symbols numerically by address
-D shows dynamic symbols only

Symbol type:
If lowercase, the symbol is local;
if uppercase, the symbol is global (external).
A - symbol's value is absolute, will not be changed by further linking.
B - symbol is in the uninitialized data section (known as BSS).
C - symbol is common. Common symbols are uninitialized data.
D - symbol is in the initialized data section.
N - symbol is a debugging symbol.
R - symbol is in a read only data section.
T - symbol is in the text(code) section.
U - symbol is undefined.

objdump : shows details of obj files
================
-d disassembly
-S mix source code when disassembles
-x display section/program headers
-r display relocation entries
-w more than 80 character wide display

readelf : displays information about contents of ELF format files
================
-a Equivalent to: -h -l -S -s -r -d -V -A -I
-e Equivalent to: -h -l -S

-h Display the ELF file header
-l Display the program headers
-S Display the section headers

-s Display the symbol table
--dyn-syms Display the dynamic symbol table

-r Display the relocations (if present)
-d Display the dynamic section (if present)

-W more than 80 character wide display

good examples:
================
# gcc -c -o test test.c
# readelf -esr test > a.txt

# gcc -g -c -o test test.c
# objdump -drS test > b.txt

PHP code cleaning tools.

PHP LOC statistics:
1. wget --no-check-certificate https://phar.phpunit.de/phploc.phar
2. /opt/lampp/bin/php phploc.phar --exclude="lib" --exclude="Resources" /mnt/data/MyWebProject/ > loc.txt

PHP Mess Detector:
1. Download http://static.phpmd.org/php/2.1.1/phpmd.phar
2. /opt/lampp/bin/php phpmd.phar /mnt/data/MyWebProject/ text codesize --exclude lib,Resources --reportfile code_complexity.txt
[output format: text; available mess detectors: cleancode, codesize, controversial, design, naming, unusedcode]

PHP Code Sniffer (Enforces a coding standard):
1. Download http://download.pear.php.net/package/PHP_CodeSniffer-2.0.0RC1.tgz
2. /opt/lampp/bin/php PHP_CodeSniffer-2.0.0RC1/scripts/phpcs --report-file=code_sniff.txt --standard=Generic --extensions=php --ignore=*/lib/*,*/Resources/* /mnt/data/MyWebProject/

PHP Dead Code Detector:
1. wget --no-check-certificate https://phar.phpunit.de/phpdcd.phar
2. /opt/lampp/bin/php phpdcd.phar --recursive --exclude="lib" --exclude="Resources" /mnt/data/MyWebProject/ > dead_code.txt

PHP Copy Paste Detector
1. wget --no-check-certificate https://phar.phpunit.de/phpcpd.phar
2. /opt/lampp/bin/php phpcpd.phar --exclude="lib" --exclude="Resources" /mnt/data/MyWebProject/ > copy_paste.txt

While searching files with find, exclude some directories

find . -type f -name '*.php' ! -path "./lib/*" ! -path "./Resources/*" -exec vim -s /root/vimscript.scr "{}" \;

To print colored text in linux terminal

echo "$(tput setaf 1) Hello $(tput setaf 2) World! $(tput sgr0)"
or
echo -e "\033[31m Hello \033[32m World! \033[0m"

Option -e means "enable interpretation of backslash escapes"

How to indent php+html+javascript code using Vim on Linux

1. install full vim with plugins.
put following vim commands in /root/.vimrc

:set nocompatible
:filetype indent on
:syntax on
:set tabstop=4
:set shiftwidth=4
:set expandtab

2. create a vim script file (lets say vimscript.scr) in /root
put the following vim commands in vimscript.scr file

" this is a vim script comment
" remove \r in case file is from windows world
:%s/\r$//g

" set filetype as javascript and indent it
:set ft=javascript
gg=G

" set filetype as html and indent it
:set ft=html
gg=G

" set filetype as php and indent it
:set ft=php
gg=G

" convert multiple blank lines to single blank line
:%s/\n\{3,}/\r\r/e

" after indenting save file
:wq
" script end


3. to indent all php files in a dir, go to that dir and run
#find . -type f -name '*.php' -exec vim -s /root/vimscript.scr "{}" \;

Building geany from source

[To compile geany]
Get source tar file from http://www.geany.org/Download/Releases
# cd geany-1.24.1
# ./configure
# make

[To compile geany plugin]
Get source tar file from http://plugins.geany.org/downloads.html
Make sure geany 1.24 is compiled and installed.
# cd geany-plugins-1.24
# ./configure
[This sometimes gives error, "configure: error: Package requirements (geany >= 1.24) were not met".
Test if installation is proper,
#PKG_CONFIG_PATH=/usr/local/lib/pkgconfig pkg-config --modversion geany
# echo $PKG_CONFIG_PATH
May be path is not having /usr/local/lib/pkgconfig, then do,
# PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure]
# make

To create puppy pet/sfs package from source code

Generally:

[compile]
# cd xyz-<ver>
# ./configure
# make

# new2dir make install
# cd ..

[to create a pet]
# dir2pet xyz-<ver>-<arch>

[to create a sfs]
# mksquashfs xyz-<ver>-<arch> xyz-<ver>-<arch>.sfs -noappend