Programming and more

How to see what programs use the most memory in linux

You have to run:


ps aux | sort -nk +4

That will print you a list of all the running applications and it wil sort them by the 4th column (memory)

The same can be applied for CPU, Virual memory etc. Just change the -nk +4 value to +3 +5 etc. Very usefull trick for administrators. In openvz for example, where virtual memory is in fact normal memory, you might want to take a look what program uses the most virutal memory.


Programmatically Build forms with PHP

I needed a way to programmatically build forms with php so that I can easily print them in any template, so that when I change template I don’t have to copy paste and fix forms all over again.

So to solve this I needed some php code to automatically build forms.

For me there are 2 options:

1) Download codeigniter and get their form helper and use that

The form helper are a bunch of functions to help you build forms. You can include them into your project easily. Get the code and import it. You can see what you can do here: http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html

Very well documented and easy to use. no build in validation though.

2) Use php-form-builder-class

http://code.google.com/p/php-form-builder-class/ This one is much better, but very badly documented. It has build in validation, and it can create many more types than codeigniter form helper (even cheditor google recaptcha and many HTML5 elements).

It’s object oriented and it fit perfectly into my project. You can Build your view and customize how you display your input boxes. It uses bootstrap juqeryui and html5 validation if your browser supports it.

You might have to take a look on the code though if you want to learn everything that the class can do for you. I managed to get understand the code, but for a beginner in php it might be difficult, but it’s overally good.

So that’s it,

Thanks for visiting.

jQuery Mobile 1.2.0 – How to disable the ajax loading and effects (and show adsense on jquery mobile!)

I had this problem, I wanted to add adsense advertisments to one of my mobile sites, but you can’t see the ads if the page loads with ajax.

So I needed to disable it. The first solution was this:

<script language="javascript">
    $.mobile.ajaxLinksEnabled = false;

But after updating jquery to the newest version, that didn’t work anymore.

I found in some forum that in order to do that you have to change the script a little bit:

<script language="javascript">
    $.mobile.ajaxEnabled = false;

The only difference is that we remove the Links in ajaxLinksEnabled.

That’s it. Thanks for visiting.

How to add expires headers on css, javascript and image files

I tried many things I found googling but nothing work, until I saw this:

Assuming you are using apache, what you must do is go to you public_html folder, create a file .htaccess and paste in it:


<FilesMatch "\.(ico|pdf|flv|jpe?g|png|gif|js|css|swf)$">
    ExpiresActive On
    ExpiresDefault "access plus 1 year"

you can add more files in the list.

Thanks for visiting.

How to install apache mod_expires In directadmin DA centos linux

cd /usr/local/directadmin/custombuild
mkdir -p custom/ap2
cp configure/ap2/configure.apache custom/ap2/configure.apache
vi custom/ap2/configure.apache

add: –enable-expires

so it looks like this:

"./configure" \
        "--prefix=/etc/httpd" \
        "--exec-prefix=/etc/httpd" \
        "--bindir=/usr/bin" \
        "--sbindir=/usr/sbin" \
        "--sysconfdir=/etc/httpd/conf" \
        "--enable-so" \
        "--enable-dav" \
        "--enable-dav-fs" \
        "--enable-dav-lock" \
        "--enable-suexec" \
        "--enable-deflate" \
        "--enable-unique-id" \
        "--with-suexec-caller=apache" \
        "--with-suexec-docroot=/" \
        "--with-suexec-gidmin=100" \
        "--with-suexec-logfile=/var/log/httpd/suexec_log" \
        "--with-suexec-uidmin=100" \
        "--with-suexec-userdir=public_html" \
        "--with-suexec-bin=/usr/sbin/suexec" \
        "--with-included-apr" \
        "--with-pcre=/usr/local" \
        "--includedir=/usr/include/apache" \
        "--libexecdir=/usr/lib/apache" \
        "--datadir=/var/www" \
        "--localstatedir=/var" \
        "--enable-logio" \
        "--enable-ssl" \
        "--enable-rewrite" \
        "--enable-proxy" \
        "--with-ssl=/usr" \
        "--enable-headers" \
./build clean
./build apache
service httpd restart

you may need to recompile php after this

./build php

Create Easy charts with php/javascript/flash

I was looking yesterday for a way to create a simple chart (Dates and values). I wanted some library to include into the MVC-CMS I created so that I can use everytime I want something.

Open Flash Chart

I knew Open Flash Chart from before. http://teethgrinder.co.uk/open-flash-chart-2/ You can see it in action here: http://www.radiotower.gr/station_details.php?id=12028.
Looks pretty good, and it uses Flash. For me that was not good. I want something that can play on every browser and OS so that clients don’t complain.

Google Charts

Looking for alternatives I found this: https://developers.google.com/chart/ I thouth my journey had finished there, because everything that google creates is awsome! Except from Google Wave, And google+ of cource and … Ok that’s not the point. So this uses javascript HTML5/SVG and it’s compatible with everything. I just didn’t like the examples enough.


HighCharts is just great. Just see the examples: http://www.highcharts.com/demo/ . Again only javascript. Especially the dates thing I wanted to do it’s there, “Time series, Zoomable”. Yes! That’s right, zoomable! How can you say no to that ? I impemented it in just 5 minutes. Works great, and it has some awsome export functions. I don’t even know how, but it works.

jquery jQueryUI autocomplete – how to submit form on selection

jQueryUI Autocomplete http://jqueryui.com/autocomplete/ is a excelent tool to create ajax/javascript google suggest style automplete forms. You can see an example in the site radiotower.gr

List changes when the user types something. It’s really cool and easy to implement. I was faced with one problem though. I wanted to automatically submit the form when the user selected something. I found the answer and I am giving it to you now:


    source: "values.json",
    minLength: 2,
    select: function(event, ui) { 
        $("#searchForm").submit(); }

searchField is the id of the input box, searchForm is the Id of the form.

How to run rsync from command line script with password

When everything else fails try:


set timeout 19900
spawn /bin/bash
expect -re "]# "
send "rsync -av --delete user@host:someremotefolder/ somelocalfolder\r"
expect -re "password:"
sleep 2
send "userpassword\r"
expect -re "total size is"
expect -re "]# "
send "exit\r"

Just replace userpassword with your password. Also replace with your rsync command, obviously.

If you don’t have expect install it:


yum install expect

How to install imagemagik to centos 5.8 – with DirectAdmin DA

It’a atually very easy. Just type:

 yum install ImageMagick ImageMagick-perl


Loaded plugins: fastestmirror, priorities
Determining fastest mirrors
 * base: mirror.kiewel-online.ch
 * epel: mirrors.n-ix.net
 * extras: mirror.kiewel-online.ch
 * updates: mirror.kiewel-online.ch
base                                                     | 1.1 kB     00:00
epel                                                     | 3.7 kB     00:00
epel/primary_db                                          | 3.8 MB     00:00
extras                                                   | 2.1 kB     00:00
extras/primary_db                                        | 207 kB     00:00
updates                                                  | 1.9 kB     00:00
updates/primary_db                                       | 1.0 MB     00:00
vz-base                                                  |  951 B     00:00
vz-updates                                               |  951 B     00:00
Excluding Packages in global exclude list
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ImageMagick.i386 0: set to be updated
--> Processing Dependency: libXt.so.6 for package: ImageMagick
--> Processing Dependency: liblcms.so.1 for package: ImageMagick
--> Processing Dependency: libwmflite-0.2.so.7 for package: ImageMagick
--> Processing Dependency: libgs.so.8 for package: ImageMagick
--> Processing Dependency: librsvg-2.so.2 for package: ImageMagick
---> Package ImageMagick.x86_64 0: set to be updated
--> Processing Dependency: libgs.so.8()(64bit) for package: ImageMagick
--> Processing Dependency: libwmflite-0.2.so.7()(64bit) for package: ImageMagick
---> Package ImageMagick-perl.x86_64 0: set to be updated
epel/filelists_db                                        | 5.6 MB     00:00
extras/filelists_db                                      | 250 kB     00:00
updates/filelists_db                                     | 4.1 MB     00:00
--> Running transaction check
---> Package ghostscript.i386 0:8.70-14.el5_8.1 set to be updated
--> Processing Dependency: urw-fonts >= 1.1 for package: ghostscript
--> Processing Dependency: ghostscript-fonts for package: ghostscript
---> Package ghostscript.x86_64 0:8.70-14.el5_8.1 set to be updated
---> Package lcms.i386 0:1.18-0.1.beta1.el5_3.2 set to be updated
---> Package libXt.i386 0:1.0.2-3.2.el5 set to be updated
---> Package librsvg2.i386 0:2.16.1-1.el5 set to be updated
--> Processing Dependency: libgsf-1.so.114 for package: librsvg2
--> Processing Dependency: libcroco-0.6.so.3 for package: librsvg2
---> Package libwmf.i386 0: set to be updated
--> Processing Dependency: gd >= 2.0.21 for package: libwmf
---> Package libwmf.x86_64 0: set to be updated
--> Running transaction check
---> Package gd.x86_64 0:2.0.33-9.4.el5_4.2 set to be updated
--> Processing Dependency: pkgconfig for package: gd
---> Package ghostscript-fonts.noarch 0:5.50-13.1.1 set to be updated
---> Package libcroco.i386 0:0.6.1-2.1 set to be updated
---> Package libgsf.i386 0:1.14.1-6.1 set to be updated
---> Package urw-fonts.noarch 0:2.3-6.1.1 set to be updated
--> Processing Dependency: mkfontscale for package: urw-fonts
--> Processing Dependency: mkfontdir for package: urw-fonts
--> Processing Dependency: chkfontpath for package: urw-fonts
--> Running transaction check
---> Package chkfontpath.x86_64 0:1.10.1-1.1 set to be updated
--> Processing Dependency: xfs for package: chkfontpath
---> Package pkgconfig.x86_64 1:0.21-2.el5 set to be updated
---> Package xorg-x11-font-utils.x86_64 1:7.1-3 set to be updated
--> Processing Dependency: libfontenc >= 0.99.2-2 for package: xorg-x11-font-uti                                                                                                                                                              ls
--> Processing Dependency: libfontenc.so.1()(64bit) for package: xorg-x11-font-u                                                                                                                                                              tils
--> Processing Dependency: libXfont.so.1()(64bit) for package: xorg-x11-font-uti                                                                                                                                                              ls
--> Running transaction check
---> Package libXfont.x86_64 0:1.2.2-1.0.4.el5_7 set to be updated
---> Package libfontenc.x86_64 0:1.0.2-2.2.el5 set to be updated
---> Package xorg-x11-xfs.x86_64 1:1.0.2-5.el5_6.1 set to be updated
--> Processing Dependency: ttmkfdir for package: xorg-x11-xfs
--> Processing Dependency: libFS.so.6()(64bit) for package: xorg-x11-xfs
--> Running transaction check
---> Package libFS.x86_64 0:1.0.0-3.1 set to be updated
---> Package ttmkfdir.x86_64 0:3.0.9-23.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
 Package                Arch      Version                      Repository  Size
 ImageMagick            i386             updates    3.3 M
 ImageMagick            x86_64             updates    3.3 M
 ImageMagick-perl       x86_64             updates    149 k
Installing for dependencies:
 chkfontpath            x86_64    1.10.1-1.1                   base        15 k
 gd                     x86_64    2.0.33-9.4.el5_4.2           base       155 k
 ghostscript            i386      8.70-14.el5_8.1              updates    9.0 M
 ghostscript            x86_64    8.70-14.el5_8.1              updates    8.9 M
 ghostscript-fonts      noarch    5.50-13.1.1                  base       801 k
 lcms                   i386      1.18-0.1.beta1.el5_3.2       base       176 k
 libFS                  x86_64    1.0.0-3.1                    base        30 k
 libXfont               x86_64    1.2.2-1.0.4.el5_7            base       245 k
 libXt                  i386      1.0.2-3.2.el5                base       173 k
 libcroco               i386      0.6.1-2.1                    base       127 k
 libfontenc             x86_64    1.0.2-2.2.el5                base        19 k
 libgsf                 i386      1.14.1-6.1                   base       116 k
 librsvg2               i386      2.16.1-1.el5                 base       178 k
 libwmf                 i386                 base       834 k
 libwmf                 x86_64                 base       832 k
 pkgconfig              x86_64    1:0.21-2.el5                 base        61 k
 ttmkfdir               x86_64    3.0.9-23.el5                 base        46 k
 urw-fonts              noarch    2.3-6.1.1                    base       4.5 M
 xorg-x11-font-utils    x86_64    1:7.1-3                      base        78 k
 xorg-x11-xfs           x86_64    1:1.0.2-5.el5_6.1            base        73 k
Transaction Summary
Install      23 Package(s)
Upgrade       0 Package(s)
Total size: 33 M
Total download size: 33 M
Is this ok [y/N]: y
Downloading Packages:
(1/21): chkfontpath-1.10.1-1.1.x86_64.rpm                |  15 kB     00:00
(2/21): libfontenc-1.0.2-2.2.el5.x86_64.rpm              |  19 kB     00:00
(3/21): libFS-1.0.0-3.1.x86_64.rpm                       |  30 kB     00:00
(4/21): ttmkfdir-3.0.9-23.el5.x86_64.rpm                 |  46 kB     00:00
(5/21): xorg-x11-xfs-1.0.2-5.el5_6.1.x86_64.rpm          |  73 kB     00:00
(6/21): xorg-x11-font-utils-7.1-3.x86_64.rpm             |  78 kB     00:00
(7/21): libgsf-1.14.1-6.1.i386.rpm                       | 116 kB     00:00
(8/21): libcroco-0.6.1-2.1.i386.rpm                      | 127 kB     00:00
(9/21): ImageMagick-perl-     | 149 kB     00:00
(10/21): libXt-1.0.2-3.2.el5.i386.rpm                    | 173 kB     00:00
(11/21): lcms-1.18-0.1.beta1.el5_3.2.i386.rpm            | 176 kB     00:00
(12/21): librsvg2-2.16.1-1.el5.i386.rpm                  | 178 kB     00:00
(13/21): libXfont-1.2.2-1.0.4.el5_7.x86_64.rpm           | 245 kB     00:00
(14/21): ghostscript-fonts-5.50-13.1.1.noarch.rpm        | 801 kB     00:00
(15/21): libwmf-                  | 832 kB     00:00
(16/21): libwmf-                    | 834 kB     00:00
(17/21): ImageMagick-           | 3.3 MB     00:00
(18/21): ImageMagick-         | 3.3 MB     00:00
(19/21): urw-fonts-2.3-6.1.1.noarch.rpm                  | 4.5 MB     00:00
(20/21): ghostscript-8.70-14.el5_8.1.x86_64.rpm          | 8.9 MB     00:00
(21/21): ghostscript-8.70-14.el5_8.1.i386.rpm            | 9.0 MB     00:00
Total                                            11 MB/s |  33 MB     00:03
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : libfontenc                                              1/23
  Installing     : libXfont                                                2/23
  Installing     : xorg-x11-font-utils                                     3/23
  Installing     : libXt                                                   4/23
  Installing     : ttmkfdir                                                5/23
  Installing     : libFS                                                   6/23
  Installing     : pkgconfig                                               7/23
  Installing     : gd                                                      8/23
  Installing     : libwmf                                                  9/23
  Installing     : libwmf                                                 10/23
  Installing     : libcroco                                               11/23
  Installing     : lcms                                                   12/23
  Installing     : libgsf                                                 13/23
  Installing     : librsvg2                                               14/23
  Installing     : chkfontpath                                            15/23
  Installing     : xorg-x11-xfs                                           16/23
  Installing     : urw-fonts                                              17/23
  Installing     : ghostscript                                            18/23
  Installing     : ghostscript-fonts                                      19/23
  Installing     : ImageMagick                                            20/23
  Installing     : ghostscript                                            21/23
  Installing     : ImageMagick-perl                                       22/23
  Installing     : ImageMagick                                            23/23
  ImageMagick.i386 0:
  ImageMagick.x86_64 0:
  ImageMagick-perl.x86_64 0:
Dependency Installed:
  chkfontpath.x86_64 0:1.10.1-1.1         gd.x86_64 0:2.0.33-9.4.el5_4.2
  ghostscript.i386 0:8.70-14.el5_8.1      ghostscript.x86_64 0:8.70-14.el5_8.1
  ghostscript-fonts.noarch 0:5.50-13.1.1  lcms.i386 0:1.18-0.1.beta1.el5_3.2
  libFS.x86_64 0:1.0.0-3.1                libXfont.x86_64 0:1.2.2-1.0.4.el5_7
  libXt.i386 0:1.0.2-3.2.el5              libcroco.i386 0:0.6.1-2.1
  libfontenc.x86_64 0:1.0.2-2.2.el5       libgsf.i386 0:1.14.1-6.1
  librsvg2.i386 0:2.16.1-1.el5            libwmf.i386 0:
  libwmf.x86_64 0:            pkgconfig.x86_64 1:0.21-2.el5
  ttmkfdir.x86_64 0:3.0.9-23.el5          urw-fonts.noarch 0:2.3-6.1.1
  xorg-x11-font-utils.x86_64 1:7.1-3      xorg-x11-xfs.x86_64 1:1.0.2-5.el5_6.1